Skip to content

Instantly share code, notes, and snippets.

@katie7r
Created June 15, 2018 15:06
Show Gist options
  • Save katie7r/16beec3eca78ae0abc6e1b19714551f5 to your computer and use it in GitHub Desktop.
Save katie7r/16beec3eca78ae0abc6e1b19714551f5 to your computer and use it in GitHub Desktop.
Django pseudonymization example (1) - User admin fields
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()
phone = forms.CharField()
date_of_birth = forms.DateField()
ip_address = forms.GenericIPAddressField()
class Meta:
model = User
fields = (
'username',
'password',
'name',
'phone',
'date_of_birth',
'ip_address',
)
@admin.register(User)
class UserAdmin(AuthUserAdmin):
form = UserChangeForm
fieldsets = [
(None, {'fields': ['username', 'password']}),
('Personal Data', {'fields': ['name', 'phone', 'date_of_birth', 'ip_address']}),
]
list_display = ('username', '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