mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:11:08 -05:00
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
224 lines
5.8 KiB
Python
224 lines
5.8 KiB
Python
from django.contrib import admin
|
|
from django.contrib.gis.admin import GISModelAdmin
|
|
from .models import Park, ParkArea, ParkLocation, Company, CompanyHeadquarters
|
|
|
|
|
|
class ParkLocationInline(admin.StackedInline):
|
|
"""Inline admin for ParkLocation"""
|
|
|
|
model = ParkLocation
|
|
extra = 0
|
|
fields = (
|
|
("city", "state", "country"),
|
|
"street_address",
|
|
"postal_code",
|
|
"point",
|
|
("highway_exit", "best_arrival_time"),
|
|
"parking_notes",
|
|
"seasonal_notes",
|
|
("osm_id", "osm_type"),
|
|
)
|
|
|
|
|
|
class ParkLocationAdmin(GISModelAdmin):
|
|
"""Admin for standalone ParkLocation management"""
|
|
|
|
list_display = (
|
|
"park",
|
|
"city",
|
|
"state",
|
|
"country",
|
|
"latitude",
|
|
"longitude",
|
|
)
|
|
list_filter = ("country", "state")
|
|
search_fields = (
|
|
"park__name",
|
|
"city",
|
|
"state",
|
|
"country",
|
|
"street_address",
|
|
)
|
|
readonly_fields = ("latitude", "longitude", "coordinates")
|
|
fieldsets = (
|
|
("Park", {"fields": ("park",)}),
|
|
(
|
|
"Address",
|
|
{
|
|
"fields": (
|
|
"street_address",
|
|
"city",
|
|
"state",
|
|
"country",
|
|
"postal_code",
|
|
)
|
|
},
|
|
),
|
|
(
|
|
"Geographic Coordinates",
|
|
{
|
|
"fields": ("point", "latitude", "longitude", "coordinates"),
|
|
"description": "Set coordinates by clicking on the map or entering latitude/longitude",
|
|
},
|
|
),
|
|
(
|
|
"Travel Information",
|
|
{
|
|
"fields": (
|
|
"highway_exit",
|
|
"best_arrival_time",
|
|
"parking_notes",
|
|
"seasonal_notes",
|
|
),
|
|
"classes": ("collapse",),
|
|
},
|
|
),
|
|
(
|
|
"OpenStreetMap Integration",
|
|
{"fields": ("osm_id", "osm_type"), "classes": ("collapse",)},
|
|
),
|
|
)
|
|
|
|
def latitude(self, obj):
|
|
return obj.latitude
|
|
|
|
latitude.short_description = "Latitude"
|
|
|
|
def longitude(self, obj):
|
|
return obj.longitude
|
|
|
|
longitude.short_description = "Longitude"
|
|
|
|
|
|
class ParkAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"name",
|
|
"formatted_location",
|
|
"status",
|
|
"operator",
|
|
"property_owner",
|
|
"created_at",
|
|
"updated_at",
|
|
)
|
|
list_filter = ("status", "location__country", "location__state")
|
|
search_fields = (
|
|
"name",
|
|
"description",
|
|
"location__city",
|
|
"location__state",
|
|
"location__country",
|
|
)
|
|
readonly_fields = ("created_at", "updated_at")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
inlines = [ParkLocationInline]
|
|
|
|
def formatted_location(self, obj):
|
|
"""Display formatted location string"""
|
|
return obj.formatted_location
|
|
|
|
formatted_location.short_description = "Location"
|
|
|
|
|
|
class ParkAreaAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "park", "created_at", "updated_at")
|
|
list_filter = ("park",)
|
|
search_fields = ("name", "description", "park__name")
|
|
readonly_fields = ("created_at", "updated_at")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
|
|
class CompanyHeadquartersInline(admin.StackedInline):
|
|
"""Inline admin for CompanyHeadquarters"""
|
|
|
|
model = CompanyHeadquarters
|
|
extra = 0
|
|
fields = (
|
|
("city", "state_province", "country"),
|
|
"street_address",
|
|
"postal_code",
|
|
"mailing_address",
|
|
)
|
|
|
|
|
|
class CompanyHeadquartersAdmin(admin.ModelAdmin):
|
|
"""Admin for standalone CompanyHeadquarters management"""
|
|
|
|
list_display = (
|
|
"company",
|
|
"location_display",
|
|
"city",
|
|
"country",
|
|
"created_at",
|
|
)
|
|
list_filter = ("country", "state_province")
|
|
search_fields = (
|
|
"company__name",
|
|
"city",
|
|
"state_province",
|
|
"country",
|
|
"street_address",
|
|
)
|
|
readonly_fields = ("created_at", "updated_at")
|
|
fieldsets = (
|
|
("Company", {"fields": ("company",)}),
|
|
(
|
|
"Address",
|
|
{
|
|
"fields": (
|
|
"street_address",
|
|
"city",
|
|
"state_province",
|
|
"country",
|
|
"postal_code",
|
|
)
|
|
},
|
|
),
|
|
(
|
|
"Additional Information",
|
|
{"fields": ("mailing_address",), "classes": ("collapse",)},
|
|
),
|
|
(
|
|
"Metadata",
|
|
{"fields": ("created_at", "updated_at"), "classes": ("collapse",)},
|
|
),
|
|
)
|
|
|
|
|
|
class CompanyAdmin(admin.ModelAdmin):
|
|
"""Enhanced Company admin with headquarters inline"""
|
|
|
|
list_display = (
|
|
"name",
|
|
"roles_display",
|
|
"headquarters_location",
|
|
"website",
|
|
"founded_year",
|
|
)
|
|
list_filter = ("roles",)
|
|
search_fields = ("name", "description")
|
|
readonly_fields = ("created_at", "updated_at")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
inlines = [CompanyHeadquartersInline]
|
|
|
|
def roles_display(self, obj):
|
|
"""Display roles as a formatted string"""
|
|
return ", ".join(obj.roles) if obj.roles else "No roles"
|
|
|
|
roles_display.short_description = "Roles"
|
|
|
|
def headquarters_location(self, obj):
|
|
"""Display headquarters location if available"""
|
|
if hasattr(obj, "headquarters"):
|
|
return obj.headquarters.location_display
|
|
return "No headquarters"
|
|
|
|
headquarters_location.short_description = "Headquarters"
|
|
|
|
|
|
# Register the models with their admin classes
|
|
admin.site.register(Park, ParkAdmin)
|
|
admin.site.register(ParkArea, ParkAreaAdmin)
|
|
admin.site.register(ParkLocation, ParkLocationAdmin)
|
|
admin.site.register(Company, CompanyAdmin)
|
|
admin.site.register(CompanyHeadquarters, CompanyHeadquartersAdmin)
|