Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28018 closed Bug (invalid)

OneToOneField not working with inlineadmin

Reported by: alex Owned by: nobody
Component: contrib.admin Version: 1.10
Severity: Normal Keywords:
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 Tim Graham)

This class hierarchy doesn't work with inlineadmin:

class hierarchy:

models.py:

class d:
  pass
class a:
  d = models.OneToOneField(d, on_delete=models.CASCADE, related_name="host")
class b:
  pass

admin.py

class dInlineAdmin(admin.TabularInline):
    model = d

@admin.register(b)
class bSpecializedAdmin(admin.ModelAdmin):
    inlines = [
        dInlineAdmin,
    ]

Error message:
<class 'x.admin.RequirementInlineAdmin'>: (admin.E202) 'x.Requirement' has no field named 'host'.

'host' is the related_name

Change History (4)

comment:1 by kapil garg, 7 years ago

I think, InlineModelAdmin works for models which have related objects. In your example,

# admin.py
class dInlineAdmin(admin.TabularInline):
    model = d

@admin.register(b)
class bSpecializedAdmin(admin.ModelAdmin):
    inlines = [
        dInlineAdmin,
    ]

model "b" is not related to model "d" and thus causing the exception. The following code will work

# admin.py
class aInlineAdmin(admin.TabularInline):
    model = a

@admin.register(d)
class dSpecializedAdmin(admin.ModelAdmin):
    inlines = [
        aInlineAdmin,
    ]
Last edited 7 years ago by kapil garg (previous) (diff)

comment:2 by kapil garg, 7 years ago

Component: Uncategorizedcontrib.admin
Type: UncategorizedBug

comment:3 by kapil garg, 7 years ago

Resolution: invalid
Status: newclosed

comment:4 by Tim Graham, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top