trainvel/sncfgtfs/admin.py

166 lines
5.7 KiB
Python
Raw Normal View History

2024-01-26 00:31:14 +00:00
from django.contrib import admin
from django.forms import BaseInlineFormSet
2024-01-26 00:31:14 +00:00
from sncfgtfs.models import Agency, Calendar, CalendarDate, FeedInfo, GTFSFeed, \
Route, Stop, StopTime, StopTimeUpdate, Transfer, Trip, TripUpdate
class LimitModelFormset(BaseInlineFormSet):
""" Base Inline formset to limit inline Model query results. """
def get_queryset(self):
return super(LimitModelFormset, self).get_queryset()[:50]
2024-01-26 20:06:00 +00:00
2024-02-09 22:15:14 +00:00
class CalendarDateInline(admin.TabularInline):
model = CalendarDate
extra = 0
formset = LimitModelFormset
2024-02-09 22:15:14 +00:00
class TripInline(admin.TabularInline):
model = Trip
extra = 0
formset = LimitModelFormset
2024-02-09 22:15:14 +00:00
autocomplete_fields = ('route', 'service',)
show_change_link = True
ordering = ('service',)
readonly_fields = ('gtfs_feed',)
2024-02-09 22:15:14 +00:00
class StopTimeInline(admin.TabularInline):
model = StopTime
extra = 0
formset = LimitModelFormset
2024-02-09 22:15:14 +00:00
autocomplete_fields = ('stop',)
readonly_fields = ('id',)
2024-02-09 22:15:14 +00:00
show_change_link = True
ordering = ('stop_sequence',)
class TripUpdateInline(admin.StackedInline):
model = TripUpdate
extra = 0
formset = LimitModelFormset
2024-02-10 18:47:34 +00:00
autocomplete_fields = ('trip',)
2024-02-09 22:15:14 +00:00
class StopTimeUpdateInline(admin.StackedInline):
model = StopTimeUpdate
extra = 0
formset = LimitModelFormset
2024-02-10 18:47:34 +00:00
autocomplete_fields = ('trip_update', 'stop_time',)
2024-02-09 22:15:14 +00:00
@admin.register(GTFSFeed)
class GTFSFeedAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'country', 'last_modified',)
list_filter = ('country', 'last_modified',)
search_fields = ('name', 'code',)
readonly_fields = ('code',)
2024-01-26 20:06:00 +00:00
@admin.register(Agency)
class AgencyAdmin(admin.ModelAdmin):
list_display = ('name', 'id', 'url', 'timezone', 'gtfs_feed',)
list_filter = ('gtfs_feed', 'timezone',)
2024-01-27 09:45:34 +00:00
search_fields = ('name',)
autocomplete_fields = ('gtfs_feed',)
2024-01-26 20:06:00 +00:00
@admin.register(Stop)
class StopAdmin(admin.ModelAdmin):
2024-01-27 09:45:34 +00:00
list_display = ('name', 'id', 'lat', 'lon', 'location_type',)
list_filter = ('location_type', 'gtfs_feed',)
2024-01-27 09:45:34 +00:00
search_fields = ('name', 'id',)
ordering = ('name',)
autocomplete_fields = ('parent_station', 'gtfs_feed',)
2024-01-26 20:06:00 +00:00
@admin.register(Route)
class RouteAdmin(admin.ModelAdmin):
list_display = ('__str__', 'id', 'type', 'gtfs_feed',)
list_filter = ('gtfs_feed', 'type', 'agency',)
2024-01-27 09:45:34 +00:00
search_fields = ('long_name', 'short_name', 'id',)
ordering = ('long_name',)
autocomplete_fields = ('agency', 'gtfs_feed',)
2024-02-09 22:15:14 +00:00
inlines = (TripInline,)
2024-01-26 20:06:00 +00:00
@admin.register(Trip)
class TripAdmin(admin.ModelAdmin):
list_display = ('id', 'origin_destination', 'route', 'service', 'headsign', 'direction_id',)
list_filter = ('direction_id', 'route__gtfs_feed',)
2024-02-04 21:20:09 +00:00
search_fields = ('id', 'route__id', 'route__long_name', 'service__id', 'headsign',)
2024-01-27 09:45:34 +00:00
ordering = ('route', 'service',)
autocomplete_fields = ('route', 'service', 'gtfs_feed',)
2024-02-09 22:15:14 +00:00
inlines = (StopTimeInline, TripUpdateInline,)
2024-01-26 20:06:00 +00:00
@admin.register(StopTime)
class StopTimeAdmin(admin.ModelAdmin):
2024-01-27 10:43:01 +00:00
list_display = ('trip', 'stop', 'arrival_time', 'departure_time',
2024-01-27 09:45:34 +00:00
'stop_sequence', 'pickup_type', 'drop_off_type',)
list_filter = ('pickup_type', 'drop_off_type', 'trip__route__gtfs_feed',)
2024-01-27 09:45:34 +00:00
search_fields = ('trip__id', 'stop__name', 'arrival_time', 'departure_time',)
ordering = ('trip', 'stop_sequence',)
autocomplete_fields = ('trip', 'stop',)
readonly_fields = ('id',)
2024-02-09 22:15:14 +00:00
inlines = (StopTimeUpdateInline,)
2024-01-26 20:06:00 +00:00
@admin.register(Calendar)
class CalendarAdmin(admin.ModelAdmin):
list_display = ('id', 'gtfs_feed', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday',
2024-01-27 09:45:34 +00:00
'saturday', 'sunday', 'start_date', 'end_date',)
list_filter = ('gtfs_feed', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday',
2024-01-27 09:45:34 +00:00
'start_date', 'end_date',)
search_fields = ('id', 'start_date', 'end_date',)
autocomplete_fields = ('gtfs_feed',)
ordering = ('gtfs_feed', 'id',)
2024-02-09 22:15:14 +00:00
inlines = (CalendarDateInline, TripInline,)
2024-01-26 20:06:00 +00:00
@admin.register(CalendarDate)
class CalendarDateAdmin(admin.ModelAdmin):
2024-01-27 09:45:34 +00:00
list_display = ('id', 'service_id', 'date', 'exception_type',)
list_filter = ('exception_type', 'date', 'service__gtfs_feed',)
2024-01-27 09:45:34 +00:00
search_fields = ('id', 'date',)
ordering = ('date', 'service_id',)
2024-01-26 20:06:00 +00:00
@admin.register(Transfer)
class TransferAdmin(admin.ModelAdmin):
2024-01-27 09:45:34 +00:00
list_display = ('from_stop', 'to_stop', 'transfer_type', 'min_transfer_time',)
list_filter = ('transfer_type',)
2024-01-28 19:06:55 +00:00
search_fields = ('from_stop__name', 'to_stop__name',)
2024-01-27 09:45:34 +00:00
autocomplete_fields = ('from_stop', 'to_stop',)
2024-01-26 20:06:00 +00:00
@admin.register(FeedInfo)
class FeedInfoAdmin(admin.ModelAdmin):
2024-01-27 14:18:33 +00:00
list_display = ('publisher_name', 'publisher_url', 'lang', 'start_date',
'end_date', 'version',)
search_fields = ('publisher_name', 'publisher_url', 'lang', 'start_date',
'end_date', 'version',)
autocomplete_fields = ('gtfs_feed',)
2024-01-27 14:18:33 +00:00
ordering = ('publisher_name',)
2024-02-04 21:20:09 +00:00
@admin.register(StopTimeUpdate)
class StopTimeUpdateAdmin(admin.ModelAdmin):
list_display = ('trip_update', 'stop_time', 'arrival_delay', 'arrival_time',
'departure_delay', 'departure_time', 'schedule_relationship',)
list_filter = ('schedule_relationship', 'trip_update__trip__gtfs_feed',)
2024-02-06 07:01:56 +00:00
search_fields = ('trip_update__trip__id', 'stop_time__stop__name', 'arrival_time', 'departure_time',)
2024-02-04 21:20:09 +00:00
ordering = ('trip_update', 'stop_time',)
2024-02-10 18:47:34 +00:00
autocomplete_fields = ('trip_update', 'stop_time',)
2024-02-04 21:20:09 +00:00
@admin.register(TripUpdate)
class TripUpdateAdmin(admin.ModelAdmin):
list_display = ('trip_id', 'start_date', 'start_time',)
2024-02-06 07:01:56 +00:00
list_filter = ('start_date', 'schedule_relationship',)
search_fields = ('trip__id', 'start_date', 'start_time',)
2024-02-04 21:20:09 +00:00
ordering = ('trip_id', 'start_date', 'start_time',)
autocomplete_fields = ('trip',)