From efabaed1ef7ec2baafabed9dfd3c08dc192d98bd Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 5 Sep 2018 10:30:12 -0500 Subject: added total_price to campsite admin --- app/locations/admin.py | 2 +- app/locations/models.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'app/locations') diff --git a/app/locations/admin.py b/app/locations/admin.py index f185e97..01da84d 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -248,7 +248,7 @@ class CheckInAdmin(OLAdminBase): @admin.register(Campsite) class CampsiteAdmin(OLAdminBase): form = LGEntryForm - list_display = ('name', 'location', 'date_arrived', 'date_left', 'campsite_type', 'campsite_price', 'nights_stayed') + list_display = ('name', 'location', 'date_arrived', 'date_left', 'campsite_type', 'total_price', 'nights_stayed') list_filter = ('date_arrived', 'campsite_type') search_fields = ['location__name', ] fieldsets = ( diff --git a/app/locations/models.py b/app/locations/models.py index 6745ff2..24b3234 100644 --- a/app/locations/models.py +++ b/app/locations/models.py @@ -245,13 +245,21 @@ class Campsite(models.Model): def lat(self): '''Get the site's latitude.''' return self.point.y - + @property def nights_stayed(self): '''Get the number of nights we spent there ''' delta = self.date_left - self.date_arrived return delta.days + @property + def total_price(self): + '''Get the price and total price for display in admin ''' + if not self.campsite_price: + price = 0 + total = self.nights_stayed * price + return "{0} ({1}/night)".format(total, self.campsite_price) + def save(self, *args, **kwargs): created = self.pk is None if not created: -- cgit v1.2.3-70-g09d2