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, 
> on_delete=models.SET(get_default_institute))
>     username = ...
>     ....
>
> This is the model in another app for the institutes
>
> class Institute(models.Model):
>     master_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name
> ='master_user')
>     name = models.CharField(max_length=255)
>
>     def members(self):
>         UserModel = apps.get_model('play', 'User')  # need to avoid 
> circular import
>         return UserModel.objects.filter(institute=self)
>
>

-- 
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/6243e47f-f526-4d08-88ac-07034583201c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to