diff --git a/busManager/coord/admin.py b/busManager/coord/admin.py index 3ddcf2c..c038fa8 100644 --- a/busManager/coord/admin.py +++ b/busManager/coord/admin.py @@ -174,10 +174,10 @@ class TravellerRouteInline(admin.TabularInline): @admin.register(Traveller) -class TravellerAdmin(MyImportExportModelAdmin, CloneModelAdmin, admin.ModelAdmin, TravellerRollMixin): +class TravellerAdmin(MyImportExportModelAdmin, admin.ModelAdmin, TravellerRollMixin): list_display = ["first_name", "last_name", "school", "year_level", "is_active", "address", "stop_route", "shuttle", "travel_start_date", "travel_end_date"] list_filter = [ - "is_active", "school", "year_level", "eligibility_status", "bus_stops__bus", "shuttle", "residential_suburb", + "is_active", "school", "year_level", "eligibility_status", "bus_stops__bus", "shuttle", ("travel_start_date", DateRangeFilterBuilder( title="Start date" )), @@ -185,16 +185,9 @@ class TravellerAdmin(MyImportExportModelAdmin, CloneModelAdmin, admin.ModelAdmin title="End date" )) ] - search_fields = ["first_name", "last_name", "residential_address"] - cloneable_fields = ["last_name", "residential_address", "residential_suburb", - "postal_address", "postal_suburb", "eligibility_status", "shuttle", - "parent_A_firstname", "parent_A_lastname", "parent_A_phone", "parent_A_email", - "parent_B_firstname", "parent_B_lastname", "parent_B_phone", "parent_B_email", - "emergency_contact_A_firstname", "emergency_contact_A_lastname", "emergency_contact_A_phone", - "emergency_contact_A_relation", "emergency_contact_B_firstname", "emergency_contact_B_lastname", - "emergency_contact_B_phone", "emergency_contact_B_relation"] + search_fields = ["first_name", "last_name"] inlines = [FamilyInline, TravellerRouteInline] - readonly_fields = ["travel_start_date", "travel_end_date", "fare_paying", "created_on", "last_edit", "is_active"] + readonly_fields = ["travel_start_date", "travel_end_date", "fare_paying", "created_on", "last_edit", "is_active", "address"] actions = ["export_to_csv", "send_sms", "confirmation_letter", "letter_creator"] fieldsets = [ (None, { @@ -203,17 +196,9 @@ class TravellerAdmin(MyImportExportModelAdmin, CloneModelAdmin, admin.ModelAdmin "school", "first_name", "last_name", - "dob", "year_level", - ] - }), - ('Address', { - 'classes': ('collapse',), - 'fields': [ - "residential_address", - "residential_suburb", - "postal_address", - "postal_suburb", + "dob", + "address", ] }), ('Office Use', { @@ -236,27 +221,6 @@ class TravellerAdmin(MyImportExportModelAdmin, CloneModelAdmin, admin.ModelAdmin "last_edit", ] }), - ('Adult Contacts', { - 'classes': ('collapse',), - 'fields': [ - "parent_A_firstname", - "parent_A_lastname", - "parent_A_phone", - "parent_A_email", - "parent_B_firstname", - "parent_B_lastname", - "parent_B_phone", - "parent_B_email", - "emergency_contact_A_firstname", - "emergency_contact_A_lastname", - "emergency_contact_A_phone", - "emergency_contact_A_relation", - "emergency_contact_B_firstname", - "emergency_contact_B_lastname", - "emergency_contact_B_phone", - "emergency_contact_B_relation" - ] - }), (None, {'fields': ["notes", "shuttle"]}) ] # list_display_links = None diff --git a/busManager/coord/models.py b/busManager/coord/models.py index f99254c..e88c929 100644 --- a/busManager/coord/models.py +++ b/busManager/coord/models.py @@ -175,20 +175,6 @@ class Traveller(models.Model): ("8", "Other Exemption"), ] - RELATIONS = [ - ("1", "Parent"), - ("2", "Step-Parent"), - ("3", "Foster Parent"), - ("4", "Host Family"), - ("5", "Sibling"), - ("6", "Grandparent"), - ("7", "Aunt/Uncle"), - ("8", "Cousin"), - ("9", "Carer"), - ("10", "Case Worker"), - ("11", "Friend/Other"), - ] - school = models.ForeignKey(School, on_delete=models.PROTECT) first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) @@ -196,10 +182,6 @@ class Traveller(models.Model): year_level = models.CharField(max_length=2, choices=YEAR) bus_stops = models.ManyToManyField(BusStop, through='TravellerRoute', blank=True) distance_to_school = models.PositiveSmallIntegerField(blank=True, null=True) - residential_address = models.CharField(max_length=50, blank=True) - residential_suburb = models.ForeignKey(Suburb, on_delete=models.PROTECT, blank=True, null=True, related_name='residential_suburb') - postal_address = models.CharField(max_length=50, blank=True) - postal_suburb = models.ForeignKey(Suburb, on_delete=models.PROTECT, blank=True, null=True, related_name='postal_suburb') travel_start_date = models.DateField(blank=True, null=True) travel_end_date = models.DateField(blank=True, null=True) @@ -214,23 +196,6 @@ class Traveller(models.Model): parent_notified = models.BooleanField() seat_number = models.CharField(max_length=5, blank=True) - parent_A_firstname = models.CharField(max_length=50, blank=True) - parent_A_lastname = models.CharField(max_length=50, blank=True) - parent_A_phone = models.CharField(max_length=15, blank=True) - parent_A_email = models.CharField(max_length=50, blank=True) - parent_B_firstname = models.CharField(max_length=50, blank=True) - parent_B_lastname = models.CharField(max_length=50, blank=True) - parent_B_phone = models.CharField(max_length=15, blank=True) - parent_B_email = models.CharField(max_length=50, blank=True) - emergency_contact_A_firstname = models.CharField(max_length=50, blank=True) - emergency_contact_A_lastname = models.CharField(max_length=50, blank=True) - emergency_contact_A_phone = models.CharField(max_length=15, blank=True) - emergency_contact_A_relation = models.CharField(max_length=50, choices=RELATIONS, blank=True) - emergency_contact_B_firstname = models.CharField(max_length=50, blank=True) - emergency_contact_B_lastname = models.CharField(max_length=50, blank=True) - emergency_contact_B_phone = models.CharField(max_length=15, blank=True) - emergency_contact_B_relation = models.CharField(max_length=50, choices=RELATIONS, blank=True) - created_on = models.DateTimeField(auto_now_add=True, blank=True, null=True) last_edit = models.DateTimeField(auto_now=True, blank=True, null=True) is_archived = models.BooleanField(default=False, verbose_name="Archived") @@ -294,6 +259,14 @@ class Traveller(models.Model): stops = 1 return f"${str(cost * stops)}" + def address(self): + families = Family.objects.filter(traveller__id__exact=self.id) + if families.count() == 0: + return "" + if families.count() == 1: + family = families.first() + return f"{family.residential_address} {family.residential_suburb}" + return "Multiple" def get_parsed_numbers(self, parents=False, emergency=False): return [] # Moved to family model. To remove from traveller model @@ -338,6 +311,9 @@ class Family(models.Model): emergency_contact_B_phone = models.CharField(max_length=15, blank=True) emergency_contact_B_relation = models.CharField(max_length=50, choices=RELATIONS, blank=True) + def __str__(self): + return self.parent_names() + def parent_names(self): a_name = self.parent_A_firstname b_name = self.parent_B_firstname