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
- 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()
精彩评论