#27595: In admin panel, ForeignKey to model subclass using UUID as primary key 
is
not automatically "selected"
-----------------------------------------+------------------------
               Reporter:  oyooyo         |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  1.10
               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              |
-----------------------------------------+------------------------
 Sample models.py:
 {{{
 from django.db import models

 import uuid

 class Base_Model(models.Model):
         id = models.UUIDField(primary_key = True, default=uuid.uuid4,
 editable=False)
         # id = models.AutoField(primary_key = True)
         prototype = models.ForeignKey('Prototype_Model', blank=True,
 null=True)
         def __str__(self):
                 return str(self.id)

 class Prototype_Model(Base_Model):
         pass
 }}}

 Sample admin.py:
 {{{
 from django.contrib import admin

 from .models import Prototype_Model

 class Base_Model_Admin(admin.ModelAdmin):
         list_display = ['id', 'prototype']

 admin.site.register(Prototype_Model, Base_Model_Admin)
 }}}

 Steps to reproduce:
 1. Create a Prototype_Model via the admin. Leave the "prototype"
 ForeignKey field empty.
 2. Create another Prototype_Model via the admin. For the "prototype"
 ForeignKey field, choose the first created Prototype_Model from the
 dropdown
 3. Switch to the Prototype_Model list view, it should show that the
 "prototype" ForeignKey field of the second Prototype_Model indeed
 references the first model
 4. Click on this second Prototype_Model in order to access the change/edit
 model form and look at the dropdown for the "prototype" field. The
 expected behaviour is that the dropdown should have the referenced first
 model automatically selected, but instead, nothing is automatically
 selected.

 **If an AutoField is used instead of a UUIDField as the primary key "id"
 field (see commented out line in Base_Model), the behaviour is as
 expected.**

--
Ticket URL: <https://code.djangoproject.com/ticket/27595>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.7ff6190e8b0544c3caeec5d05ac0c424%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to