Verified Commit 38950340 authored by Agate's avatar Agate 💬

Ensure we always use raw_ids for related fields in django's admin

parent 8d75d58e
......@@ -5,7 +5,7 @@ from django.conf import settings
from django.conf.urls import url
from django.urls import include, path
from django.conf.urls.static import static
from django.contrib import admin
from funkwhale_api.common import admin
from django.views import defaults as default_views
......
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
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
......
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
from . import tasks
......
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
......
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
......
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
......
from django.contrib import admin
from funkwhale_api.common import admin
from . import models
......
......@@ -2,7 +2,7 @@
from __future__ import absolute_import, unicode_literals
from django import forms
from django.contrib import admin
from funkwhale_api.common import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.utils.translation import ugettext_lazy as _
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment