#26502: Lookup of attribute 'id' on model inheritance models in InlineModelAdmin
fails when using fk_name of parent model
-------------------------------------+-------------------------------------
     Reporter:  Braintelligence      |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Forms                |                  Version:  1.8
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  id, model            |             Triage Stage:
  inheritance, inherited model,      |  Unreviewed
  inline                             |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Braintelligence:

Old description:

> Having two models, of which one inherits from another, for example:
>
> {{{
> class Person(models.Model):
>     firstname = models.CharField(max_length=255, blank=True)
>     lastname = models.CharField(max_length=255)
>     person_something = models.ForeignKey(Something)
>
> class Author(Person):
>     publisher = models.CharField(max_length=255)
>     author_something = models.ForeignKey(Something)
> }}}
>
> I can't access the id field like so:
>
> {{{
> class AuthorInline(admin.StackedInline):
>     model = Author
>     fk_name = 'person_something'
>     fields = ['id', 'lastname', 'publisher']
>
> class SomethingAdmin(admin.ModelAdmin):
>     inlines = [ AuthorInline ]
>     list_display = ('somethinga', 'somethingb')
> }}}
>
> I get a KeyError and it says:
> "Key 'id' not found in 'AuthorForm'"
>
> Using Author._meta.get_all_field_names() the field id is definitely in
> the model, though. Removing 'id' from the fields list makes everything
> work.
>
> Am I doing something wrong or is this a legit bug?

New description:

 Having two models, of which one inherits from another, for example:

 {{{
 class Person(models.Model):
     firstname = models.CharField(max_length=255, blank=True)
     lastname = models.CharField(max_length=255)
     person_something = models.ForeignKey(Something)

 class Author(Person):
     publisher = models.CharField(max_length=255)
     author_something = models.ForeignKey(Something)
 }}}

 I can't access the id field like so:

 {{{
 class AuthorInline(admin.StackedInline):
     model = Author
     fk_name = 'person_something'
     fields = ['id', 'lastname', 'publisher']
     readonly_fields = fields

 class SomethingAdmin(admin.ModelAdmin):
     inlines = [ AuthorInline ]
     list_display = ('somethinga', 'somethingb')
 }}}

 I get a KeyError and it says:
 "Key 'id' not found in 'AuthorForm'"

 Using Author._meta.get_all_field_names() the field id is definitely in the
 model, though. Removing 'id' from the fields list makes everything work.

 Am I doing something wrong or is this a legit bug?

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26502#comment:11>
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/073.7a86a25639f885646d2ea76b24752d06%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to