1
class HmsMedicine(models.Model):
    id = models.IntegerField(primary_key=True)
    medicine_name = models.CharField(max_length=100)
    price = models.IntegerField(max_length=6)

class HmsBilling(models.Model):
    id = models.IntegerField(primary_key=True)
    regid = models.ForeignKey(HmsPatient, db_column='regid')
    medicine = models.ForeignKey(HmsMedicine, db_column='medicine')
    quantity = models.IntegerField()
    rate = models.IntegerField()

我想在price字段中有rate字段的值。

4

1 回答 1

0
class HmsBilling(models.Model):
    id = models.IntegerField(primary_key=True)
    regid = models.ForeignKey(HmsPatient, db_column='regid')
    medicine = models.ForeignKey(HmsMedicine, db_column='medicine')
    quantity = models.IntegerField()
    rate = models.ForeignKey(HmsMedicine, db_column='price')

hms = HmsBilling.objects.select_related().get(id=5)
hms.rate

这将为您提供 id = 5 的计费价格(请参阅此链接以获取有关选择相关的参考)

更好的:

class HmsBilling(models.Model):
    id = models.IntegerField(primary_key=True)
    medicine = models.ForeignKey(HmsMedicine)
    quantity = models.IntegerField()

hms = HmsBilling.objects.select_related().get(id=5)
hms.medicine.price
于 2012-10-23T13:03:48.237 回答