Django admin - stackedInline single instance

I am creating a site based on a specially configured admin django instance, and I am encountering problems with user profiles as built-in in user_admin

a long story, no matter what I set for max_num and optional in the admin.StackedInline instance, it allows up to 2 profiles per user - with a default empty if the user has an existing profile

Does anyone know how I can configure this to show only one inline profile without resorting to some kind of hacking front end JS?

corresponding code from: profiles.admin.py

from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from profile.models import user_profile class user_profile_admin(admin.StackedInline): model = user_profile fk_name = 'user' max_num = 1 extra = 0 class user_admin_extended(UserAdmin): inlines = [user_profile_admin, ] admin.site.unregister(User) admin.site.register(User, user_admin_extended) 
+7
django django-admin
source share
1 answer

I assume that you are using the FK field to connect the user and profile? Try OneToOneField, it should display only one built-in administrator.

+5
source share

All Articles