#35029: DisallowedModelAdminLookup for uuid field
-------------------------------------+-------------------------------------
     Reporter:  jameslao             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.admin        |                  Version:  5.0
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  DisallowedModelAdminLookup, uuid   |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by jameslao:

Old description:

> In Django 5.0, 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
> }}}

New description:

 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
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/35029#comment:1>
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/0107018c5aba1019-e1207bb6-ca2e-42b3-acf8-2d75b5b9625e-000000%40eu-central-1.amazonses.com.

Reply via email to