Opened 10 years ago
Last modified 10 years ago
#26502 closed Uncategorized
Lookup of attribute 'id' on model inheritance models in InlineModelAdmin fails when using fk_name of parent model — at Version 2
| Reported by: | Waldemar Hamm | Owned by: | nobody | 
|---|---|---|---|
| Component: | Forms | Version: | 1.8 | 
| Severity: | Normal | Keywords: | id, model inheritance, inherited model, inline | 
| 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 )
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?
Change History (2)
comment:1 by , 10 years ago
| Description: | modified (diff) | 
|---|---|
| Summary: | Lookup of attribute 'id' on model inheritance models in InlineModelAdmin fails → Lookup of attribute 'id' on model inheritance models in InlineModelAdmin fails when using fk_name of parent model | 
comment:2 by , 10 years ago
| Description: | modified (diff) | 
|---|
  Note:
 See   TracTickets
 for help on using tickets.