1👍
As parent refers to Category objects, why use 0 and not None instead? Parent must be an object not an integer.
- Rename your attributes. CompanyId, Parent must become companyId, parent
-
In your Category Class declare parent as:
parent = models.ForeignKey(User, null=True, blank=True, default = None)
Only children categories will have a parent relationship, if a Category is parent then parent will be None. Then, when you want to get parent categories you will filter your query like:
Category.objects.filter(companyId = companyid, parent = None)
Also, parent will be a Category object not an integer.
Source:stackexchange.com