音楽で楽しみましょう!-Let's have fun with music!-
Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
parent
7c3206bf83
commit
54c6d22102
517 changed files with 637 additions and 639 deletions
65
api/funquail_api/common/admin.py
Normal file
65
api/funquail_api/common/admin.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from django.contrib.admin import site # noqa: F401
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.contrib.admin import register as initial_register
|
||||
from django.db.models.fields.related import RelatedField
|
||||
|
||||
from . import models, tasks
|
||||
|
||||
|
||||
def register(model):
|
||||
"""
|
||||
To make the admin more performant, we ensure all the the relations
|
||||
are listed under raw_id_fields
|
||||
"""
|
||||
|
||||
def decorator(modeladmin):
|
||||
raw_id_fields = []
|
||||
for field in model._meta.fields:
|
||||
if isinstance(field, RelatedField):
|
||||
raw_id_fields.append(field.name)
|
||||
setattr(modeladmin, "raw_id_fields", raw_id_fields)
|
||||
return initial_register(model)(modeladmin)
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def apply(modeladmin, request, queryset):
|
||||
queryset.update(is_approved=True)
|
||||
for id in queryset.values_list("id", flat=True):
|
||||
tasks.apply_mutation.delay(mutation_id=id)
|
||||
|
||||
|
||||
apply.short_description = "Approve and apply"
|
||||
|
||||
|
||||
@register(models.Mutation)
|
||||
class MutationAdmin(ModelAdmin):
|
||||
list_display = [
|
||||
"uuid",
|
||||
"type",
|
||||
"created_by",
|
||||
"creation_date",
|
||||
"applied_date",
|
||||
"is_approved",
|
||||
"is_applied",
|
||||
]
|
||||
search_fields = ["created_by__preferred_username"]
|
||||
list_filter = ["type", "is_approved", "is_applied"]
|
||||
actions = [apply]
|
||||
|
||||
|
||||
@register(models.Attachment)
|
||||
class AttachmentAdmin(ModelAdmin):
|
||||
list_display = [
|
||||
"uuid",
|
||||
"actor",
|
||||
"url",
|
||||
"file",
|
||||
"size",
|
||||
"mimetype",
|
||||
"creation_date",
|
||||
"last_fetch_date",
|
||||
]
|
||||
list_select_related = True
|
||||
search_fields = ["actor__domain__name"]
|
||||
list_filter = ["mimetype"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue