Opened 7 years ago
Closed 7 years ago
#28899 closed Uncategorized (needsinfo)
recursive relationship only works one way
Reported by: | HenrySiau | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Normal | Keywords: | ForeignKey, self |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Note:
See TracTickets
for help on using tickets.
I tried this and it worked for me: