[Django] #28018: OneToOneField not working with inlineadmin

4 views
Skip to first unread message

Django

unread,
Apr 4, 2017, 2:45:41 PM4/4/17
to django-...@googlegroups.com
#28018: OneToOneField not working with inlineadmin
-----------------------------------------+------------------------
Reporter: alex | 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 |
-----------------------------------------+------------------------
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
class dInlineAdmin(admin.TabularInline):
model = d

# admin.py
@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

--
Ticket URL: <https://code.djangoproject.com/ticket/28018>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 5, 2017, 8:02:31 AM4/5/17
to django-...@googlegroups.com
#28018: OneToOneField not working with inlineadmin
-------------------------------+--------------------------------------

Reporter: alex | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by kapil garg):

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 bSpecializedAdmin(admin.ModelAdmin):
inlines = [
aInlineAdmin,
]
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28018#comment:1>

Django

unread,
Apr 5, 2017, 8:03:44 AM4/5/17
to django-...@googlegroups.com
#28018: OneToOneField not working with inlineadmin
-------------------------------+--------------------------------------
Reporter: alex | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by kapil garg):

* type: Uncategorized => Bug
* component: Uncategorized => contrib.admin


--
Ticket URL: <https://code.djangoproject.com/ticket/28018#comment:2>

Django

unread,
Apr 5, 2017, 8:05:20 AM4/5/17
to django-...@googlegroups.com
#28018: OneToOneField not working with inlineadmin
-------------------------------+--------------------------------------
Reporter: alex | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by kapil garg):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/28018#comment:3>

Django

unread,
Apr 5, 2017, 8:30:45 AM4/5/17
to django-...@googlegroups.com
#28018: OneToOneField not working with inlineadmin
-------------------------------+--------------------------------------
Reporter: alex | Owner: nobody

Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Tim Graham:

Old description:

> 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
> class dInlineAdmin(admin.TabularInline):
> model = d
>
> # admin.py
> @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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28018#comment:4>

Reply all
Reply to author
Forward
0 new messages