Friday, March 28, 2014

ManytoManyField (through) not showing up !

I am trying to do a ManytoManyField through a middle Table. After I run syncdb, I do not see the column in pdadmin.
What am I doing wrong?

Here is my code

class Countries(models.Model):

    country_name = models.CharField(max_length=200)
    country_id = models.CharField(primary_key=True, max_length=2)
    region = models.CharField(max_length=200)

    #Economic profile
    gdp = models.DecimalField(max_digits=17, decimal_places=2, default=0.00)
    gdp_growth = models.DecimalField(max_digits=5, decimal_places=2, default=0.00)

class Products(models.Model):

    product_id = models.AutoField(primary_key=True)
    hs_number = models.ManyToManyField(Countries, through='Imports')
    product_descript = models.CharField(max_length=250)

    class Meta:
        db_table = "Products"

    def __unicode__(self):
        return self.hs_number

class Imports(models.Model):
    hs_number = models.ForeignKey(Products)
    country_id = models.ForeignKey(Countries)
    imported_value2008 = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment