#31553: Incorrect query for inline admin when the parent is a proxy model
-----------------------------------------+------------------------
Reporter: Adam Duren | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In our application we have a `ModelAdmin` which displays all rows and a
special `ModelAdmin` which displays a subset of data available on the
table (filtered rows) via the use of ProxyModel. The `ModelAdmin` contains
an inline to a related model.
We noticed that as our related table grew the time it took to render the
one using a proxy model increased drastically. The non-proxy model detail
page loads in sub-second where as the proxy model detail page takes over a
minute.
Upon further inspection we discovered through the use of `django-debug-
toolbar` that the query which was being issued for the proxy model did not
filter the related objects by the foreign key but instead retrieves all
objects from the database.
Below is an example which will reproduce the issue. You can easily verify
by creating two users. Create 100K notifications and assign them to User
A. Click on the detail for User B and observe that User B takes just as
long as User A to load only when using the Proxy model.
{{{#!python
# models.py
class User(models.Model):
name = models.CharField()
class UserProxy(User)
class Meta:
proxy = True
class Notification(models.Model):
user = models.ForeignKey("Person", models.CASCADE)
text = models.CharField()
# admin.py
class NotificationAdmin(admin.TabularInline):
model = Notification
"""
Query for will be:
SELECT *
FROM "app_notification"
WHERE app_notification"."user_id" = 'd0b44931-2d8d-4668-a74b-
38b83ba9abf4'::uuid
"""
class UserAdmin(admin.ModelAdmin):
model = User
"""
Query for will be:
SELECT *
FROM "app_notification"
"""
class UserProxyAdmin(admin.ModelAdmin):
model = UserProxy
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31553>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.ca3371d13703a36399973d3918f4854f%40djangoproject.com.