Tuesday, April 23, 2013

Choices with many to many

Hi to all
thi is my first post on django group.
I'm new on django and I'm going crazy for a week on this question:
 
I have these models:
 
class Linea(models.Model):
    linea = models.CharField(unique=True, max_length=10, verbose_name = "Linea")
    class Meta:
          verbose_name_plural = "Linee"
    def __unicode__(self):
           return self.linea
 
class Board(models.Model):
    board = models.CharField(unique=True, max_length=15, verbose_name = "Board")
    life = models.IntegerField(max_length=4, verbose_name = "Ore di vita")
    class Meta:
         verbose_name_plural = "Boards"
    def __unicode__(self):
         return u'%s' % self.board
 
class Package(models.Model):
     package = models.CharField(unique=True, max_length=10, verbose_name = "Package")
     class Meta:
          verbose_name_plural = "Packages"
     def __unicode__(self):
          return self.package
 
class Prodotto(models.Model):
     linea = models.ForeignKey(Linea, verbose_name = "Linea")
     prodotto = models.CharField(unique=True, max_length=15, verbose_name = "Prodotto")
     package = models.ManyToManyField(Package, related_name="packages", verbose_name = "Package")
     board = models.ManyToManyField(Board, related_name="boards", verbose_name = "Board")
 
class Prove(models.Model):
     nomeprova = models.CharField(unique=True, max_length=20, verbose_name = "Nome prova")# *
     TIPOPROVA = (
                                           ('c1', c1',),(c2', c2.',),(c3.', c3.',),
                                 )
     tipodiprova = models.CharField(unique=True, max_length=10, choices = TIPOPROVA, default = 'c1', verbose_name = "Tipo di prova")
     linea = models.ForeignKey(Linea, verbose_name = "Linea")
     prodotto = models.ForeignKey(Prodotto, verbose_name = "Prodotto")
     package = models.CharField(max_length=20, verbose_name = "Package")# *
     board = models.CharField(max_length=20, verbose_name = "Board")# *
 
In admin form of  "Prove" for the the fields package and board  I need to choice from the list of boards and packages that belong prodotto, because prodotto (as you can see ) contain a list of pakage and boards (Many to many ).
For do that the only thing I do until now is to override rthe Prove.board and Prove.package fields to forms.ChoiceField but how can I take the list from the current product and put it in these fields?
 
Tanks in advance

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment