Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7709217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:48:31+00:00 2026-06-01T00:48:31+00:00

I have these models: class UserProfile(models.Model): user = models.OneToOneField(User) #etc class Organization(models.Model): users =

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:48:33+00:00Added an answer on June 1, 2026 at 12:48 am

    Rough idea (untested): set the ForeignKey to UserProfile model but reflect the user_id field instead of primary key. So you’ll have relation to UserProfile with the same values in the database as now (User.id):

    class OrganizationUser(models.Model):
        user = models.ForeignKey(UserProfile, to_field='user_id') 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models: class UserProfile(models.Model): user = models.OneToOneField(User) score = models.PositiveIntegerField() class
I have the following models: class Post(models.Model): message = models.TextField() (etc.) class UserProfile(models.Model): user
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
I have these models class User(models.Model): user_name = models.CharField() ph_number = models.CharField() class ExamPaper(models.Model):
I have these models: class Model1(models.Model): ... class Model2(models.Model): m1 = models.OneToOneField(Model1, related_name='m2') ...
I have these models: class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100)
I have this models: class Comment(models.Model): text = models.TextField(max_length = 300) author = models.ForeignKey(User)
I have these two models : class Module(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(unique=True,
I have these 3 models in models.py class Customer(models.Model): name = models.CharField(max_length=50) .... class
I have these models: class A(Model): pass class B(Model): the_a = ForeignKey(A) class C(Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.