I have these models:
class UserProfile(models.Model):
user = models.OneToOneField(User)
#etc
class Organization(models.Model):
users = models.ManyToManyField(User, through=OrganizationUser, verbose_name=_('users'))
#etc
class OrganizationUser(models.Model):
organization = models.ForeignKey('Organization')
user = models.ForeignKey(User)
I want to show the organizations for an user with inline:
class UserOrganizationsInline(admin.TabularInline):
model = OrganizationUser
class UserProfileAdmin(admin.ModelAdmin):
inlines = [UserOrganizationsInline]
admin.site.register(UserProfile, UserProfileAdmin)
The error message is:
<class 'customer.models.organization.OrganizationUser'> has no ForeignKey to <class 'customer.models.userprofile.UserProfile'>
I know why: Organization has ForeignKey to auth.User instead of modes.UserProfile.
How can i make this work without changing the models.
Rough idea (untested): set the
ForeignKeytoUserProfilemodel but reflect theuser_idfield instead of primary key. So you’ll have relation toUserProfilewith the same values in the database as now (User.id):