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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35029>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
New description:
On Django 5.0 and MariaDB 11.0.4, if we create a model with primary ID
in models.py
in admin.py
{{{
from . import models
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/35029#comment:1>
Comment (by James Lao):
Seems like this issue is not limited to UUID but to any field other than
AutoField used as id. Maybe we should revert this change?
The difference is in django/contrib/admin/options.py => BaseModelAdmin =>
lookup_allowed
in 4.2.8
{{{
for part in lookup.split(LOOKUP_SEP):
try:
field = model._meta.get_field(part)
except FieldDoesNotExist:
# Lookups on nonexistent fields are ok, since they're
ignored
# later.
break
# It is allowed to filter on values that would be found from
local
# model anyways. For example, if you filter on
employee__department__id,
# then the id value would be found already from
employee__department_id.
if not prev_field or (
prev_field.is_relation
and field not in prev_field.path_infos[-1].target_fields
):
relation_parts.append(part)
if not getattr(field, "path_infos", None):
# This is not a relational field, so further parts
# must be transforms.
break
prev_field = field
model = field.path_infos[-1].to_opts.model
}}}
In 5.0.0
{{{
for part in lookup.split(LOOKUP_SEP):
try:
field = model._meta.get_field(part)
except FieldDoesNotExist:
# Lookups on nonexistent fields are ok, since they're
ignored
# later.
break
if not prev_field or (
prev_field.is_relation
and field not in model._meta.parents.values()
and field is not model._meta.auto_field
and (
model._meta.auto_field is None
or part not in getattr(prev_field, "to_fields", [])
)
):
relation_parts.append(part)
if not getattr(field, "path_infos", None):
# This is not a relational field, so further parts
# must be transforms.
break
prev_field = field
model = field.path_infos[-1].to_opts.model
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35029#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
Seems to be the same as #35020
--
Ticket URL: <https://code.djangoproject.com/ticket/35029#comment:3>
* resolution: fixed => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/35029#comment:4>