Skip to content

Commit

Permalink
Merge pull request #827 from to-sta/extend_schema
Browse files Browse the repository at this point in the history
iso, grouptext and organization_text models added
  • Loading branch information
andrewtavis authored Apr 21, 2024
2 parents 130ee3b + 884182d commit 8d17012
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/content/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from django.contrib import admin

from .models import Faq, Image, Resource, ResourceTopic, Task, Topic, TopicFormat
from .models import (
Faq,
Image,
IsoCodeMap,
Resource,
ResourceTopic,
Task,
Topic,
TopicFormat,
)

admin.site.register(Faq)
admin.site.register(Image)
Expand All @@ -9,3 +18,4 @@
admin.site.register(Task)
admin.site.register(Topic)
admin.site.register(TopicFormat)
admin.site.register(IsoCodeMap)
4 changes: 4 additions & 0 deletions backend/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ class Image(models.Model):

def __str__(self) -> str:
return f"{self.id}"


class IsoCodeMap(models.Model):
code = models.CharField(max_length=2)
7 changes: 7 additions & 0 deletions backend/content/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DiscussionTag,
Faq,
Image,
IsoCodeMap,
Resource,
ResourceTag,
ResourceTopic,
Expand Down Expand Up @@ -165,3 +166,9 @@ def validate(self, data: Dict[str, Union[str, int]]) -> Dict[str, Union[str, int
)

return data


class IsoCodeMapSerializer(serializers.ModelSerializer[IsoCodeMap]):
class Meta:
model = IsoCodeMap
fields = "__all__"
1 change: 1 addition & 0 deletions backend/content/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

urlpatterns = [
path("", include(router.urls)),
path("iso_codes/", views.IsoCodeMapListAPIView.as_view(), name="iso_codes"),
]
13 changes: 13 additions & 0 deletions backend/content/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# mypy: disable-error-code="override"
from django.db.models import Q
from rest_framework import status, viewsets
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -13,6 +14,7 @@
DiscussionEntry,
Faq,
Image,
IsoCodeMap,
Resource,
ResourceTopic,
Task,
Expand All @@ -24,6 +26,7 @@
DiscussionSerializer,
FaqSerializer,
ImageSerializer,
IsoCodeMapSerializer,
ResourceSerializer,
ResourceTopicSerializer,
TaskSerializer,
Expand Down Expand Up @@ -297,3 +300,13 @@ class TopicFormatViewSet(viewsets.ModelViewSet[TopicFormat]):
queryset = TopicFormat.objects.all()
serializer_class = TopicFormatSerializer
pagination_class = CustomPagination


class IsoCodeMapListAPIView(ListAPIView[IsoCodeMap]):
queryset = IsoCodeMap.objects.all()
serializer_class = IsoCodeMapSerializer

def get(self, request: Request) -> Response:
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
17 changes: 17 additions & 0 deletions backend/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def __str__(self) -> str:
return f"{self.id}"


class OrganizationText(models.Model):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE)
primary = models.BooleanField(default=False)
description = models.TextField(max_length=500)
get_involved = models.TextField(max_length=500)
donate = models.TextField(max_length=500)


class GroupEvent(models.Model):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
event_id = models.ForeignKey("events.Event", on_delete=models.CASCADE)
Expand Down Expand Up @@ -201,6 +210,14 @@ def __str__(self) -> str:
return f"{self.id}"


class GroupText(models.Model):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE)
primary = models.BooleanField(default=False)
description = models.TextField(max_length=500)
get_involved = models.TextField(max_length=500)


class Status(models.Model):
status_type = models.ForeignKey("StatusEntityType", on_delete=models.CASCADE)
org_id = models.ForeignKey(
Expand Down

0 comments on commit 8d17012

Please sign in to comment.