[Answer]-How to write Foreign Key to an attribute of other model?

1👍

Just use the class name znode instead of znode.code. Django automatically adds an id column to every model which will be used as reference as mentioned in the documentation.

Behind the scenes, Django appends “_id” to the field name to create its database column name. In the above example, the database table for the Car model will have a manufacturer_id column.

Also you should use CamelCaseClassNames to meet pep8 coding style conventions.

Leave a comment