ManyToMany and "set" function

9 views
Skip to first unread message

Vanni Brutto

unread,
Nov 27, 2013, 2:22:31 AM11/27/13
to django...@googlegroups.com
Hi,

i have a model with a m2m:


class PiattoPersonalizzato(models.Model):
    descrizione = models.CharField(max_length=80)
    categoria = models.ForeignKey(Categoria)
    numero = models.IntegerField(default=1)

    ingredienti = models.ManyToManyField(Ingrediente,default=None,null=True,blank=True)
    prezzo = models.DecimalField(max_digits=15, decimal_places=2, default=0)
    def __unicode__(self):
        return self.descrizione
    class Meta:
        verbose_name_plural = "Piatti Personalizzati"

I need to use the difference function, so 

piattoPersonalizzato = [... get the object model ... ]
piatto = [... get the object model ... ]
[...]
                ingredientiPiattoComanda = piatto.ingredienti.all()
                ingredientiPiattoPersonalizzato = piattoPersonalizzato.ingredienti.all()
                intersezione = set(ingredientiPiattoComanda).difference(set(ingredientiPiattoPersonalizzato))
                if not intersezione:
   [...]


It is possible do it using django database function? Do it cost a lot of memory, i want to do it using database...

regards,
Vanni
Reply all
Reply to author
Forward
0 new messages