1

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?

onurmatik
  • 5,105
  • 7
  • 42
  • 67

1 Answers1

1

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'

Xavier Barbosa
  • 3,919
  • 1
  • 20
  • 18
  • you are right, `db_table` is the parameter. but then, as this is a base model that others are inherited, i want all the inherited models to be named in that format. thus it should accept a class name parameter similar to the related_name field attribute, i.e. `db_table = content_block_%(class)s`, but it doesn't. – onurmatik Jan 25 '11 at 10:07
  • how can the model name of the inheriting model can be accessed from within the Meta class? can the db_table attribute be parametrized by that such as `db_table = content_block_%s % inheriting_model_name`? – onurmatik Jan 25 '11 at 11:25