开发者

how to model the following in Django correctly

开发者 https://www.devze.com 2023-01-13 11:02 出处:网络
I have the following tables.The ComponentBuild table has two columns \'comp_pn\' and \'parent_pn\' that are both ForeignKeys.Django is complaining Unknown column \'product_parent_pn.product_id_id.What

I have the following tables. The ComponentBuild table has two columns 'comp_pn' and 'parent_pn' that are both ForeignKeys. Django is complaining Unknown column 'product_parent_pn.product_id_id. What's the correct way to model these relationship?

class Product(models.Model):
    name = models.CharField(max_length=80)

    def __unicode__(self):
  开发者_开发技巧      return self.name

class ProductParentPn(models.Model):
    part_no = models.CharField(max_length=80)
    product_id = models.ForeignKey(Product)
    def __unicode__(self):
        return self.part_no

class CompMap(models.Model):
    component = models.CharField(max_length=50)
    part_no = models.CharField(max_length=50)

    def __unicode__(self):
        return self.part_no 

class CompProductMap(models.Model):
    comp_id = models.IntegerField()
    prod_id = models.IntegerField()
    class Meta:
        db_table = u'comp_product_map'

class ComponentBuild(models.Model):
    comp_sn = models.CharField(max_length=35)
    parent_sn = models.CharField(max_length=15)
    comp_pn = models.ForeignKey(CompMap)
    parent_pn = models.ForeignKey(ProductParentPn)
    date = models.DateField(default=datetime.datetime.today())

    def __unicode__(self):
        return self.comp_sn
0

精彩评论

暂无评论...
验证码 换一张
取 消