contrib.user_based
¶
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 adjango.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 theno_user_behavior
attribute, which may be set to one of the following constants defined on theUserBasedFlexQuery
class:NUB_ALL
: don’t restrict the querysetNUB_NONE
: restrict to the empty queryset (default)NUB_PASS
: let the custom function handle auser
ofNone
If the
pass_anonymous_user
attribute is changed toFalse
,django.contrib.auth.models.AnonymousUser
objects are treated as if they wereNone
and the configured no-user behavior comes to play.Because it can handle an
HttpRequest
directly, instances of thisFlexQuery
may also be used in conjunction with the django_filters library as thequeryset
parameter of filters.-
call_bound
(user, *args, **kwargs)¶ Calls the custom function with a user, followed by the remaining arguments.
- Parameters
user (django.contrib.auth.models.User | django.http.HttpRequest | None) – User to filter the queryset for
- Returns Q