New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of `get_user_model' at module level in manager causes circular import #19
Comments
My CustomUser model had a manytomany relationship with a Video model. The video model then had a flag field which would in turn call get_user_model() and lead to either circular import errors or the error listed above depending on the order of the Installed_apps list. Solution: In CustomUser instead of importing the video model and initiating the field like: favorite_videos = models.ManyToManyField(Video, blank=True, related_name='favorite_videos') Don't import the video model and initialize like: favorite_videos = models.ManyToManyField('api.Video', blank=True, related_name='favorite_videos') |
I have tried experimenting inside the In short, it now has Just to be safe, have you added the location of your user model to |
Yes, I set settings.AUTH_USER_MODEL to my custom user model. My user model included these relevant fields: favorite_artists = models.ManyToManyField(Artist, blank=True, related_name='favorite_artists') The video model contains the flag field as well as a separate manytomany field pointing back to the user model via settings.AUTH_USER_MODEL and a foreign key relationship with the artist model. I tested initializing with get_user_model() on a separate model and ran into the same issue so I don't think the problem is unique to this project. |
Can you just upload a minimum reproducible example in the form of a repository somewhere and share that link here? It will help me in seeing all the code, rather than shooting in the dark. As of now, I can't seem to reproduce the issue on my end. |
https://github.com/TSolo315/testflag Ran into the issue making migrations for customUser after adding the many to many fields. |
Thanks, I will try to look into this when I have some more time today. |
Okay, so I could fix this by make these changes:
Please try to verify if it works at your end too. Thanks for the report. If you can make these changes in #18, I will be happy to merge. |
Also, as a piece of advice, you may probably add a third field non-binary to your gender choices |
get_user_model
in manager causes circular import
Originally posted by @TSolo315 in #18 (comment)
The text was updated successfully, but these errors were encountered: