Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2018 15:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Django pseudonymization example (1) - User admin
# ...
class UserChangeForm(AuthUserChangeForm):
# fields...
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
model = self._meta.model
for field in model.MASKING_FIELDS:
self.fields[field].initial = getattr(self.instance, field)
self.fields[field].validators = model._meta.get_field(
def clean(self, *args, **kwargs):
super(UserChangeForm, self).clean(*args, **kwargs)
for field in self._meta.model.MASKING_FIELDS:
setattr(self.instance, field, self.cleaned_data.get(field))
# Meta...
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment