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. CustomQueryManager by zvoase 4 years, 11 months ago
  2. FieldLevelPermissionsAdmin by buriy 5 years, 9 months ago
  3. Modifying the fields of a third/existing model class by marinho 2 years, 5 months ago
  4. is_dirty and dict of changed values by jaredthane 3 years, 10 months ago
  5. convenience parent class for UserProfile model by willhardy 4 years, 1 month ago

Comments

(Forgotten your password?)