如何在将实例保存到数据库之前返回实例?
下面是类似于我想要完成的事情:
class Personne(models.Model):
nom = models.CharField(max_length=100, verbose_name="Origem")
def save(self, *args, **kwargs):
found = None
try:
found = Personne.objects.get(nom=self.nom)
super(Personne, self).save(*args, **kwargs)
except AudioFile.DoesNotExist:
return found
def test_personne_is_the_same(self):
p1 = Personne.objects.create(nom="Malcom X")
p2 = Personne.objects.create(nom="Malcom X")
self.assertEqual(p1, p2)
断言给出:p1 != None