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.
我成功地取得了希望的结果,用pk=0制造了我的肥胖症,但我相信,如果有的话,那是最好的。
这样做的方法不像这样。
任何帮助都是巨大的。
增 编