Skip to content

Instantly share code, notes, and snippets.

@hseritt
Created February 25, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hseritt/2dec6052f3da07198dcdcfc2f081ae99 to your computer and use it in GitHub Desktop.
Save hseritt/2dec6052f3da07198dcdcfc2f081ae99 to your computer and use it in GitHub Desktop.
Django form field: somewhat complex queryset filter
self.fields['watchers'] = forms.ModelMultipleChoiceField(
queryset=User.objects.filter(
Q(contact__organization=self.request.user.contact.organization)|
Q(contact__organization__org_type__in=['Owner',])|
Q(groups__name__in=['issues_admin', 'cases_admin'])
).distinct().order_by('username')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment