Question

I have an abstract Container class which allows derived models to hold some content blocks such as images, text, etc., which are also separate models. For db tidiness, I want tables for those models to be labeled as content_block_image, content_block_text, etc.

But when I specify app_label = 'content_block' in Meta class of Content model, I am getting an error during syncdb:

content.event: 'content' has an m2m relation with model Content, which has either not been installed or is abstract.

I am declaring the following base classes as follows:

# base.py
class Content(models.Model):
    tags = models.TextField(_('tags'), blank=True)
    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType, 
                                     related_name='%(class)s_content_set')

    container_type = models.ForeignKey(ContentType)
    container_id = models.PositiveIntegerField()
    container = generic.GenericForeignKey('container_type', 'container_id')

    class Meta:
        app_label = 'content_block'

class Container(models.Model):
    content_type = models.ForeignKey(ContentType, 
                                     related_name='%(class)s_container_set')
    content = generic.GenericRelation('Content', 
                                      content_type_field='container_type', 
                                      object_id_field='container_id')
    class Meta:
        abstract = True

Then, in my models I am declaring models I call container such as:

# models.py
class Event(Container):
    title = models.CharField(max_length=100)
    start = models.DateTimeField()
    end = models.DateTimeField()

If I remove the app_label syncdb runs without a problem. It seems that app_label is not just a label.

Any ideas on how to get this going with the app_label for the Content base class set?

Was it helpful?

Solution

From the doc

If a model exists outside of the standard models.py (for instance, if the app’s models are in submodules of myapp.models), the model must define which app it is part of:

app_label = 'myapp'

content_block application exists ? if not, i'm not shure it will work.

It seems that what you want to do is forcing the table names. It's possible will this property

The name of the database table to use for the model:

db_table = 'music_album'

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