This commit is contained in:
pacnpal
2024-10-31 17:27:31 +00:00
parent c1591af871
commit 71272e36a6
10 changed files with 119 additions and 78 deletions

View File

@@ -66,17 +66,7 @@ class Park(models.Model):
self.slug = slugify(self.name)
# Update the location field to combine country, region, and city
location_parts = []
if self.city:
location_parts.append(self.city.name)
if self.region:
location_parts.append(self.region.name)
if self.country:
location_parts.append(self.country.name)
# Only update location if we have parts to combine
if location_parts:
self.location = ', '.join(location_parts)
self.location = self.get_formatted_location()
super().save(*args, **kwargs)
@@ -93,15 +83,15 @@ class Park(models.Model):
raise cls.DoesNotExist("No park found with this slug")
def get_formatted_location(self):
"""Get a formatted location string combining city, region, and country"""
location_parts = []
if self.city:
location_parts.append(self.city.name)
if self.region:
location_parts.append(self.region.name)
if self.country:
location_parts.append(self.country.name)
return ', '.join(location_parts)
"""Get a formatted location string: $COUNTRY, $REGION, $CITY"""
location = self.country.name
if self.region and self.city:
location += f", {self.region.name}, {self.city.name}"
elif self.region:
location += f", {self.region.name}"
return location
class ParkArea(models.Model):
name = models.CharField(max_length=255)