-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0612c4
commit 3b7cb7f
Showing
12 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
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 EventSubTopic | ||
|
||
admin.site.register(EventSubTopic) |
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 EventSubTopicsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "event_sub_topics" |
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,28 @@ | ||
# Generated by Django 5.0 on 2023-12-18 13:47 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('event_topics', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EventSubTopic', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=200, null=True)), | ||
('slug', models.CharField(max_length=200, null=True)), | ||
('event_topic_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='event_topics.eventtopic')), | ||
], | ||
options={ | ||
'indexes': [models.Index(fields=['slug', 'event_topic_id'], name='event_sub_t_slug_e7fe13_idx')], | ||
}, | ||
), | ||
] |
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,20 @@ | ||
from django.db import models | ||
|
||
|
||
class EventSubTopic(models.Model): | ||
name = models.CharField(max_length=200, null=True) | ||
slug = models.CharField(max_length=200, null=True) | ||
|
||
event_topic_id = models.ForeignKey( | ||
"event_topics.EventTopic", | ||
on_delete=models.CASCADE, | ||
null=True, | ||
) | ||
|
||
class Meta: | ||
indexes = [ | ||
models.Index(fields=["slug", "event_topic_id"]), | ||
] | ||
|
||
def __str__(self): | ||
return f"{self.name} ({self.slug}) - {self.event_topic_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,9 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import EventSubTopic | ||
|
||
|
||
class EventSubTopicSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = EventSubTopic | ||
fields = ("id", "name", "slug", "event_topic_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 @@ | ||
# 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,21 @@ | ||
from django.urls import path | ||
|
||
from .views import EventSubTopicCreate, EventSubTopicList, EventSubTopicRetrieve, EventSubTopicRetrieveUpdate | ||
|
||
urlpatterns = [ | ||
path("event-sub-topics/", EventSubTopicCreate.as_view(), name="event_sub_topic_create"), | ||
path("event-sub-topics/<int:pk>/", EventSubTopicRetrieveUpdate.as_view(), name="event_sub_topic_detail"), | ||
path( | ||
"event-topics/<int:event_topic_id>/event-sub-topics", EventSubTopicList.as_view(), name="event_sub_topic_list" | ||
), | ||
path( | ||
"events/<int:event_id>/event-sub-topic", | ||
EventSubTopicRetrieve.as_view(), | ||
name="event_event_sub_topic_view_detail", | ||
), | ||
path( | ||
"custom-placeholders/<int:custom_placeholder_id>/event-sub-topic", | ||
EventSubTopicRetrieve.as_view(), | ||
name="custom_placeholder_event_sub_topic_view_detail", | ||
), | ||
] |
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,46 @@ | ||
from rest_framework import generics | ||
|
||
from open_event_api.permissions import IsSuperAdminForUpdate | ||
|
||
from .models import EventSubTopic | ||
from .serializer import EventSubTopicSerializer | ||
|
||
|
||
class EventSubTopicCreate(generics.CreateAPIView): | ||
"""Allows creation of EventSubTopic.""" | ||
|
||
serializer_class = EventSubTopicSerializer | ||
|
||
|
||
class EventSubTopicList(generics.ListAPIView): | ||
"""Allows listing EventSubTopic.""" | ||
|
||
queryset = EventSubTopic.objects.all() | ||
serializer_class = EventSubTopicSerializer | ||
|
||
# Fields to allow sorting by | ||
ordering_fields = ["name"] | ||
|
||
|
||
class EventSubTopicRetrieve(generics.RetrieveAPIView): | ||
"""Allows viewing of the related EventSubTopic.""" | ||
|
||
queryset = EventSubTopic.objects.all() | ||
serializer_class = EventSubTopicSerializer | ||
|
||
def get(self, request, *args, **kwargs): | ||
if kwargs.get("event_id") is not None: | ||
# TODO: implement fetching event sub topic by event id | ||
self.kwargs["pk"] = 1 | ||
if kwargs.get("custom_placeholder_id") is not None: | ||
# TODO: implement fetching event sub topic by custom placeholder id | ||
self.kwargs["pk"] = 1 | ||
|
||
return self.retrieve(request, *args, **kwargs) | ||
|
||
|
||
class EventSubTopicRetrieveUpdate(generics.RetrieveUpdateAPIView): | ||
"""Allows viewing and updating of EventSubTopic.""" | ||
|
||
permission_classes = (IsSuperAdminForUpdate,) | ||
serializer_class = EventSubTopicSerializer |
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
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