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 8839469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:14:39+00:00 2026-06-14T10:14:39+00:00

so I’m doing a small django project and I’m running into a few problems

  • 0

so I’m doing a small django project and I’m running into a few problems when trying to place certain models inline in the admin site. Eg:

models.py

class Client(models.Model):
    client_name = models.CharField(max_length=100,unique=True,blank=False)
    phone_number = models.ForeignKey(Phone)

class Phone(models.Model):
    info = models.Charfield("eg. Personal", max_length=20)
    number = models.CharField(max_length=20, blank=False)

now if I want to have my client admin with a phone_number stacked inline I can’t do that,… and instead I need to have my models like this:

class Client(models.Model):
    client_name = ...

class PhoneAbstract(models.Model):
    info = ...
    number = ...

    class Meta: 
        abstract = True

class ClientPhone(PhoneAbstract):
    client = models.ForeignKey(Client)

…and basically define a new class that inherits from PhoneAbstract every time I want to relate a phone with a model :(. This sucks but it’s the only way in which I can then do this and get the proper admin interface:

admin.py

class PhoneInline(admin.TabularInline):
    model = ClientPhone

class ClientAdmin(admin.ModelAdmin):
    inlines = (PhoneInline, )

Now, this is ugly as hell (to my still uneducated eyes) and it makes the relationships awkward… so, is there a way of having the foreign keys in my ClientAdmin in the first case? maybe this is what ModelAdmin.list_select_related is for, but I am not sure… 🙁

  • 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-14T10:14:40+00:00Added an answer on June 14, 2026 at 10:14 am

    I’ve no idea why you want to define things this way round. The way you want to have it, one phone number can belong to multiple clients, which seems unlikely. Having the ForeignKey field on the PhoneNumber model is the right thing to do, because that way the relationship makes sense (a client can have multiple phone numbers).

    But there’s no need to muck about with abstract models and subclassing. If you need the ability for a phone number to point to multiple different model classes, then generic relations are what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

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.