Skip to content

Instantly share code, notes, and snippets.

Embed
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(
f'_{field}'
).validators
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
You can’t perform that action at this time.