On Friday 05 May 2017 05:41:52 Tobias Dacoir wrote:
> I am trying to build a model (in two separate apps) which has the
> following constraints:
> 
> - There can be many institutes
> - there can many users
> - each user is a member of exactly one institute
> - each institute has exactly one master user
> 
> However I am running into CircularDependency errors when trying to
> create this model and database. Of course this model is a bit
> problematic because you can't have an institute without master user,
> but also you can't create a user without some default institute. How
> do I fix this? Should I be more lean on the model side and allow for
> a lot of blanks and null values and make all the exception handling
> somewhere else?
> 
> Please tell me how to improve my model.
> 
> >> class User(AbstractBaseUser, PermissionsMixin):
> >     # account-related information
> >     institute = models.ForeignKey(Institute, blank=True, null=True,

institute = models.ForeignKey('mycoolapp.Institute', ....)

This uses a promise and resolves the model at init stage (rather then class 
declaration). Make 
sure you remove the import of Institute or it won't help.

If you're interested in the topic of resolving models at runtime, take a loot 
at django.apps.Apps, 
specifically get_model. But all the work for foreign keys is already done for 
you.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2130428.5o0dMYScpf%40devstation.
For more options, visit https://groups.google.com/d/optout.

Reply via email to