2009-01-16 15:32:31 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
from .models import (
|
2022-02-03 19:24:19 +00:00
|
|
|
Advisor,
|
|
|
|
Album,
|
|
|
|
Band,
|
|
|
|
Bee,
|
|
|
|
Car,
|
|
|
|
CarTire,
|
|
|
|
Event,
|
|
|
|
Inventory,
|
|
|
|
Member,
|
|
|
|
Profile,
|
|
|
|
ReleaseEvent,
|
|
|
|
School,
|
2022-10-17 02:02:56 +00:00
|
|
|
Student,
|
2022-02-03 19:24:19 +00:00
|
|
|
User,
|
|
|
|
VideoStream,
|
2016-12-08 16:00:14 +00:00
|
|
|
)
|
2011-10-13 18:51:33 +00:00
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
|
|
|
|
class WidgetAdmin(admin.AdminSite):
|
|
|
|
pass
|
|
|
|
|
2013-10-10 20:42:30 +00:00
|
|
|
|
2009-03-30 23:16:34 +00:00
|
|
|
class CarAdmin(admin.ModelAdmin):
|
2022-02-03 19:24:19 +00:00
|
|
|
list_display = ["make", "model", "owner"]
|
|
|
|
list_editable = ["owner"]
|
2009-01-16 15:32:31 +00:00
|
|
|
|
2013-10-10 20:42:30 +00:00
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
class CarTireAdmin(admin.ModelAdmin):
|
|
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
|
|
|
if db_field.name == "car":
|
2016-12-08 16:00:14 +00:00
|
|
|
kwargs["queryset"] = Car.objects.filter(owner=request.user)
|
2009-01-16 15:32:31 +00:00
|
|
|
return db_field.formfield(**kwargs)
|
2017-01-21 13:13:44 +00:00
|
|
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
2009-01-16 15:32:31 +00:00
|
|
|
|
2013-10-10 20:42:30 +00:00
|
|
|
|
2010-03-02 02:28:49 +00:00
|
|
|
class EventAdmin(admin.ModelAdmin):
|
2022-02-03 19:24:19 +00:00
|
|
|
raw_id_fields = ["main_band", "supporting_bands"]
|
2010-03-02 02:28:49 +00:00
|
|
|
|
2012-02-23 08:07:07 +00:00
|
|
|
|
2014-04-05 15:58:05 +00:00
|
|
|
class AlbumAdmin(admin.ModelAdmin):
|
2022-02-03 19:24:19 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"cover_art",
|
|
|
|
)
|
|
|
|
readonly_fields = ("cover_art",)
|
2014-04-05 15:58:05 +00:00
|
|
|
|
|
|
|
|
2012-02-23 08:07:07 +00:00
|
|
|
class SchoolAdmin(admin.ModelAdmin):
|
2022-02-03 19:24:19 +00:00
|
|
|
filter_vertical = ("students",)
|
|
|
|
filter_horizontal = ("alumni",)
|
2012-02-23 08:07:07 +00:00
|
|
|
|
2016-11-12 17:11:23 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
site = WidgetAdmin(name="widget-admin")
|
2009-01-16 15:32:31 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(User)
|
|
|
|
site.register(Car, CarAdmin)
|
|
|
|
site.register(CarTire, CarTireAdmin)
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(Member)
|
|
|
|
site.register(Band)
|
|
|
|
site.register(Event, EventAdmin)
|
|
|
|
site.register(Album, AlbumAdmin)
|
2022-02-03 19:24:19 +00:00
|
|
|
site.register(ReleaseEvent, search_fields=["name"])
|
|
|
|
site.register(VideoStream, autocomplete_fields=["release_event"])
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(Inventory)
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(Bee)
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(Advisor)
|
2012-02-23 08:07:07 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(School, SchoolAdmin)
|
2022-10-17 02:02:56 +00:00
|
|
|
site.register(Student)
|
2013-09-07 16:52:14 +00:00
|
|
|
|
2016-12-08 16:00:14 +00:00
|
|
|
site.register(Profile)
|