Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango form getting value from previous instance?
    text
    copied!<p>any ideas why this is happening?</p> <pre><code>(Pdb) import copy (Pdb) tmpForm=copy.copy(form1) (Pdb) form1 &lt;cms.forms.MainFeaturedForm object at 0x7f05a0493350&gt; (Pdb) tmpForm &lt;cms.forms.MainFeaturedForm object at 0x7f05a054e950&gt; </code></pre> <p>copying form1 to tmpForm (and making sure they're on different memory addresses) to make sure this behaviour is not happening because form1 is being changed</p> <pre><code>(Pdb) v1=form1.save(commit=False) (Pdb) v1.position </code></pre> <p>as can be seen above, v1.position == None right after a form1.save(commit=False)</p> <pre><code>(Pdb) v1.image_type=2 (Pdb) v1.Article=article (Pdb) v1.section=33 (Pdb) v1.save() (Pdb) v1.position 55L </code></pre> <p>here I set some values and saved it the save() function changes v1 position to 55 (that's expected)</p> <pre><code>(Pdb) v2=tmpForm.save(commit=False) (Pdb) v2.position 55L </code></pre> <p>but now, after I saved v1, v2 (a completly new instance) has a position setted to the same one that was set on v1 (not expected)</p> <hr> <p>in case it helps, here's the save() function of this object (class Featured):</p> <pre><code>def save(self): if self.Article: try: featured = Featured.objects.get(Article=self.Article, section=self.section) self.hiddenID = featured.hiddenID if self.position == None: if featured.position == None: self.position = 55 else: self.position = featured.position super(Featured, self).save(force_insert=False, force_update=True) except Featured.DoesNotExist: self.hiddenID = None super(Featured, self).save(force_insert=True, force_update=False) else: self.hiddenID = None super(Featured, self).save(force_insert=True, force_update=False) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload