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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:54:34+00:00 2026-06-15T23:54:34+00:00

I am confused as far as Database design goes for a Django application with

  • 0

I am confused as far as Database design goes for a Django application with specific relationships. I have been looking at the following database schema : http://www.databaseanswers.org/data%5Fmodels/customers_and_orders/index.htm

I am confused about the relationships between Customer_addresses and Customers, and Addresses.

I know that:

  • one customer can have Many addresses.
  • many customers can have the same (one) address

Does this equate to a many to many relationship?

  • Many customers can have many addresses?

When I’m building the model in django I have (simplified):

class Customer_Address(models.Model):
    customer = models.ManyToManyField('inventory.Customer')
    address = models.ManyToManyField('inventory.Address')

Is this right? or does this make more sense:

class Customer_Address(models.Model):
    customer = models.ForeignKeyField('inventory.Customer')
    address = models.ManyToManyField('inventory.Address')

UPDATED QUESTION:

Based on the idea that it is a many to many relationship.
Does one ManyToMany relation, require two ManyToManyFields?

Based on the following:
http://en.wikipedia.org/wiki/Many-to-many_%28data_model%29

Since Django supports ManyToManyFields, do I not even require the junction table?
And if I do use the junction table (Customer_addresses) the article seems to imply using Two OneToMany relationships, which wouldn’t that just be two foreign keys like this?

class Customer_Address(models.Model):
    customer = models.ForeignKeyField('inventory.Customer')
    address = models.ForgeinKeyField('inventory.Address')

UPDATED QUESTION:

Now that we know that Django builds the intermediate table, and the table Customer_Addresses is not required. Which table should have the ManyToManyfield? the customer tables? or the Address table?

Example: https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

In the Person/Groups examples.. The Groups has the ManyToManyField. Is there any reason the ManyToManyfield couldn’t be defined in the Person table?

  • 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-15T23:54:35+00:00Added an answer on June 15, 2026 at 11:54 pm

    To Sum up

    For the first question.

    When a relationship states that

    • one customer can have Many addresses.

    • many customers can have the same (one) address

    Than its clearly a Many-to-Many relationship and always use ManyToManyField

    Now for the second question.

    What if you want to have a intermediate table which has extra fields between two many to many entities(Tables/models)

    Than create a new Model which has a ForiegnKey from the other two models. As in

    class Person(models.Model):
        name = models.CharField(max_length=128)
    
        def __unicode__(self):
            return self.name
    
    class Group(models.Model):
        name = models.CharField(max_length=128)
        members = models.ManyToManyField(Person, through='Membership')
    
        def __unicode__(self):
            return self.name
    
    class Membership(models.Model):
        person = models.ForeignKey(Person)
        group = models.ForeignKey(Group)
        date_joined = models.DateField()
        invite_reason = models.CharField(max_length=64)
    

    For more Read

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

Sidebar

Related Questions

I understand how to design a database schema that has simple one-to-many relationships between
In SQL Server we have: Instance->Database->Schema->Objects (tables etc) I'm confused what the MySQL equivalents
I have been so confused lately regarding difference between predicate and function in first
I'm using NHibernate + Fluent to handle the database in my application. So far
All the answers I've seen to this so far have confused me. I've made
I've been looking into creating a new application for iOS and after my last
Confused here... I have two dates which I NSLog to console and get: dates
Mildly confused. I have a combobox that is databound to a list of strings.
Bit confused here, I have an on-demand instance but do I get charged even
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray

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.