common model privacy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def exclude_private(self):
    """filter based on 'privacy_field' model class attribute

    'privacy_field' is a two-tuple whose first item is the name of a
    BooleanField and whose second item is a bool which is True if
    '<privacy_field[0]> == True' indicates private (such as a field 'is_private')
    """
    if not hasattr(self.model, "privacy_field"):
        return self

    privacy_field = self.model.privacy_field
    return self.exclude(**{privacy_policy[0]: privacy_field[1]})

from django.db.models import QuerySet
QuerySet.exclude_private = exclude_private

More like this

  1. FieldLevelPermissionsAdmin by buriy 4 years, 5 months ago
  2. CustomQueryManager by zvoase 3 years, 7 months ago
  3. FieldAccessForm (per-field user access for forms derived from models) by Killarny 3 years, 3 months ago
  4. Online boolean switch in the admin list by sasha 4 years, 5 months ago
  5. A ModelChoiceField with support for title in options based on a field in the model by celopes 1 year, 6 months ago

Comments

(Forgotten your password?)