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
FlexQueryimplementation, accepting either adjango.http.HttpRequestor 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_behaviorattribute, which may be set to one of the following constants defined on theUserBasedFlexQueryclass:NUB_ALL: don’t restrict the querysetNUB_NONE: restrict to the empty queryset (default)NUB_PASS: let the custom function handle auserofNone
If the
pass_anonymous_userattribute is changed toFalse,django.contrib.auth.models.AnonymousUserobjects are treated as if they wereNoneand the configured no-user behavior comes to play.Because it can handle an
HttpRequestdirectly, instances of thisFlexQuerymay also be used in conjunction with the django_filters library as thequerysetparameter 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