|
|
@ -1,22 +1,28 @@ |
|
|
|
from django.contrib import admin |
|
|
|
from django.contrib import admin |
|
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
|
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
|
|
|
from django.contrib.auth.models import User |
|
|
|
from django.contrib.auth.models import User |
|
|
|
|
|
|
|
from django.contrib.auth.hashers import make_password |
|
|
|
from django import forms |
|
|
|
from django import forms |
|
|
|
from .models import Account |
|
|
|
from .models import Account |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountInlineForm(forms.ModelForm): |
|
|
|
class AccountInlineForm(forms.ModelForm): |
|
|
|
hased_email_set = forms.EmailField(label='Set hashed email address') |
|
|
|
hashed_email_set = forms.EmailField(label='Set hashed email address') |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
model = Account |
|
|
|
model = Account |
|
|
|
fields = ['hashed_email'] |
|
|
|
fields = ['hashed_email'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, commit): |
|
|
|
|
|
|
|
self.instance.set_hashed_email(self.cleaned_data['hashed_email_set']) |
|
|
|
|
|
|
|
return super().save(commit) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountInline(admin.StackedInline): |
|
|
|
class AccountInline(admin.StackedInline): |
|
|
|
model = Account |
|
|
|
model = Account |
|
|
|
can_delete = False |
|
|
|
can_delete = False |
|
|
|
form = AccountInlineForm |
|
|
|
form = AccountInlineForm |
|
|
|
|
|
|
|
readonly_fields = ['hashed_email'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserAdmin(BaseUserAdmin): |
|
|
|
class UserAdmin(BaseUserAdmin): |
|
|
@ -25,3 +31,4 @@ class UserAdmin(BaseUserAdmin): |
|
|
|
|
|
|
|
|
|
|
|
admin.site.unregister(User) |
|
|
|
admin.site.unregister(User) |
|
|
|
admin.site.register(User, UserAdmin) |
|
|
|
admin.site.register(User, UserAdmin) |
|
|
|
|
|
|
|
admin.site.register(Account) |
|
|
|