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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:12:19+00:00 2026-05-26T14:12:19+00:00

I have a system with several steps. Each step increments one single object instance.

  • 0

I have a system with several steps. Each step increments one single object instance.
I want to save the instance in db only in the final step, on others just update the instance I saved in the session.

My model class seems like this:

class Proposta(models.Model):
    Modelo = models.ForeignKey("ModeloVersao", verbose_name="Modelo")
    Pacotes = models.ManyToManyField("PacoteModelo", null=True, blank=True)
    Opcionais = models.ManyToManyField("ItemModelo", null=True, blank=True)
    RevestimentoInterno = models.ForeignKey("RevestimentoInternoModelo", verbose_name="Revestimento Interno")
    Cor = models.ForeignKey("CorModelo")
    CorSecundaria = models.ForeignKey("CorModeloSecundaria", verbose_name="Cor secundária", null=True, blank=True)
    Data = models.DateTimeField(auto_now_add = True)
    Status = models.CharField("Status", choices=STATUS_PROPOSTA, max_length=10)
    Cliente = models.ForeignKey("Cliente")

Here’s my problem:
When I try to add or retrieve m2m fields it obviously throws a ValueError with the message ‘Proposta’ instance needs to have a primary key value before a many-to-many relationship can be used.

I successfully got the wanted result by creating my obj instance with pk=0 but I’m sure it isn’t the best way, if there is.

Do exist a way of doing that without cheating like this.

Any help would be great.

Thanks

  • 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-26T14:12:19+00:00Added an answer on May 26, 2026 at 2:12 pm

    You might find the answers to this question helpful.

    Summary for quick reference:

    • Use ModelForms – Based on the ModelForms documentation
    • Save it to DB, but use a status field – I think this is less than ideal

    I might add that the documentation specifically explains how to deal with M2M fields, in the section that explains The save() method.

    Of those, I recommend using ModelForms. Hopefully this helps!

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

Sidebar

Related Questions

Let's say we have system A comprising a MySQL database, with several tables. After
I'm working on a social networking system that will have comments coming from several
Looking for suggestions on file system management tools. We have several terabytes of images,
I have several embedded linux systems that I want to write a 'Who's Online?'
I have System.Collections.Generic.Dictionary<A, B> dict where A and B are classes, and an instance
I have document scanning system where several types of documents are scanned. Initially, the
Our SQL Server 2000 instance hosts several databases which are all similar, one for
I have the following issue: I want to display Tickets from a helpdesk system
I have implemented authentication systems for webapps several times over the years, but before
We have system here that uses Java JNI to call a function in 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.