Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new fields for the event model and remove the pagination error #46

Open
wants to merge 3 commits into
base: revamp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.5 on 2024-04-07 10:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bhawan_app', '0016_auto_20221116_0024'),
]

operations = [
migrations.AddField(
model_name='event',
name='registered_students',
field=models.ManyToManyField(related_name='registered_events', to='bhawan_app.resident'),
),
migrations.AlterField(
model_name='complaint',
name='status',
field=models.CharField(choices=[('res', 'Resolved'), ('pen', 'Pending'), ('unr', 'Unresolved'), ('ipr', 'Inprocess')], default='pen', max_length=10),
),
]
24 changes: 24 additions & 0 deletions migrations/0018_event_deadline_date_event_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.5 on 2024-04-07 11:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bhawan_app', '0017_event_registered_students_alter_complaint_status'),
]

operations = [
migrations.AddField(
model_name='event',
name='deadline_date',
field=models.DateField(blank=True, default='2003-11-23'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='location',
field=models.CharField(blank=True, max_length=255),
),
]
18 changes: 18 additions & 0 deletions migrations/0018_event_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2024-04-07 11:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bhawan_app', '0017_event_registered_students_alter_complaint_status'),
]

operations = [
migrations.AddField(
model_name='event',
name='location',
field=models.CharField(blank=True, max_length=255),
),
]
19 changes: 19 additions & 0 deletions migrations/0019_event_deadline_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.5 on 2024-04-07 11:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bhawan_app', '0018_event_location'),
]

operations = [
migrations.AddField(
model_name='event',
name='deadline_date',
field=models.DateField(default='2003-11-23'),
preserve_default=False,
),
]
14 changes: 14 additions & 0 deletions migrations/0020_merge_20240407_1843.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 4.1.5 on 2024-04-07 13:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('bhawan_app', '0018_event_deadline_date_event_location'),
('bhawan_app', '0019_event_deadline_date'),
]

operations = [
]
3 changes: 3 additions & 0 deletions models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Event(Model):
)
timings = models.ManyToManyField(Timing,)
date = models.DateField()
registered_students = models.ManyToManyField(Resident, related_name='registered_events')
location = models.CharField(max_length=255,blank=True)
deadline_date=models.DateField()

def __str__(self):
"""
Expand Down
13 changes: 13 additions & 0 deletions serializers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from bhawan_app.models import Event
from bhawan_app.serializers.timing import TimingSerializer
from bhawan_app.serializers.resident import ResidentSerializer

Hostel = swapper.load_model("Kernel", "Residence")

Expand All @@ -14,6 +15,7 @@ class EventSerializer(serializers.ModelSerializer):
"""

timings = TimingSerializer(many=True,)
registered_students = ResidentSerializer(many=True,)

class Meta:
"""
Expand All @@ -28,12 +30,16 @@ class Meta:
"description",
"display_picture",
"timings",
"registered_students",
"location",
"deadline_date",
]

def create(self, validated_data):
timing_data = validated_data.pop("timings")
timing_serializer = TimingSerializer(data=timing_data, many=True)
timing_serializer.is_valid(raise_exception=True)
registered_students = ResidentSerializer(many=True)

hostel_code = self.context["hostel__code"]
try:
Expand All @@ -60,6 +66,13 @@ def update(self, instance, validated_data):
timings = timing_serializer.save()
instance.timings.clear()
instance.timings.add(*timings)
if 'registered_students' in validated_data.keys():
students = validated_data.pop('registered_students')
students_serializer = ResidentSerializer(data=students, many=True)
students_serializer.is_valid(raise_exception=True)
students = students_serializer.save()
instance.students.clear()
instance.students.add(*students)
return super().update(instance, validated_data)


2 changes: 2 additions & 0 deletions views/complaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ComplaintViewset(viewsets.ModelViewSet):
serializer_class = ComplaintSerializer
allowed_methods = ['GET', 'POST', 'PATCH']
permission_classes = [IsAuthenticated]
pagination_class = None


@action(detail=True, methods=['GET'])
def unsuccessful(self, request, hostel__code, pk=None):
Expand Down