Django Models : same object types, different field types
<p>Edit : These different types were just because of the django method:<br/></p>

<pre><code>request.POST.get("attribute")
</code></pre>

<p>which from Json data, returns me unicode.
The solution was to parse these values at the beginning
<br/></p>

<hr>

<p><br/>
I have got a big problem, and i don't understand where it comes from. <br/>
On my Score model to save scores for a game, I need to compare values from the current score and the old one before saving. My error is that the types of my field are different whereas my object types are identical.</p>

<p>Maybe some code could explain : <br/><br/></p>

<pre><code>class Score(models.Model):
    map = models.ForeignKey(Map, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    score = models.FloatField()

    class Meta:
        unique_together = ('map', 'user')

    def save(self, *args, **kwargs):
        try:
            oldScore = Score.objects.get(map=self.map, user=self.user)
        except ObjectDoesNotExist:
            oldScore = None

        if oldScore is not None:
            if oldScore.score &lt; self.score:
                print &gt;&gt; sys.stderr, type(oldScore), type(self)
                print &gt;&gt; sys.stderr, type(oldScore.score),     type(self.score)
                oldScore.delete()
            else:
                return False
        super(Score, self).save(*args, **kwargs)
        return True

    def __unicode__(self):
        return str(self.map) + ' - ' + self.user.username + " : " + str(self.score)
</code></pre>

<p>and how i create the score and save it :</p>

<pre><code>score = Score(map=map, user=user, score=score)
saved = score.save()
</code></pre>

<p>The result of debug prints :</p>

<pre><code>&lt;class 'main.models.score.Score'&gt; &lt;class 'main.models.score.Score'&gt;
&lt;type 'float'&gt; &lt;type 'unicode'&gt;
</code></pre>

<p>I would like to compare my old with new score, but I can't because of these different types. <br/> I know i could do some type conversions, but I'd like to know why this is happening, maybe I have failed on something stupid :s</p>

<p>ps: I'm under python 2.7 and Django 1.9.2
Thanks for helping me :)</p>