mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 14:11:09 -05:00
yay
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user