Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

stackoverflow Django ForeignKey

class Versao(models.Model):
    projeto=models.ForeignKey(Projeto, on_delete=models.CASCADE)
    local=models.FileField()
    num_versao=models.IntegerField(blank=True)

    def __str__(self):
        return str(self.projeto) + '_V' + str(self.num_versao)

    def save(self, force_update=False, force_insert=False):
        qtd_versoes=Versao.objects.filter(projeto=self.projeto).count()
        self.num_versao=qtd_versoes+1
        super(Versao, self).save(force_insert, force_update)
Source by pt.stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #stackoverflow #Django #ForeignKey
ADD COMMENT
Topic
Name
9+9 =