From e676768ee2c2c0bf1f02199e33f478a2a444f94c Mon Sep 17 00:00:00 2001 From: vcai122 Date: Wed, 28 Feb 2024 16:57:35 -0500 Subject: [PATCH] add in_use field to gsr + make better admin page --- backend/gsr_booking/admin.py | 11 ++++++++++- .../gsr_booking/migrations/0012_gsr_in_use.py | 16 ++++++++++++++++ backend/gsr_booking/models.py | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 backend/gsr_booking/migrations/0012_gsr_in_use.py diff --git a/backend/gsr_booking/admin.py b/backend/gsr_booking/admin.py index 5e9487c1..e9210d54 100644 --- a/backend/gsr_booking/admin.py +++ b/backend/gsr_booking/admin.py @@ -7,8 +7,17 @@ class GroupMembershipAdmin(admin.ModelAdmin): search_fields = ["user__username__icontains", "group__name__icontains"] +class GSRAdmin(admin.ModelAdmin): + def get_queryset(self, request): + return GSR.all_objects.all() + + list_display = ["name", "kind", "lid", "gid", "in_use"] + search_fields = ["name", "lid", "gid"] + ordering = ["-in_use"] + + admin.site.register(Group) admin.site.register(GroupMembership, GroupMembershipAdmin) -admin.site.register(GSR) +admin.site.register(GSR, GSRAdmin) admin.site.register(GSRBooking) admin.site.register(Reservation) diff --git a/backend/gsr_booking/migrations/0012_gsr_in_use.py b/backend/gsr_booking/migrations/0012_gsr_in_use.py new file mode 100644 index 00000000..86b458d0 --- /dev/null +++ b/backend/gsr_booking/migrations/0012_gsr_in_use.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.22 on 2024-02-28 21:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("gsr_booking", "0011_alter_reservation_group"), + ] + + operations = [ + migrations.AddField( + model_name="gsr", name="in_use", field=models.BooleanField(default=True), + ), + ] diff --git a/backend/gsr_booking/models.py b/backend/gsr_booking/models.py index 95740bcc..f9c44d27 100644 --- a/backend/gsr_booking/models.py +++ b/backend/gsr_booking/models.py @@ -84,6 +84,11 @@ def save(self, *args, **kwargs): ) +class GSRManager(models.Manager): + def get_queryset(self): + return super().get_queryset().filter(in_use=True) + + class GSR(models.Model): KIND_WHARTON = "WHARTON" @@ -96,6 +101,11 @@ class GSR(models.Model): name = models.CharField(max_length=255) image_url = models.URLField() + in_use = models.BooleanField(default=True) + + objects = GSRManager() + all_objects = models.Manager() # for admin page + def __str__(self): return f"{self.lid}-{self.gid}"