How to restrict Model.objects.all() to data pertaining to one organization

21 views
Skip to first unread message

Mauro Crociara

unread,
Apr 10, 2018, 7:04:03 AM4/10/18
to Django users
Hi everyone,

I posted this question on Stackoverflow almost 4 months ago and asked a couple of times on #django IRC channel on Freenode, but none gave me a suggestion about the problem. Up to now I have no solution and no clue how to proceed. Maybe you can show me the right direction.

Thanks for your time and support!
Mauro

Jani Tiainen

unread,
Apr 10, 2018, 7:11:56 AM4/10/18
to django...@googlegroups.com
Hi.

Model.objects.filter (organization=organization)

Or did you mean something else?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9647aa9-4743-4bf3-9202-72329e4c38af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason

unread,
Apr 10, 2018, 7:35:17 AM4/10/18
to Django users
Looking at your SO question, seems to me you're expecting some magic to happen without any pertinent information available to execute that filter.

There are a couple things I can think of to add more information to the incoming request to help you use the custom model manager.  For example, when a user logs in, you specify an organization name that's included in all API requests as a query param, and said param is used to execute the db query.  

Gabriel - Iulian Dumbrava

unread,
Apr 10, 2018, 7:53:57 AM4/10/18
to Django users
Please take a look at this comparison grid. At least one of those packages allows automatic filtering of queries if you set it up properly. For example, each table must have that 'organisation' field to filter on it.

Gabriel - Iulian Dumbrava

unread,
Apr 10, 2018, 7:56:23 AM4/10/18
to Django users
I think django-multitenant gives you the best answer.


marți, 10 aprilie 2018, 14:04:03 UTC+3, Mauro Crociara a scris:
Reply all
Reply to author
Forward
0 new messages