34👍
✅
From the docs, you can build your own form, something like this:
from django.forms import ModelForm, PasswordInput
class TwitterUserForm(ModelForm):
class Meta:
model = TwitterUser
widgets = {
'password': PasswordInput(),
}
Or you can do it like this:
from django.forms import ModelForm, PasswordInput
class TwitterUserForm(ModelForm):
password = forms.CharField(widget=PasswordInput())
class Meta:
model = TwitterUser
I’ve no idea which one is better – I slightly prefer the first one, since it means you’ll still get any help_text
and verbose_name
from your model.
Regardless of which of those two approaches you take, you can then make the admin use your form like this (in your app’s admin.py
):
from django.contrib import admin
class TwitterUserAdmin(admin.ModelAdmin):
form = TwitterUserForm
admin.site.register(TwitterUser, TwitterUserAdmin)
Source:stackexchange.com