Files
thrillwiki_django_no_react/backend/apps/parks/models/areas.py

48 lines
1.4 KiB
Python

import pghistory
from django.db import models
from django.utils.text import slugify
from apps.core.history import TrackedModel
from .parks import Park
@pghistory.track()
class ParkArea(TrackedModel):
# Import managers
from ..managers import ParkAreaManager
objects = ParkAreaManager()
id: int # Type hint for Django's automatic id field
park = models.ForeignKey(
Park,
on_delete=models.CASCADE,
related_name="areas",
help_text="Park this area belongs to",
)
name = models.CharField(max_length=255, help_text="Name of the park area")
slug = models.SlugField(
max_length=255, help_text="URL-friendly identifier (unique within park)"
)
description = models.TextField(blank=True, help_text="Detailed description of the area")
opening_date = models.DateField(
null=True, blank=True, help_text="Date this area opened"
)
closing_date = models.DateField(
null=True, blank=True, help_text="Date this area closed (if applicable)"
)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super().save(*args, **kwargs)
def __str__(self):
return self.name
class Meta(TrackedModel.Meta):
verbose_name = "Park Area"
verbose_name_plural = "Park Areas"
ordering = ["park", "name"]
unique_together = ("park", "slug")