This commit is contained in:
pacnpal
2024-10-29 01:09:14 -04:00
parent d19e5a5c07
commit 2d31847974
195 changed files with 5000 additions and 1213 deletions

View File

@@ -2,6 +2,7 @@ from django.db import models
from django.contrib.contenttypes.fields import GenericRelation
from django.utils.text import slugify
from simple_history.models import HistoricalRecords
import pycountry
class Park(models.Model):
STATUS_CHOICES = [
@@ -15,6 +16,7 @@ class Park(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
location = models.CharField(max_length=255)
country = models.CharField(max_length=2, help_text='Two-letter country code (ISO 3166-1 alpha-2)')
description = models.TextField(blank=True)
owner = models.ForeignKey(
'companies.Company',
@@ -73,6 +75,14 @@ class Park(models.Model):
return cls.objects.get(id=history.id), True
raise cls.DoesNotExist("No park found with this slug")
def get_country_name(self):
"""Get the full country name from the country code"""
try:
country = pycountry.countries.get(alpha_2=self.country)
return country.name if country else self.country
except:
return self.country
class ParkArea(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)