开发者

How to save to Django Model that Have Mulitple Foreign Keys Fields

I have this Model

class inventory_transaction(models.Model):    
    stockin = models.DecimalField(blank=True, null=True,max_digits=8, decimal_places=2)
    stockout = models.DecimalField(blank=True,null=True,max_digits=8, decimal_places=2)
    from_container = models.ForeignKey(container_identity)
    staffs = models.ForeignKey(staff_name)
    goods_details = models.ForeignKey(departments)
    balance = models.DecimalField(max_digits=8,开发者_如何转开发 decimal_places=2)
    date = models.DateTimeField(auto_now=True)

    class meta:
        ordering = ["date"]
        get_latest_by = "date"

My Question is

  1. How do i save do i save data into it with its multiple foreign keys fields taken care of

Thanks


transaction = inventory_transaction() # read PEP 8 and rename to InventoryTransaction
transaction.staffs = staff_name.objects.create(params)
transaction.goods_details = departmens.objects.create(params)

# other attrs

transaction.save()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜