Skip to content

Commit

Permalink
add in_use field to gsr + make better admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
vcai122 committed Feb 28, 2024
1 parent efa3e09 commit e676768
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/gsr_booking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions backend/gsr_booking/migrations/0012_gsr_in_use.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
10 changes: 10 additions & 0 deletions backend/gsr_booking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"

Expand Down

0 comments on commit e676768

Please sign in to comment.