Django加入复合外键

时间:2019-11-14 20:59:13

标签: django django-models django-rest-framework

我有一个关注者

class Tblrfqvendor(models.Model):
    """RFQ Master for Vendors
    This typical represents the same RFQ sent to different people
    """
    ven_rfqid = models.ForeignKey(Tblrfqitem, db_column='RFQID', on_delete=models.DO_NOTHING, primary_key=True,related_name="venrfq")  # Field name made lowercase.
    lineitem = models.IntegerField(db_column='LineItem')  # Field name made lowercase.
    vendorid = models.CharField(db_column='VendorID', max_length=10)  # Field name made lowercase.


    class Meta:
        managed = False
        db_table = 'tblRFQVendor'
        constraints = [constraints.UniqueConstraint(fields=['ven_rfqid', 'lineitem', 'vendorid'], name='unique_vendor_rfq')]
        ordering = ['-lastrevdate']


class Tblrfqitem(models.Model):
    """A Line Item for a particular Master Vendor RFQ
    """
    item_rfqid = models.ForeignKey(Tblrfqmaster, db_column='RFQID', on_delete=models.DO_NOTHING,  primary_key=True,related_name='items')  # Field name made lowercase.
    lineitem = models.IntegerField(db_column='LineItem')
    itemid = models.CharField(db_column='ItemID', max_length=100, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'tblRFQItem'
        constraints = [constraints.UniqueConstraint(fields=['item_rfqid','lineitem'], name='unique_item')]

如何获取它,以便可以在lineitem和ven_rfid上进行序列化,而不仅是单个主键?

0 个答案:

没有答案