tags:

views:

59

answers:

1

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

+1  A: 
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()
Almad