Opened 8 years ago

Closed 8 years ago

Last modified 8 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, 8 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 8 years ago by kapil garg (previous) (diff)

comment:2 by kapil garg, 8 years ago

Component: Uncategorizedcontrib.admin
Type: UncategorizedBug

comment:3 by kapil garg, 8 years ago

Resolution: invalid
Status: newclosed

comment:4 by Tim Graham, 8 years ago

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