1π
class User(AbstractUser):
class Meta:
app_label = 'auth'
This can solve your problem but may cause some errors when you migrate your app. The other hack is define get_app_list
in your AdminSite
.
1π
I think what youβre looking for is replacing the django user model. To do this, see the answer on this post: Extending the User model with custom fields in Django. I would suggest going the extending route, but that would mean both parent and child model would have to be registered.
If you really want one single model, just set the AUTH_USER_MODEL
setting to your model. This essentially replaces the default model.
In your settings.py:
AUTH_USER_MODEL = "appname.UserModelName"
For more info on replacing the user model, see https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model.
- [Django]-How to implement followers/following in Django
- [Django]-Error Saving geodjango PointField
- [Django]-Django Model Forms β Setting a required field
0π
In admin.py use
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
UserAdmin.list_display = ('email', 'first_name', 'last_name', 'is_active', 'date_joined', 'is_staff')
admin.site.register(User, UserAdmin)
- [Django]-Serialize datetime to JSON
- [Django]-Django-rest-framework 3.0 create or update in nested serializer
- [Django]-Django, ImportError: cannot import name Celery, possible circular import?
0π
Might want to try this:
https://libraries.io/pypi/django-modeladmin-reorder
Custom ordering for the apps and models in the admin app. You can also rename, cross link or exclude models from the app list.
- [Django]-Django migrations using RunPython to commit changes
- [Django]-How do I run another script in Python without waiting for it to finish?
- [Django]-How to pass Django request object in user_passes_test decorator callable function
0π
How can I get the new User model to show up under "Authentication and
Authorization"
I had the same concern using Django 3.0, this is how I solved it :
class CustomUser(AbstractUser):
class Meta:
db_table = 'auth_user'
app_label = 'auth'
In settings :
AUTH_USER_MODEL = "auth.CustomUser"
- [Django]-Django β iterate number in for loop of a template
- [Django]-How to make Django serve static files with Gunicorn?
- [Django]-Django cannot import login from django.contrib.auth.views
0π
try this:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy as _
class AdminExtra(UserAdmin):
add_form_template = "admin/auth/user/add_form.html"
change_user_password_template = None
fieldsets = (
(None, {"fields": ("username", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name", "email", "nick_name")}),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
),
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": ("username", "password1", "password2"),
},
),
)
admin.site.register(User, AdminExtra)
- [Django]-Variable subtraction in django templates
- [Django]-You are trying to add a non-nullable field 'id' to contact_info without a default
- [Django]-How to change django admin "view site" link to custom absolute url