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

  • Home
  • SEARCH
  • 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 554657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:43:59+00:00 2026-05-13T11:43:59+00:00

I’ve previously asked questions for this project, regarding the Django Admin, Inlines, Generics, etc.

  • 0

I’ve previously asked questions for this project, regarding the Django Admin, Inlines, Generics, etc. Thanks again to the people who contributed answers to those. For background, those questions are here:

Django – Designing Model Relationships – Admin interface and Inline

Django Generic Relations with Django Admin

However, I think I should probably review my model again, to make sure it’s actually “correct”. So the focus here is on database design, I guess.

We have a Django app with several objects – Users (who have a User Profile), Hospitals, Departments, Institutions (i.e. Education Institutions) – all of whom have multiple addresses (or no addresses). It’s quite likely many of these will have multiple addresses.

It’s also possible that multiple object may have the same address, but this is rare, and I’m happy to have duplication for those instances where it occurs.

Currently, the model is:

class Address(models.Model):
    street_address = models.CharField(max_length=50)
    suburb = models.CharField(max_length=20)
    state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES_CHOICES)
    ...
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()
    ...
class Hospital(models.Model):
    name = models.CharField(max_length=20)
    address = generic.GenericRelation(Address)
    ...
class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    address = generic.GenericRelation(Address)
    ...

Firstly – am I doing it right, with the FK field on each object that has address(es)?

Secondly, is there a better alternative to using Generic Relations for this case, where different objects all have addresses? In the other post, somebody mentioned using abstract classes – I thought of that, but there seems to be quite a bit of duplication there, since the addresses model is basically identical for all.

Also, we’ll be heavily using the Django admin, so it has to work with that, preferrably also with address as inlines.(That’s where I was hitting an issue – because I was using generic relationships, the Django admin was expecting something in the content_type and object_id fields, and was erroring out when those were empty, instead of giving some kind of lookup).

Cheers,
Victor

  • 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-05-13T11:44:00+00:00Added an answer on May 13, 2026 at 11:44 am

    I think what you’ve done is more complicated than using some kind of subclassing (the base class can either be abstract or not).

    class Addressable(models.Model):
      ...   # common attributes to all addressable objects
    
    class Hospital(Addressable):
      name = models.CharField(max_length=20)
      ...
    
    class UserProfile(models.Model):
      user = models.ForeignKey(User, unique=True)
    
    class Address(models.Model):
      street_address = models.CharField(max_length=50)
      suburb = models.CharField(max_length=20)
      state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES_CHOICES)
      ...
      owner = models.ForeignKey(Addressable)
    

    You should consider making the base class (Addressable) abstract, if you don’t want a seperate table for it in your database.

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

Sidebar

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.