Opened 12 months ago
Last modified 12 months ago
#35029 closed Bug
DisallowedModelAdminLookup for uuid field — at Version 1
Reported by: | James Lao | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 5.0 |
Severity: | Normal | Keywords: | DisallowedModelAdminLookup, uuid |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
On Django 5.0 and MariaDB 11.0.4, if we create a model with primary ID field with UUIDField, and another model referencing it, then in Django admin, if we create a filter of the second model with the first model, an error of DisallowedModelAdminLookup will be thrown.
in models.py
from django.db import models import uuid # Create your models here. class Request(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='Request ID') name = models.CharField(max_length=50, blank=True) class RequestItem(models.Model): request = models.ForeignKey(Request, on_delete=models.CASCADE, related_name='items') description = models.CharField(max_length=255, blank=True)
in admin.py
from . import models @admin.register(models.RequestItem) class RequestItemAdmin(admin.ModelAdmin): list_display = ( 'request', ) list_filter = ( 'request', ) @admin.register(models.Request) class RequestAdmin(admin.ModelAdmin): list_display = ( 'id', 'name' ) list_filter = ( 'id', )
Then the filter of request in RequestItemAdmin will throw an error
DisallowedModelAdminLookup at /admin/uid/requestitem/ Filtering by request__id__exact not allowed
Note:
See TracTickets
for help on using tickets.