django-form-designer icon indicating copy to clipboard operation
django-form-designer copied to clipboard

Circular import with get_user_model

Open b-jam opened this issue 10 years ago • 2 comments

Its fine to import, but if you import a model from this app from within your own models.py file, it will cause a circular error due to the get_user_model() running from within the code. see http://stackoverflow.com/questions/17469682/django-1-5-accessing-custom-user-model-fields-in-models-py for a very relevant case and how they solved.

b-jam avatar Nov 06 '14 23:11 b-jam

The Django documentation has the answer: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.get_user_model

The most relevant section: Generally speaking, you should reference the User model with the AUTH_USER_MODEL setting in code that is executed at import time. get_user_model() only works once Django has imported all models.

b-jam avatar Nov 06 '14 23:11 b-jam

The problem is models.py::formlog::created_by field. This field is not inside any method. So if you import this from your own models it will crash. a fix would be to put this inside a method or change it to use the AUTH_USER_MODEL setting.

b-jam avatar Nov 11 '14 20:11 b-jam