views:

114

answers:

1

Hi all,

I'm trying to get an abstract model working in Django and I hit a brick wall trying to set the related_name per the recommendation here: http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name

This is what my abstract model looks like:

class CommonModel(models.Model):

    created_on = models.DateTimeField(editable=False)
    creared_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_created", editable=False)
    updated_on = models.DateTimeField(editable=False)
    updated_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_updated", editable=False)

    def save(self):
        if not self.id:
            self.created_on = datetime.now()
            self.created_by = user.id

        self.updated_on = datetime.now()
        self.updated_by = user.id
        super(CommonModel, self).save()

    class Meta:
        abstract = True

My common model is in [project_root]/models.py. It is the parent object of this model, which is located in an app called Feedback [project_root]/feedback/models.py:

from django.db import models
from mediasharks.models import CommonModel

class Feedback(CommonModel):
    message = models.CharField(max_length=255)
    request_uri = models.CharField(max_length=255)
    domain = models.CharField(max_length=255)
    feedback_type = models.IntegerField()

Basically I'm trying to set up a common model so that I'll always be able to tell when and by whom database entries were created.

When I run "python manage.py validate" I get this error message: KeyError: 'app_label'

Am I missing something here?

+1  A: 

Note the bold text on your link: "Changed in development version". If you're not using a recent checkout of Django trunk - for instance, you're on the latest released version, 1.1 - you should be using this link for the documentation. That version of the text makes no reference to app_label, because it had not yet been introduced.

Daniel Roseman
Ah, thanks for that, Daniel. I'll read the docs more carefully next time.
rayan