Created
June 15, 2018 15:02
-
-
Save katie7r/64658d8ade0bfa05fb3912798e3513da to your computer and use it in GitHub Desktop.
Django pseudonymization example (1) - User queryset _filter_or_exclude
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
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