mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 03:51:09 -05:00
- Implemented extensive test cases for the Parks API, covering endpoints for listing, retrieving, creating, updating, and deleting parks. - Added tests for filtering, searching, and ordering parks in the API. - Created tests for error handling in the API, including malformed JSON and unsupported methods. - Developed model tests for Park, ParkArea, Company, and ParkReview models, ensuring validation and constraints are enforced. - Introduced utility mixins for API and model testing to streamline assertions and enhance test readability. - Included integration tests to validate complete workflows involving park creation, retrieval, updating, and deletion.
34 lines
1012 B
Python
34 lines
1012 B
Python
from django.db import models
|
|
from django.urls import reverse
|
|
from django.utils.text import slugify
|
|
from typing import Tuple, Any
|
|
import pghistory
|
|
|
|
from 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")
|
|
name = models.CharField(max_length=255)
|
|
slug = models.SlugField(max_length=255)
|
|
description = models.TextField(blank=True)
|
|
opening_date = models.DateField(null=True, blank=True)
|
|
closing_date = models.DateField(null=True, blank=True)
|
|
|
|
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:
|
|
unique_together = ('park', 'slug') |