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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:16:21+00:00 2026-06-02T16:16:21+00:00

Reading, the Django docs on many-to-many relationships when you need an extra field on

  • 0

Reading, the Django docs on many-to-many relationships when you need an extra field on the intermediary table, it’s not clear to me what you gain by defining the relationship as many-to-many vs just having a foreign key to the intermediary model in each of your models.

For instance, in the example here: https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

Why bother with the ManyToManyField line? Does it allow you to refer to the relationship any differently? Does it change something in the admin?

  • 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-02T16:16:22+00:00Added an answer on June 2, 2026 at 4:16 pm

    Why bother with the ManyToManyField line: M2M fields are django fields which are useful for many model field interfaces like ModelAdmin or ModelForm (declaring fields, excluding, default widgets). It also generate helper methods like easy to access m2m managers and auto m2m saving in the admin.

    Here’s a quick example for what the field does automatically for the admin panel: you can’t save a through model without the main object saved first. The admin handles this behavior with a save_m2m after the main object is saved automatically. If you did not use an m2m field, you’d have to code this kind of logic yourself.

    I think you’d use this field when your project works with m2m fields but you just need a small amount of additional information. That way your code is virtually the same as a typical m2m relationship but when you need it, you can query the extra info.

    Otherwise, adding a mere “date_added” field would require writing admin widgets, save_model hooks, ModelForm representation, etc.

    You’re right though that removing the m2m line with a through model won’t make any database changes and you could ultimately replace the m2mfield functionality with the default ForeignKey reverse managers without much harm.

    model.m2m_through_set.all() # this would work
    model.m2m_through_set.create(target=target_instance)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
I've been reading on the django docs about the comments framework and how to
I've been reading the docs for django-notification , and they seem to cover creating
Django will email ADMINS upon 500 errors. Reading app-engine-patch docs, it claims to enable
I am very new to django and celery. I was reading their docs but
When reading source code of Django, I find some statements: class Field(object): Base class
surfing on the web, reading about django dev best practices points to use pickled
I have been reading a lot of django articles, including the official doc. Occasionally,
I remember reading somewhere on the internets about a half-assed tiny django CMS app,
Duplicate: Django or Ruby-On-Rails? I have been reading on Ruby on Rails, and it

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.