[Fixed]-Controlling queryset after filtering | Django Admin

1👍

As parent refers to Category objects, why use 0 and not None instead? Parent must be an object not an integer.

  1. Rename your attributes. CompanyId, Parent must become companyId, parent
  2. 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.

👤Kostas

Leave a comment