api
This commit is contained in:
parent
681a8d8a3e
commit
3683f943a6
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
BIN
api/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
api/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/admin.cpython-312.pyc
Normal file
BIN
api/__pycache__/admin.cpython-312.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/apps.cpython-312.pyc
Normal file
BIN
api/__pycache__/apps.cpython-312.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/models.cpython-312.pyc
Normal file
BIN
api/__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
3
api/admin.py
Normal file
3
api/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
api/apps.py
Normal file
6
api/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
0
api/migrations/__init__.py
Normal file
0
api/migrations/__init__.py
Normal file
BIN
api/migrations/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
api/migrations/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
3
api/models.py
Normal file
3
api/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
BIN
api/serializers/__pycache__/event.cpython-312.pyc
Normal file
BIN
api/serializers/__pycache__/event.cpython-312.pyc
Normal file
Binary file not shown.
10
api/serializers/event.py
Normal file
10
api/serializers/event.py
Normal file
@ -0,0 +1,10 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from web.models import Event
|
||||
|
||||
|
||||
class EventSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = '__all__'
|
BIN
api/views/__pycache__/event.cpython-312.pyc
Normal file
BIN
api/views/__pycache__/event.cpython-312.pyc
Normal file
Binary file not shown.
112
api/views/event.py
Normal file
112
api/views/event.py
Normal file
@ -0,0 +1,112 @@
|
||||
from rest_framework.views import APIView
|
||||
from django.contrib.auth.models import User
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.serializers.event import EventSerializer
|
||||
from common.build_response import build_response
|
||||
from web.models import Event, EventDivision
|
||||
|
||||
|
||||
class EventView(APIView):
|
||||
def get(self, request, event_id):
|
||||
try:
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
except Exception:
|
||||
return build_response(404)
|
||||
|
||||
try:
|
||||
event_serializer = EventSerializer(event)
|
||||
except Exception:
|
||||
return build_response(422)
|
||||
|
||||
return build_response(data=event_serializer.data)
|
||||
|
||||
def post(self, request):
|
||||
data = request.POST
|
||||
|
||||
try:
|
||||
division = get_object_or_404(EventDivision, pk=data.get('division'))
|
||||
except Exception:
|
||||
return build_response(500, message="Unable to retrieve division info")
|
||||
|
||||
try:
|
||||
user = User.objects.filter(email=data.get('created_by')).first()
|
||||
except Exception:
|
||||
return build_response(500, message="Could not find user!")
|
||||
|
||||
try:
|
||||
new_event = Event(
|
||||
name=data.get("name"),
|
||||
description=data.get("description"),
|
||||
division=division,
|
||||
start_date=data.get('start_date'),
|
||||
end_date=data.get('end_date'),
|
||||
submit_by_date=data.get('submit_by_date'),
|
||||
chosen_date=None,
|
||||
created_by=user
|
||||
)
|
||||
|
||||
new_event.save()
|
||||
except Exception:
|
||||
return build_response(500, message="Unable to create new event!")
|
||||
|
||||
try:
|
||||
event_serializer = EventSerializer(new_event)
|
||||
except Exception:
|
||||
return build_response(422)
|
||||
|
||||
return build_response(200, data=event_serializer.data)
|
||||
|
||||
def put(self,request, event_id):
|
||||
try:
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
except Exception:
|
||||
return build_response(404)
|
||||
|
||||
data = request.POST
|
||||
|
||||
try:
|
||||
division = get_object_or_404(EventDivision, pk=data.get('division'))
|
||||
except Exception:
|
||||
return build_response(500, message="Unable to retrieve division info")
|
||||
|
||||
try:
|
||||
event.name = data.get('name', event.name)
|
||||
event.description = data.get('description', event.description)
|
||||
event.division = None
|
||||
event.start_date = data.get('start_date', event.start_date)
|
||||
event.end_date = data.get('end_date', event.end_date)
|
||||
event.submit_by_date = data.get('submit_by_date', event.submit_by_date)
|
||||
event.chosen_date = data.get('chosen_date', event.chosen_date)
|
||||
event.created_by = data.get('created_by', event.created_by)
|
||||
|
||||
event.save()
|
||||
|
||||
except Exception:
|
||||
build_response(500, message='Unable to update event')
|
||||
|
||||
try:
|
||||
event_serializer = EventSerializer(event)
|
||||
except Exception:
|
||||
return build_response(422)
|
||||
|
||||
return build_response(200, data=event_serializer.data)
|
||||
|
||||
def delete(self, request, event_id):
|
||||
try:
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
except Exception:
|
||||
return build_response(404)
|
||||
|
||||
try:
|
||||
event.active = False
|
||||
event.save()
|
||||
except Exception:
|
||||
return build_response(500, message="Unable to deactivate event")
|
||||
|
||||
try:
|
||||
event_serializer = EventSerializer(event)
|
||||
except Exception:
|
||||
return build_response(422)
|
||||
|
||||
return build_response(204, data=event_serializer)
|
BIN
common/__pycache__/build_response.cpython-312.pyc
Normal file
BIN
common/__pycache__/build_response.cpython-312.pyc
Normal file
Binary file not shown.
30
common/build_response.py
Normal file
30
common/build_response.py
Normal file
@ -0,0 +1,30 @@
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
status_code_message_map = {
|
||||
204: 'Successfully deleted entity.',
|
||||
403: 'User does not have access to this entity.',
|
||||
404: 'No entity matches the given query',
|
||||
500: 'Something went wrong!'
|
||||
}
|
||||
|
||||
|
||||
def build_response(status_code=200, data=None, message=None):
|
||||
response = Response()
|
||||
response.status_code = status_code
|
||||
|
||||
if response.status_code == 200:
|
||||
response.data = data
|
||||
else:
|
||||
response.data = {}
|
||||
response.data['message'] = message if message else status_code_message_map.get(status_code)
|
||||
|
||||
exc_info = sys.exc_info()
|
||||
exception_info = ''.join(traceback.format_exception(*exc_info))
|
||||
response.data['details'] = exception_info
|
||||
|
||||
return response
|
||||
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@ -35,13 +35,15 @@ CSRF_TRUSTED_ORIGINS = ['https://korabo.domdit.com']
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'web',
|
||||
'api',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'bootstrap5'
|
||||
'bootstrap5',
|
||||
'rest_framework'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -16,9 +16,14 @@ Including another URLconf
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from api.views.event import EventView
|
||||
from web import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('api/event/', EventView.as_view(), name='event'),
|
||||
path('api/event/<int:event_id>', EventView.as_view(), name='event'),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
path('admin/', admin.site.urls),
|
||||
path("", views.index, name="index"),
|
||||
|
21
requests/event_post.py
Normal file
21
requests/event_post.py
Normal file
@ -0,0 +1,21 @@
|
||||
import requests
|
||||
|
||||
|
||||
url = 'http://127.0.0.1:8000/api/event/'
|
||||
|
||||
data = {
|
||||
'name': 'this is a test',
|
||||
'description': 'Some long ass description',
|
||||
'start_date': '2025-03-28T23:30:00Z',
|
||||
'end_date': '2025-04-04T23:30:00Z',
|
||||
'submit_by_date': '2025-04-03T23:30:00Z',
|
||||
'created_by': 'me@domdit.com',
|
||||
'division': 1
|
||||
|
||||
}
|
||||
|
||||
|
||||
resp = requests.post(url, data=data)
|
||||
print(resp.status_code)
|
||||
print('------------')
|
||||
print(resp.json())
|
20
requests/event_put.py
Normal file
20
requests/event_put.py
Normal file
@ -0,0 +1,20 @@
|
||||
import requests
|
||||
|
||||
|
||||
url = "http://127.0.0.1:8000/api/event/3"
|
||||
|
||||
data = {
|
||||
"name": "this is a test and a change",
|
||||
# 'description': 'Some long ass description',
|
||||
# 'start_date': '2025-03-28T23:30:00Z',
|
||||
"end_date": "2025-04-07T23:30:00Z",
|
||||
# 'submit_by_date': '2025-04-03T23:30:00Z',
|
||||
# 'created_by': 'me@domdit.com',
|
||||
"division": 2,
|
||||
}
|
||||
|
||||
|
||||
resp = requests.put(url, data=data)
|
||||
print(resp.status_code)
|
||||
print("------------")
|
||||
print(resp.json())
|
@ -1,8 +1,14 @@
|
||||
asgiref==3.8.1
|
||||
beautifulsoup4==4.12.3
|
||||
certifi==2025.1.31
|
||||
charset-normalizer==3.4.1
|
||||
Django==4.2.16
|
||||
django-bootstrap-v5==1.0.11
|
||||
djangorestframework==3.15.2
|
||||
gunicorn==23.0.0
|
||||
idna==3.10
|
||||
packaging==24.1
|
||||
requests==2.32.3
|
||||
soupsieve==2.6
|
||||
sqlparse==0.5.1
|
||||
urllib3==2.3.0
|
||||
|
17
web/admin.py
17
web/admin.py
@ -1,6 +1,21 @@
|
||||
from django.contrib import admin
|
||||
from web.models import Event, EventAdmin, Availability
|
||||
from web.models import (
|
||||
Event,
|
||||
EventAdmin,
|
||||
Availability,
|
||||
EventComment,
|
||||
EventCommentReaction,
|
||||
EventCommentReactionAdmin,
|
||||
EventDivision,
|
||||
EventDivisionAdmin,
|
||||
SharedEvent,
|
||||
SharedEventAdmin
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(Event, EventAdmin)
|
||||
admin.site.register(Availability)
|
||||
admin.site.register(EventComment)
|
||||
admin.site.register(EventCommentReaction, EventCommentReactionAdmin)
|
||||
admin.site.register(EventDivision, EventDivisionAdmin)
|
||||
admin.site.register(SharedEvent, SharedEventAdmin)
|
||||
|
@ -1,7 +1,8 @@
|
||||
# Generated by Django 5.1.2 on 2024-10-22 20:31
|
||||
# Generated by Django 4.2.16 on 2025-03-29 00:40
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -9,6 +10,7 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -20,14 +22,82 @@ class Migration(migrations.Migration):
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('name', models.TextField()),
|
||||
('description', models.TextField()),
|
||||
('start_date', models.DateTimeField()),
|
||||
('end_date', models.DateTimeField()),
|
||||
('submit_by_date', models.DateTimeField()),
|
||||
('chosen_date', models.DateTimeField()),
|
||||
('participants', models.IntegerField()),
|
||||
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'events',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventComment',
|
||||
fields=[
|
||||
('created_at', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True, null=True)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('content', models.TextField()),
|
||||
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.event')),
|
||||
('submitted_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'events_comments',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventDivision',
|
||||
fields=[
|
||||
('created_at', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True, null=True)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('name', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('description', models.TextField(blank=True, null=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SharedEvent',
|
||||
fields=[
|
||||
('created_at', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True, null=True)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.event')),
|
||||
('shared_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shared_by', to=settings.AUTH_USER_MODEL)),
|
||||
('shared_to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shared_to', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'shared_event',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventCommentReaction',
|
||||
fields=[
|
||||
('created_at', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True, null=True)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('reaction', models.CharField(blank=True, default=None, max_length=8)),
|
||||
('event_comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.eventcomment')),
|
||||
('submitted_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'event_comment_reactions',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='event',
|
||||
name='division',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.eventdivision'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Availability',
|
||||
fields=[
|
||||
@ -35,12 +105,12 @@ class Migration(migrations.Migration):
|
||||
('updated_at', models.DateTimeField(auto_now=True, null=True)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('user', models.TextField()),
|
||||
('time_table', models.JSONField()),
|
||||
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.event')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'availabilities',
|
||||
'db_table': 'availability',
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -1,21 +0,0 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-24 17:59
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('web', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='availability',
|
||||
name='user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.2.16 on 2025-03-29 01:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('web', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='chosen_date',
|
||||
field=models.DateTimeField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='participants',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
]
|
18
web/migrations/0003_alter_event_participants.py
Normal file
18
web/migrations/0003_alter_event_participants.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.16 on 2025-03-29 01:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('web', '0002_alter_event_chosen_date_alter_event_participants'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='participants',
|
||||
field=models.IntegerField(blank=True, default=1),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,38 +0,0 @@
|
||||
from django.contrib import admin
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
created_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
updated_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Event(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.TextField(blank=False, null=False)
|
||||
start_date = models.DateTimeField(blank=False, null=False)
|
||||
end_date = models.DateTimeField(blank=False, null=False)
|
||||
participants = models.IntegerField(blank=False)
|
||||
|
||||
class Meta:
|
||||
db_table = 'events'
|
||||
|
||||
|
||||
class EventAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'start_date', 'end_date', 'active')
|
||||
|
||||
|
||||
class Availability(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
time_table = models.JSONField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'availabilities'
|
7
web/models/__init__.py
Normal file
7
web/models/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
from .availability import Availability
|
||||
from .event import Event, EventAdmin
|
||||
from .event_comment import EventComment, EventCommentAdmin
|
||||
from .event_comment_reaction import EventCommentReaction, EventCommentReactionAdmin
|
||||
from .event_division import EventDivision, EventDivisionAdmin
|
||||
from .shared_event import SharedEvent, SharedEventAdmin
|
||||
|
BIN
web/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/availability.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/availability.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/base.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/base.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/event.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/event.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/event_comment.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/event_comment.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/event_comment_reaction.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/event_comment_reaction.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/event_division.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/event_division.cpython-312.pyc
Normal file
Binary file not shown.
BIN
web/models/__pycache__/shared_event.cpython-312.pyc
Normal file
BIN
web/models/__pycache__/shared_event.cpython-312.pyc
Normal file
Binary file not shown.
15
web/models/availability.py
Normal file
15
web/models/availability.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from web.models.base import BaseModel
|
||||
from web.models.event import Event
|
||||
|
||||
|
||||
class Availability(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
time_table = models.JSONField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'availability'
|
10
web/models/base.py
Normal file
10
web/models/base.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
created_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
updated_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
25
web/models/event.py
Normal file
25
web/models/event.py
Normal file
@ -0,0 +1,25 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from web.models.base import BaseModel
|
||||
from web.models.event_division import EventDivision
|
||||
|
||||
|
||||
class Event(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.TextField(blank=False, null=False)
|
||||
description = models.TextField(blank=False, null=False)
|
||||
division = models.ForeignKey(EventDivision, on_delete=models.CASCADE)
|
||||
start_date = models.DateTimeField(blank=False, null=False)
|
||||
end_date = models.DateTimeField(blank=False, null=False)
|
||||
submit_by_date = models.DateTimeField(blank=False, null=False)
|
||||
chosen_date = models.DateTimeField(blank=True, null=True)
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
db_table = 'events'
|
||||
|
||||
|
||||
class EventAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'start_date', 'end_date', 'active', 'created_by')
|
20
web/models/event_comment.py
Normal file
20
web/models/event_comment.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from web.models.base import BaseModel
|
||||
from web.models.event import Event
|
||||
|
||||
|
||||
class EventComment(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
content = models.TextField(blank=False, null=False)
|
||||
submitted_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
db_table = 'events_comments'
|
||||
|
||||
|
||||
class EventCommentAdmin(admin.ModelAdmin):
|
||||
list_display = ('event', 'content', 'submitted_by')
|
20
web/models/event_comment_reaction.py
Normal file
20
web/models/event_comment_reaction.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from web.models.base import BaseModel
|
||||
from web.models.event_comment import EventComment
|
||||
|
||||
|
||||
class EventCommentReaction(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
reaction = models.CharField(default=None, blank=True, max_length=8)
|
||||
event_comment = models.ForeignKey(EventComment, on_delete=models.CASCADE)
|
||||
submitted_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
db_table = 'event_comment_reactions'
|
||||
|
||||
|
||||
class EventCommentReactionAdmin(admin.ModelAdmin):
|
||||
list_display = ('event_comment', 'reaction', 'submitted_by')
|
14
web/models/event_division.py
Normal file
14
web/models/event_division.py
Normal file
@ -0,0 +1,14 @@
|
||||
from django.contrib import admin
|
||||
from django.db import models
|
||||
|
||||
from web.models.base import BaseModel
|
||||
|
||||
|
||||
class EventDivision(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(blank=True, null=True, max_length=255)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
|
||||
|
||||
class EventDivisionAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', )
|
20
web/models/shared_event.py
Normal file
20
web/models/shared_event.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from web.models.base import BaseModel
|
||||
from web.models.event import Event
|
||||
|
||||
|
||||
class SharedEvent(BaseModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
shared_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='shared_by')
|
||||
shared_to = models.ForeignKey(User, on_delete=models.CASCADE, related_name='shared_to')
|
||||
|
||||
class Meta:
|
||||
db_table = 'shared_event'
|
||||
|
||||
|
||||
class SharedEventAdmin(admin.ModelAdmin):
|
||||
list_display = ('shared_by', 'shared_to', 'event')
|
Loading…
x
Reference in New Issue
Block a user