Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@katie7r
Created June 15, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katie7r/64658d8ade0bfa05fb3912798e3513da to your computer and use it in GitHub Desktop.
Save katie7r/64658d8ade0bfa05fb3912798e3513da to your computer and use it in GitHub Desktop.
Django pseudonymization example (1) - User queryset _filter_or_exclude
# ...
class UserQuerySet(models.QuerySet):
def _filter_or_exclude(self, negate, *args, **kwargs):
for field in self.model.MASKING_FIELDS:
value = kwargs.pop(field, None)
if value is not None:
kwargs[f'_{field}'] = mask(value)
return super(UserQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)
# ...
class User(AbstractUser):
MASKING_FIELDS = ['name', 'phone', 'date_of_birth', 'ip_address']
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment