-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created model for attendance, events and blogs
- Loading branch information
Showing
42 changed files
with
435 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Attendance | ||
|
||
admin.site.register(Attendance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AttendanceConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'attendance' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.0.8 on 2023-01-16 22:39 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('event', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Attendance', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('title', models.CharField(max_length=100)), | ||
('comment', models.CharField(blank=True, max_length=256)), | ||
('eventId', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='event.event')), | ||
], | ||
options={ | ||
'ordering': ('-created_at',), | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.0.8 on 2023-01-16 22:42 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('attendance', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='attendance', | ||
name='title', | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.db import models | ||
from event.models import Event | ||
from core.models import AuditableModel | ||
|
||
# Create your models here. | ||
|
||
|
||
class Attendance (AuditableModel): | ||
eventId = models.ForeignKey( | ||
Event, on_delete=models.SET_NULL, null=True) | ||
comment = models.CharField(max_length=256, blank=True) | ||
|
||
class Meta: | ||
ordering = ('-created_at',) | ||
|
||
def __str__(self) -> str: | ||
return self.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib import admin | ||
from .models import Post, Comment | ||
|
||
# Register your models here. | ||
|
||
|
||
@admin.register(Comment) | ||
class CommentAdmin(admin.ModelAdmin): | ||
list_display = ["id", 'author', 'postId', 'created_at', 'active'] | ||
list_filter = ['active', 'created_at'] | ||
search_fields = ['author', "postId", "active", 'body'] | ||
|
||
|
||
@admin.register(Post) | ||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ["id", "author", 'author', 'created_at', 'status'] | ||
list_filter = ['status', 'created_at'] | ||
search_fields = ['author', "status", 'body'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'blog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.db import models | ||
# from .models import Post | ||
|
||
|
||
class PublishedManager(models.Manager): | ||
def get_queryset(self): | ||
return super().get_queryset().filter(status=Post.Status.PUBLISHED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 4.0.8 on 2023-01-16 23:58 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Post', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('title', models.CharField(max_length=250)), | ||
('slug', models.SlugField(max_length=250)), | ||
('body', models.TextField()), | ||
('publish', models.DateTimeField(default=django.utils.timezone.now)), | ||
('status', models.CharField(choices=[('DF', 'Draft'), ('PB', 'Published')], default='DF', max_length=2)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'ordering': ['-publish'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('body', models.TextField()), | ||
('active', models.BooleanField(default=True)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to=settings.AUTH_USER_MODEL)), | ||
('postId', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.post')), | ||
], | ||
options={ | ||
'ordering': ['created_at'], | ||
}, | ||
), | ||
migrations.AddIndex( | ||
model_name='post', | ||
index=models.Index(fields=['-publish'], name='blog_post_publish_bb7600_idx'), | ||
), | ||
migrations.AddIndex( | ||
model_name='comment', | ||
index=models.Index(fields=['created_at'], name='blog_commen_created_4e025c_idx'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.0.8 on 2023-01-17 00:06 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='post', | ||
name='slug', | ||
field=models.SlugField(blank=True, max_length=200, null=True), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import time | ||
from django.db import models | ||
from core.models import AuditableModel | ||
from django.utils import timezone | ||
from account.models import CustomUser | ||
|
||
# from .manager import PublishedManager | ||
|
||
|
||
class PublishedManager(models.Manager): | ||
def get_queryset(self): | ||
return super().get_queryset().filter(status=Post.Status.PUBLISHED) | ||
|
||
|
||
class Post(AuditableModel): | ||
class Status(models.TextChoices): | ||
DRAFT = 'DF', 'Draft' | ||
PUBLISHED = 'PB', 'Published' | ||
title = models.CharField(max_length=250) | ||
slug = models.SlugField(max_length=200, null=True, blank=True) | ||
author = models.ForeignKey(CustomUser, | ||
on_delete=models.CASCADE, | ||
related_name='blog_posts') | ||
body = models.TextField() | ||
publish = models.DateTimeField(default=timezone.now) | ||
status = models.CharField(max_length=2, | ||
choices=Status.choices, | ||
default=Status.DRAFT) | ||
objects = models.Manager() # The default manager. | ||
published = PublishedManager() # Our custom manager. | ||
|
||
class Meta: | ||
ordering = ['-publish'] | ||
indexes = [ | ||
models.Index(fields=['-publish']), | ||
] | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def save(self, *args, **kwargs): | ||
self.slug = str(f'{self.author.firstname} {self.author.lastname}').replace( | ||
" ", "-").strip().lower() + '-' + str(int(time.time())) | ||
return super().save(*args, **kwargs) | ||
|
||
|
||
class Comment(AuditableModel): | ||
postId = models.ForeignKey(Post, | ||
on_delete=models.CASCADE, | ||
related_name='comments') | ||
author = models.ForeignKey(CustomUser, | ||
on_delete=models.CASCADE, | ||
related_name='comments') | ||
body = models.TextField() | ||
active = models.BooleanField(default=True) | ||
|
||
class Meta: | ||
ordering = ['created_at'] | ||
indexes = [ | ||
models.Index(fields=['created_at']), | ||
] | ||
|
||
def __str__(self): | ||
return f'Comment by {self.author} on {self.postId}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import uuid | ||
from django.db import models | ||
|
||
|
||
class AuditableModel(models.Model): | ||
id = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
abstract = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.