Hi there!
I'm searching in a way to limit the queryset which I can get through a model.
Suppose I have the following models (with dependencies):
Company
|- Section
| |- Employee
| |- Task
| `- more models...
|- Customer
| |- Contract
| |- Accounts
| `- other great models ...
`- some more models...
It should be noted that my real models are much deeper and it's not really about business.
With a context processor I have added a company instance to request:
def magic_view(request):
request.company # is a instance of Company model
Now my question is what is the best way to limit the access to the child models of Company to the request instance of company?
I could make it like task = Task.objects.get(pk=4,section__task=task)
, but this is a bad way if my model structure is getting deeper.
Edit: I could give each other model a foreign key to company, but is this a good practice to store relations redundant? Edit 2: No it isn't. See http://stackoverflow.com/questions/3347008/is-it-bad-to-use-redundant-relationships.