1👍
I’m not really sure what you mean by dynamically creating the queries, given that you only have a set number of fields. But you can perhaps use the fact that the query is a keyword argument to a function, and as such can be replaced with a dictionary and the **
syntax:
kwargs = {'membership__is_tech': True}
ms_tech = microsoft.filter(**kwargs)
(Note that there should be no objects
in the filter you give, as microsoft
is already a queryset, not a model.)
1👍
The most pythonic/djangonic (and also the most normalized) way to do that would be to not include is_billing/is_admin/is_tech to your Membership model as fields but to add a “department” field that could get “admin/billing/tech” values (or is a ForeignKey to your Department model).
If you want to have two departments (for instance admin and blling) then add a ManyToMany field to the Department model.