Created
June 15, 2018 15:21
-
-
Save katie7r/fb4ee3698a91b169cef236828c56fda1 to your computer and use it in GitHub Desktop.
Django pseudonymization example (2) - User admin starting point
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
from django import forms | |
from django.contrib import admin | |
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin | |
from django.contrib.auth.forms import UserChangeForm as AuthUserChangeForm | |
from .models import User | |
class UserChangeForm(AuthUserChangeForm): | |
name = forms.CharField(max_length=128) | |
phone = forms.CharField(max_length=16) | |
date_of_birth = forms.DateField() | |
ip_address = forms.GenericIPAddressField() | |
def __init__(self, *args, **kwargs): | |
super(UserChangeForm, self).__init__(*args, **kwargs) | |
self.fields['date_of_birth'].widget = admin.widgets.AdminDateWidget() | |
class Meta: | |
model = User | |
fields = ( | |
'username', | |
'password', | |
'name', | |
'phone', | |
'date_of_birth', | |
'ip_address', | |
) | |
@admin.register(User) | |
class UserAdmin(AuthUserAdmin): | |
form = UserChangeForm | |
list_display = ('username', 'name', 'phone', 'date_of_birth', 'ip_address') | |
fieldsets = [ | |
(None, {'fields': ['username', 'password']}), | |
('Personal Data', {'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