Browse Source

improve editing of hashed email in admin

master
Fr3deric 6 years ago
parent
commit
346bb2cb5b
  1. 12
      bam/admin.py

12
bam/admin.py

@ -7,14 +7,22 @@ from .models import Account
class AccountInlineForm(forms.ModelForm): class AccountInlineForm(forms.ModelForm):
hashed_email_set = forms.EmailField(label='Set hashed email address') hashed_email_set = forms.EmailField(label='Set hashed email address',
required=False)
hashed_email_clear = forms.BooleanField(label='Clear hashed email address',
required=False)
class Meta: class Meta:
model = Account model = Account
fields = ['hashed_email'] fields = ['hashed_email']
def save(self, commit): def save(self, commit):
self.instance.set_hashed_email(self.cleaned_data['hashed_email_set']) if len(self.cleaned_data['hashed_email_set']) > 0:
self.instance.set_hashed_email(
self.cleaned_data['hashed_email_set']
)
elif self.cleaned_data['hashed_email_clear']:
self.instance.hashed_email = ''
return super().save(commit) return super().save(commit)

Loading…
Cancel
Save