Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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