FlexQuery variant that restricts the base QuerySet for a given user.

class django_flexquery.contrib.user_based.UserBasedFlexQuery(base)

This is a slightly modified FlexQuery implementation, accepting either a django.http.HttpRequest or a user object as argument for the custom function and passing the user through.

When no user (or None) is given, the behavior is determined by the no_user_behavior attribute, which may be set to one of the following constants defined on the UserBasedFlexQuery class:

  • NUB_ALL: don’t restrict the queryset

  • NUB_NONE: restrict to the empty queryset (default)

  • NUB_PASS: let the custom function handle a user of None

If the pass_anonymous_user attribute is changed to False, django.contrib.auth.models.AnonymousUser objects are treated as if they were None and the configured no-user behavior comes to play.

Because it can handle an HttpRequest directly, instances of this FlexQuery may also be used in conjunction with the django_filters library as the queryset parameter of filters.

call_bound(user, *args, **kwargs)

Calls the custom function with a user, followed by the remaining arguments.


user (django.contrib.auth.models.User | django.http.HttpRequest | None) – User to filter the queryset for

Returns Q