mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 08:49:15 +02:00
Ensure we always use raw_ids for related fields in django's admin
This commit is contained in:
parent
8d75d58e82
commit
3895034089
9 changed files with 27 additions and 8 deletions
19
api/funkwhale_api/common/admin.py
Normal file
19
api/funkwhale_api/common/admin.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from django.contrib.admin import register as initial_register, site, ModelAdmin # noqa
|
||||
from django.db.models.fields.related import RelatedField
|
||||
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue