[Answered ]-Django 'OneToOneField' object has no attribute 'id'

2👍

You can not use the instance data in the top level code of your class.
At the point the code is run (import time) there is simply no instance yet.
If you want to initialize an instance with calculated data, overwrite the __init__ method of the class.

Leave a comment