Django admin inline UserProfile field -
Each user (user should have) is a UserProfile object, and may have location (foreign key in place) in place of every UserProfile.
I want to show these places (and allow them to be edited / added / removed) in the user view in the admin location . Nested inline is not feasible, so I want to add a location inline on the user page, which is uncertain how to do it. Import models from django.db to users module UserProfile (models.Model): user = models.OneToOneField (user) to import module from
models.py
registration # ... class space (models.Model): owner = models.ForeignKey (UserProfile) # address and django.contrib.auth.models from django.contrib Import admin content
admin Import the user.php
import the user from main.models UserProfile, import Django.contrib.auth.admin from the UserAdmin AuthUserAdmin class as UserProfileInline (admin.StackedInline): model = UserProfile max_num = 1 can_delete = Invalid class placement Xine (admin.TabularInline): Modal = Location Extra = 1 Class UserAdmin (AuthUserAdmin): inlines = [UserProfileInline, LocationInline] # clearly does not work, because the location is from UserProfile, not user # How can I do this Use user.profile instead? Admin.site.unregister (user) admin.site.register (User, UserAdmin)
Comments
Post a Comment