Django admin - stackedInline single instance

django, django-admin

Solution

I assume you're using FK field to connect user and profile? Try OneToOneField it should render just one inline in admin.

Problem

I'm building a site based on a highly customized django admin instance and am running into issues with user profiles as an inline to user_admin long story short regardless of what I set for max_num and extra in the admin.StackedInline instance it allows up to 2 profiles per user - with a blank one in place by default if the user has an existing profile anyone know how I could adjust this to show only a single inline profile without resorting to some JS front end hack? relevant 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) ```

Original source