I recently extended with UserProfile so my admin.py looks like this:
from django.contrib import admin
from django.contrib.auth.models import User
from models import UserProfile
from django.contrib.auth.admin import UserAdmin
admin.site.unregister(User)
class UserProfileInline(admin.StackedInline):
model = UserProfile
class UserProfileAdmin(UserAdmin):
# fieldsets = [
# (None, {'fields': ['image']}),
# ('Avatar', {'fields': ['text'], 'classes': ['collapse']}),
# ]
inlines = (UserProfileInline,)
admin.site.register(User, UserProfileAdmin)
and models.py like this:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
# Required
user = models.ForeignKey(User, unique=True)
image = models.ImageField(upload_to='media/users/', blank=True, help_text="Your face")
text = models.TextField(blank=True, help_text="Write something about yourself")
In an app called users that is referred to by settings.py with:
AUTH_PROFILE_MODULE = users.UserProfile
1
Basically what I want to achieve is to get rid of the #1 StackedInLine that shows in the admin. The reason I use StackedInLine instead of TabularInLine is because otherwise I get a "Delete?" column to the right and I find it optional so I would like to either exclude that or get rid of the #1 numbering in StackedInLine.
2
Also. I wonder why I cannot use fieldsets when I have loaded the UserProfile models.py file in admin.py. It simply says the field doesn't exist. Do I have to call the fields differently than in django/ contrib/auth/admin.py where I've seen it work?
If you feel like there is a more efficient way of doing this just tell me.