mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 11:51:10 -05:00
Add management command to seed comprehensive sample data for ThrillWiki application
- Implemented cleanup of existing sample data to avoid conflicts. - Created functions to generate companies, parks, rides, park areas, and reviews. - Ensured proper relationships between models during data creation. - Added logging for better tracking of data seeding process. - Included checks for required database tables before seeding.
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db import models
|
||||
from django.utils.text import slugify
|
||||
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'
|
||||
@@ -23,12 +26,17 @@ class Company(TrackedModel):
|
||||
)
|
||||
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 save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -36,6 +44,7 @@ class Company(TrackedModel):
|
||||
ordering = ['name']
|
||||
verbose_name_plural = 'Companies'
|
||||
|
||||
|
||||
class CompanyHeadquarters(models.Model):
|
||||
"""
|
||||
Simple address storage for company headquarters without coordinate tracking.
|
||||
@@ -47,7 +56,7 @@ class CompanyHeadquarters(models.Model):
|
||||
on_delete=models.CASCADE,
|
||||
related_name='headquarters'
|
||||
)
|
||||
|
||||
|
||||
# Address Fields (No coordinates needed)
|
||||
street_address = models.CharField(
|
||||
max_length=255,
|
||||
@@ -76,13 +85,13 @@ class CompanyHeadquarters(models.Model):
|
||||
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)
|
||||
@@ -102,7 +111,7 @@ class CompanyHeadquarters(models.Model):
|
||||
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."""
|
||||
@@ -122,4 +131,4 @@ class CompanyHeadquarters(models.Model):
|
||||
ordering = ['company__name']
|
||||
indexes = [
|
||||
models.Index(fields=['city', 'country']),
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user