[Solved]-Django proxy model with additional model fields?


It looks like this might work for the __getattr__:

def __getattr__(self, key):

    if key not in ('original', '_ original_cache'):
        return getattr(self.original, key)      
    raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, key))


What about making CustomArticle a subclass of Article? Django models do support inheritance! Have a look at: https://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance


try something like this:

class CustomArticle(models.Model):
    # Other methods...

    original = models.ForeignKey('Article')

    def __getattr__(self, name):
        return getattr(self.original, name)

Leave a comment