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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:56:48+00:00 2026-05-16T01:56:48+00:00

I was working on a many-to-many model with extra fields and i saw the

  • 0

I was working on a many-to-many model with extra fields and i saw the documentation
for extra fields in many to many relations

on their exemple, to create a membership they use

m2 = Membership.objects.create(person=paul, group=beatles,date_joined=date(1960, 8, 1), invite_reason= "Wanted to form a band.")

but that means that they already have the “person” and “group” instances. Normally working in websites we have the id’s of the objects… so to create a membership i’d have to do:

person = Person.objects.get(pk=idPerson)
group = Group.objects.get(pk=idgroup)

Now, correct me if i’m wrong but aren’t we consulting pointlessly the database two times before the insert? because, all we need in the Membership is the foreign key id’s and not the whole object…
maybe there’s another way to insert in a many-to-many relation using only the id’s

  • 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-16T01:56:48+00:00Added an answer on May 16, 2026 at 1:56 am

    You can use

    Membership.objects.create(person_id=person_id, group_id=group_id)
    

    where person_id and group_id are the ids of the objects you want to link.

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

Sidebar

Related Questions

I'm pretty new to NHibernate. I have working many to many mappings. they look
I've been working for many hours trying to do a simple thing: use a
I am implementing many SSB working on two different instances. They are data push
I am a lone programmer working on many .Net projects. I work alone and
I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how
After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
I am working a project with many NUnit tests, that were already written long
I'm working on a project that has many iframes that are opened and closed
I am working with a standard library with many files. I would like to
I'm working on a large project (for me) which will have many classes and

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.