[Django] #28899: recursive relationship only works one way

5 views
Skip to first unread message

Django

unread,
Dec 6, 2017, 3:10:56 AM12/6/17
to django-...@googlegroups.com
#28899: recursive relationship only works one way
-------------------------------------+-------------------------------------
Reporter: HenrySiau | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords: ForeignKey, self
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
class Catalog(models.Model):
parent = models.ForeignKey('self',related_name='children',
on_delete=models.CASCADE, null=True, blank=True)


}}}

Catalog.parent always return null, while Catalog.children.all() works
fine.

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

Django

unread,
Dec 6, 2017, 5:13:50 AM12/6/17
to django-...@googlegroups.com
#28899: recursive relationship only works one way
-------------------------------------+-------------------------------------
Reporter: HenrySiau | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: needsinfo

Keywords: ForeignKey, self | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

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


Comment:

I tried this and it worked for me:

{{{
In [1]: from test_app.models import Catalog

In [2]: parent = Catalog.objects.create()

In [3]: child = Catalog.objects.create(parent=parent)

In [4]: child.parent
Out[4]: <Catalog: Catalog object (1)>

In [5]: child.refresh_from_db()

In [6]: child.parent
Out[6]: <Catalog: Catalog object (1)>
}}}

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

Reply all
Reply to author
Forward
0 new messages