-
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
d8015b3
commit 92f38bc
Showing
13 changed files
with
175 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 Group | ||
|
||
admin.site.register(Group) |
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 GroupsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "groups" |
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,32 @@ | ||
# Generated by Django 5.0 on 2023-12-18 14:09 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Group', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=200)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('modified_at', models.DateTimeField(auto_now=True)), | ||
('social_links', models.JSONField(null=True)), | ||
('about', models.TextField(null=True)), | ||
('banner_url', models.URLField(null=True)), | ||
('logo_url', models.URLField(null=True)), | ||
('deleted_at', models.DateTimeField(null=True)), | ||
('user_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
28 changes: 28 additions & 0 deletions
28
groups/migrations/0002_group_follower_count_group_is_promoted_and_more.py
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 14:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('groups', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='group', | ||
name='follower_count', | ||
field=models.IntegerField(default=0, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='group', | ||
name='is_promoted', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='group', | ||
name='thumbnail_image_url', | ||
field=models.URLField(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,24 @@ | ||
from django.db import models | ||
|
||
|
||
class Group(models.Model): | ||
name = models.CharField(max_length=200) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
modified_at = models.DateTimeField(auto_now=True) | ||
social_links = models.JSONField(null=True) | ||
about = models.TextField(null=True) | ||
banner_url = models.URLField(null=True) | ||
logo_url = models.URLField(null=True) | ||
thumbnail_image_url = models.URLField(null=True) | ||
is_promoted = models.BooleanField(default=False) | ||
follower_count = models.IntegerField(null=True, default=0) | ||
deleted_at = models.DateTimeField(null=True) | ||
|
||
user_id = models.ForeignKey( | ||
"users.CustomUser", | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
) | ||
|
||
def __str__(self): | ||
return f"{self.name} ({self.user_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 Group | ||
|
||
|
||
class GroupSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Group | ||
fields = ("name", "user_id", "deleted_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 @@ | ||
# 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,10 @@ | ||
from django.urls import path | ||
|
||
from .views import GroupListCreate, GroupListRelation, GroupRetrieveRelation, GroupRetrieveUpdateDestroy | ||
|
||
urlpatterns = [ | ||
path("groups/", GroupListCreate.as_view(), name="group_list_create"), | ||
path("groups/<int:pk>/", GroupRetrieveUpdateDestroy.as_view(), name="group_detail_update_delete"), | ||
path("events/<int:event_id>/group", GroupRetrieveRelation.as_view(), name="event_group_detail"), | ||
path("users/<int:user_id>/groups", GroupListRelation.as_view(), name="user_group_list"), | ||
] |
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,58 @@ | ||
from rest_framework import generics | ||
|
||
from open_event_api.permissions import IsSuperAdminForUpdate | ||
|
||
from .models import Group | ||
from .serializer import GroupSerializer | ||
|
||
|
||
class GroupListCreate(generics.ListCreateAPIView): | ||
"""Allows listing and creation of Group.""" | ||
|
||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
# Fields to allow sorting by | ||
ordering_fields = ["name"] | ||
# TODO: Add filtering based on name field. | ||
|
||
|
||
class GroupRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView): | ||
"""Allows viewing, updating and deleting of Group.""" | ||
|
||
permission_classes = (IsSuperAdminForUpdate,) | ||
serializer_class = GroupSerializer | ||
|
||
|
||
class GroupRetrieveRelation(generics.RetrieveAPIView): | ||
"""Allows viewing of the related Group.""" | ||
|
||
permission_classes = (IsSuperAdminForUpdate,) | ||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
def get(self, request, *args, **kwargs): | ||
if kwargs.get("event_id") is not None: | ||
# TODO: implement fetching group by event id | ||
self.kwargs["pk"] = 1 | ||
|
||
return self.retrieve(request, *args, **kwargs) | ||
|
||
|
||
class GroupListRelation(generics.ListAPIView): | ||
"""Allows listing of the related Group.""" | ||
|
||
permission_classes = (IsSuperAdminForUpdate,) | ||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
# Fields to allow sorting by | ||
ordering_fields = ["name"] | ||
# TODO: Add filtering based on name field. | ||
|
||
def get(self, request, *args, **kwargs): | ||
if kwargs.get("user_id") is not None: | ||
# TODO: implement fetching group by user id | ||
self.kwargs["pk"] = 1 | ||
|
||
return self.list(request, *args, **kwargs) |
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