Sunday, September 23, 2018

Re: Django - using intermediate user group model

Is that User [N] -- [N] Group with many to many through Enrollment (something like that: User [1] -- [N] Enrollment [N] -- [1] Group)? Then, the answer in this gist here.


W dniu piątek, 21 września 2018 20:16:05 UTC+2 użytkownik Fernando Balmaceda napisał:
Hi everyone!

I am trying to add a foreign key in a model to the table intermediary between User and Group. Something like this:

from django.db import models
from django.contrib.auth.models import User


class Enrollment(models.Model):
   
    user_groups
= models.ForeignKey(User.groups.through, on_delete=models.CASCADE)

But when i try this, django throws an error:

core.Enrollment.user_groups: (fields.E300) Field defines a relation with model 'User_groups', which is either not installed, or is abstract.

How can I achieve this?. 
Using Django 2.0

Thanks!

--
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+unsubscribe@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/276ed34b-082f-4580-8852-ebee77be1889%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment