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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:31:13+00:00 2026-05-27T05:31:13+00:00

this is the representation of my models: class B(models.Model): I’m a dummy model, so

  • 0

this is the representation of my models:

class B(models.Model):
   """I'm a dummy model, so doesn't pay atention of what I do"""
   name = models.CharField(max_length=250)

class A(models.Model):
   name = models.CharField(max_length=250)
   many_b = models.ManyToManyField(B)

Now, suppose I have a list of B objects. And a single A object that will be related to that Bs. Something like this:

a = A.objects.get(id=1)
list_of_b = [B<name='B1'>,B<name='B2'>,B<name='B3'>,]

The way I relate them now is this:

for b_object in list_of_b:
   a.many_b.add(b_object)

Is there any way to add all the B objects in a single transaction? Maybe in a single method, like:

a.many_b.addList(b) #This doesn't exist
  • 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-27T05:31:14+00:00Added an answer on May 27, 2026 at 5:31 am

    From the docs:

    >>> john = Author.objects.create(name="John")
    >>> paul = Author.objects.create(name="Paul")
    >>> george = Author.objects.create(name="George")
    >>> ringo = Author.objects.create(name="Ringo")
    >>> entry.authors.add(john, paul, george, ringo)
    

    So if you have a list, use argument expansion:

    a.many_b.add(*list_of_b)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My model is a simple parent/child representation looking like this public class Parent {
I have a model looking like this. class ProjectMembership(models.Model): member = models.ForeignKey(User, related_name='project_membership_member_set') Edit:
How i can map structure like this db model http://imagepost.ru/images/186/oefb4v6.png into class A{ Map<SomeEnum,
I have a model which has 2 fields, a and b like this: class
I need to grab the base64-encoded representation of the ViewState . Obviously, this would
Let's say that I have a string 5a . This is the hex representation
I have a Customer class which has a representative field....this field is initially blank
I have a tree of nodes like this: class Node: next # the next
I've created an XML schema by annotating an existing Java domain model class, now
I am working with models of neurons. One class I am designing is a

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.