membershipworks: Improve EventExt admin
This commit is contained in:
parent
f2332dbe37
commit
fbdfb47e60
@ -1,5 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||
from django.utils.html import format_html
|
||||
|
||||
from django_object_actions import DjangoObjectActions, action
|
||||
from django_q.tasks import async_task
|
||||
@ -107,27 +108,45 @@ class EventAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"title",
|
||||
"start",
|
||||
"end",
|
||||
"duration",
|
||||
"count",
|
||||
"cap",
|
||||
"category",
|
||||
"venue",
|
||||
]
|
||||
list_filter = ["category", "calendar", "venue"]
|
||||
list_filter = [
|
||||
"category",
|
||||
"calendar",
|
||||
"venue",
|
||||
("materials_fee", admin.EmptyFieldListFilter),
|
||||
]
|
||||
show_facets = admin.ShowFacets.ALWAYS
|
||||
search_fields = ["eid", "title", "url"]
|
||||
date_hierarchy = "start"
|
||||
readonly_fields = [
|
||||
field.name
|
||||
for field in Event._meta.get_fields()
|
||||
if not (field.auto_created or field.many_to_many or not field.concrete)
|
||||
] + ["duration"]
|
||||
|
||||
@admin.display()
|
||||
@property
|
||||
def readonly_fields(self):
|
||||
fields = []
|
||||
for field in Event._meta.get_fields():
|
||||
if field.auto_created or field.many_to_many or not field.concrete:
|
||||
continue
|
||||
elif field.name == "url":
|
||||
fields.append("_url")
|
||||
else:
|
||||
fields.append(field.name)
|
||||
fields.insert(fields.index("end") + 1, "duration")
|
||||
return fields
|
||||
|
||||
@admin.display(ordering="duration")
|
||||
def duration(self, obj):
|
||||
return obj.duration
|
||||
|
||||
@admin.display(description="URL")
|
||||
def _url(self, obj):
|
||||
return format_html(
|
||||
'<a href="https://claremontmakerspace.org/events/#!event/{0}">{0}</a>',
|
||||
obj.url,
|
||||
)
|
||||
|
||||
def has_add_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user