Greetings, 

I'm trying to create a M2M relation between an abstract base class and a 
model that extends the same base. 

I have the following code: 

#Base object: 
class BaseObject(models.Model): 
    datetime = models.DateTimeField(auto_now_add=True) 
    shared = models.ManyToManyField('userprofile.UserProfile', 
                                through='models_bases.SharedObject', 
                                symmetrical=False, 
                                
related_name="%(app_label)s_%(class)s_related") 

    class Meta: 
        abstract = True 

<snip> 

and the through table: 

#Through table: 
class SharedObject(models.Model): 
    from userprofile.models import UserProfile 

    class Meta: 
        db_table = 'shared_object' 
    userprofile = models.ForeignKey(UserProfile) 
    content_type = models.ForeignKey(ContentType) 
    object_pk = models.PositiveIntegerField() 
    shared_object = GenericForeignKey( 
                                ct_field="content_type", 
                                fk_field="object_pk") 
    datetime = models.DateTimeField(auto_now_add=True) 


when I go to do ./manage.py makemigrations I get the following errors: 

SystemCheckError: System check identified some issues: 

ERRORS: 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'author.Author.shared', but it does not have a 
foreign key to 'Author' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'award.Award.shared', but it does not have a foreign 
key to 'Award' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'book.Book.shared', but it does not have a foreign 
key to 'Book' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'publisher.Publisher.shared', but it does not have a 
foreign key to 'Publisher' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'rlcomments.RLComment.shared', but it does not have a 
foreign key to 'RLComment' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'statusposts.StatusPost.shared', but it does not have 
a foreign key to 'StatusPost' or 'UserProfile'. 


The models are all extensions of BaseObject (including UserProfile). 

I have found this ticket: https://code.djangoproject.com/ticket/11760#no1  
which I believe to be related. 

My question is how do i achieve a M2M with an abstract base that uses a 
through table? 


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db47604e-c8cd-46fb-9f44-e09f8372a8d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to