mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:31: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.
125 lines
3.8 KiB
Python
125 lines
3.8 KiB
Python
from django.contrib.postgres.fields import ArrayField
|
|
from django.db import models
|
|
from core.models import TrackedModel
|
|
import pghistory
|
|
|
|
@pghistory.track()
|
|
class Company(TrackedModel):
|
|
|
|
# Import managers
|
|
from ..managers import CompanyManager
|
|
|
|
objects = CompanyManager()
|
|
class CompanyRole(models.TextChoices):
|
|
OPERATOR = 'OPERATOR', 'Park Operator'
|
|
PROPERTY_OWNER = 'PROPERTY_OWNER', 'Property Owner'
|
|
|
|
name = models.CharField(max_length=255)
|
|
slug = models.SlugField(max_length=255, unique=True)
|
|
roles = ArrayField(
|
|
models.CharField(max_length=20, choices=CompanyRole.choices),
|
|
default=list,
|
|
blank=True
|
|
)
|
|
description = models.TextField(blank=True)
|
|
website = models.URLField(blank=True)
|
|
|
|
# Operator-specific fields
|
|
founded_year = models.PositiveIntegerField(blank=True, null=True)
|
|
parks_count = models.IntegerField(default=0)
|
|
rides_count = models.IntegerField(default=0)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class Meta:
|
|
ordering = ['name']
|
|
verbose_name_plural = 'Companies'
|
|
|
|
class CompanyHeadquarters(models.Model):
|
|
"""
|
|
Simple address storage for company headquarters without coordinate tracking.
|
|
Focus on human-readable location information for display purposes.
|
|
"""
|
|
# Relationships
|
|
company = models.OneToOneField(
|
|
'Company',
|
|
on_delete=models.CASCADE,
|
|
related_name='headquarters'
|
|
)
|
|
|
|
# Address Fields (No coordinates needed)
|
|
street_address = models.CharField(
|
|
max_length=255,
|
|
blank=True,
|
|
help_text="Mailing address if publicly available"
|
|
)
|
|
city = models.CharField(
|
|
max_length=100,
|
|
db_index=True,
|
|
help_text="Headquarters city"
|
|
)
|
|
state_province = models.CharField(
|
|
max_length=100,
|
|
blank=True,
|
|
db_index=True,
|
|
help_text="State/Province/Region"
|
|
)
|
|
country = models.CharField(
|
|
max_length=100,
|
|
default='USA',
|
|
db_index=True,
|
|
help_text="Country where headquarters is located"
|
|
)
|
|
postal_code = models.CharField(
|
|
max_length=20,
|
|
blank=True,
|
|
help_text="ZIP or postal code"
|
|
)
|
|
|
|
# Optional mailing address if different or more complete
|
|
mailing_address = models.TextField(
|
|
blank=True,
|
|
help_text="Complete mailing address if different from basic address"
|
|
)
|
|
|
|
# Metadata
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
@property
|
|
def formatted_location(self):
|
|
"""Returns a formatted address string for display."""
|
|
components = []
|
|
if self.street_address:
|
|
components.append(self.street_address)
|
|
if self.city:
|
|
components.append(self.city)
|
|
if self.state_province:
|
|
components.append(self.state_province)
|
|
if self.postal_code:
|
|
components.append(self.postal_code)
|
|
if self.country and self.country != 'USA':
|
|
components.append(self.country)
|
|
return ", ".join(components) if components else f"{self.city}, {self.country}"
|
|
|
|
@property
|
|
def location_display(self):
|
|
"""Simple city, state/country display for compact views."""
|
|
parts = [self.city]
|
|
if self.state_province:
|
|
parts.append(self.state_province)
|
|
elif self.country != 'USA':
|
|
parts.append(self.country)
|
|
return ", ".join(parts) if parts else "Unknown Location"
|
|
|
|
def __str__(self):
|
|
return f"{self.company.name} Headquarters - {self.location_display}"
|
|
|
|
class Meta:
|
|
verbose_name = "Company Headquarters"
|
|
verbose_name_plural = "Company Headquarters"
|
|
ordering = ['company__name']
|
|
indexes = [
|
|
models.Index(fields=['city', 'country']),
|
|
] |