Optimize saving FK and M2M relationships in django

See also http://stackoverflow.com/questions/2846029/django-set-foreign-key-using-integer
    employee = Employee(first_name="Name", last_name="Name") 
  employee.type_id = 4 
  employee.save(update_fields = ["type",])

ForeignKey and M2M fields store their value in an attribute with _id at the end, which you can access directly to avoid visiting the database.

Comments

Popular posts from this blog

Handling control characters (escaping) in python for json and mysql

python port sniffer with pcapy and impacket

Django field, form and model validation process