Question

I have the 2 following models, and I'd like to link them with a ManyToMany relationship :

  • www/hruser/models.py

    from django.db import models
    
    class HRuser(models.Model):
        """Custom user class."""
        email = models.EmailField(max_length=60, unique=True, db_index=True)
        is_active = models.BooleanField(default=True)
        is_staff = models.BooleanField(default=False)
        video = models.ManyToManyField('www.pandastream.models.Video', related_name='users')
    
  • www/pandastream/models.py

    from django.db import models
    
    from www.hruser.models import HRuser
    
    
    class Video(models.Model):
        """Video object, really basic for now."""
        video_id = models.CharField(max_length=32, unique=True, db_index=True)
        user = models.ForeignKey(HRuser, related_name='videos')
    

As you can see, they are in a different app, and Video also has a ForeignKey to HRuser. To avoid a circular import in www/hruser/models.py I try to use a lazy relationship, as defined here in the docs, but it raises an error on syncdb :

Error: One or more models did not validate:
hruser.hruser: 'video' has an m2m relation with model www.pandastream.models.Video, which has either not been installed or is abstract.

So far, I have tried :

  • to import my Video model in a python shell, which works
  • to switch from mysql(5.6.10) to sqlite(3.7.12)
  • to switch from Django 1.5 to Django 1.4
  • to change the HRuser.video field to a simple ForeignKey field
  • to look at the source of django.core.management.validation

All of which didn't change anything to my problem, so either I do not understand the documentation correctly or the documentation is wrong, but either way, any help would be appreciated.

Was it helpful?

Solution

The way to reference the target as a string, as explained in that docs link, is as "appname.Model". So it should just be "pandastream.Video".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top