Abstract Django model doesn't have a "model" attribute?

Jonah Bishop

I have an abstract model in a Django app:

class HistoryTrackedModel(models.Model):
    def save(self, *args, **kwargs):
        super(self.model, self).save(*args, **kwargs) # Call the real save method
        # Do some miscellaneous work here (after saving)

    class Meta:
        abstract = True

A child model uses the abstract model as its base:

class Project(HistoryTrackedModel):
    name = models.TextField(unique=True, blank=False, db_index=True)
    ... other fields ...

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ('name',)

When I instantiate an instance of Project (the child model), and call the save() method, I get the following error:

'Project' object has no attribute 'model'

It's failing on the super(self.model, self).save() call in the abstract class's save method. I attempted to change that method to the following, but it (fairly obviously, now that I look at it) gets caught in a recursive loop:

class HistoryTrackedModel(models.Model):
    def save(self, *args, **kwargs):
        my_model = type(self)
        super(my_model, self).save(*args, **kwargs) # Call the real save method

What am I doing wrong here? Shouldn't all child classes that inherit from a base class (which itself inherits from models.Model) include the model attribute?

albar
super(HistoryTrackedModel, self).save(*args, **kwargs)  

should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AttributeError: "QuerySet" doesn't have attribute 'model'

From Dev

django : LookupError: App ' doesn't have a 'models' model

From Dev

django : LookupError: App ' doesn't have a 'models' model

From Dev

Django "can't set attribute" in model

From Dev

Derived attribute in Django model

From Dev

django abstract model inheritance import

From Dev

Django doesn't call model clean method

From Dev

Subclassing django model doesn't carry the Manager

From Dev

django model form with bootstrap doesn't work

From Dev

Django template doesn't show model items

From Dev

Can I delete an object of a model from view even though the user doesn't have permission? Django

From Dev

Choosing to have an attribute or model in rails

From Dev

How to remove unique constraint for a model attribute of an abstract model after inheritance?

From Dev

Yii create a new attribute in the model doesn't work

From Dev

Yii create a new attribute in the model doesn't work

From Dev

Switch on model attribute doesn't work - laravel 4

From Dev

python sklearn pickled model doesn't have the same number of features

From Dev

LookupError: App 'users' doesn't have a 'user' model

From Dev

through model for an Abstract model

From Dev

Django, get an attribute from a model

From Dev

Get Attribute type of a model in Django

From Dev

Django View/Model Attribute Error

From Dev

Django - A model can't have more than one AutoField

From Dev

Django - A model can't have more than one AutoField

From Dev

How to access parent abstract class of model in Django

From Dev

How to extend django abstract base model by inheritance?

From Dev

ForeignKey field related to abstract model in Django

From Dev

Register abstract model in admin django 1.6

From Dev

Django abstract model field name choice

Related Related

  1. 1

    AttributeError: "QuerySet" doesn't have attribute 'model'

  2. 2

    django : LookupError: App ' doesn't have a 'models' model

  3. 3

    django : LookupError: App ' doesn't have a 'models' model

  4. 4

    Django "can't set attribute" in model

  5. 5

    Derived attribute in Django model

  6. 6

    django abstract model inheritance import

  7. 7

    Django doesn't call model clean method

  8. 8

    Subclassing django model doesn't carry the Manager

  9. 9

    django model form with bootstrap doesn't work

  10. 10

    Django template doesn't show model items

  11. 11

    Can I delete an object of a model from view even though the user doesn't have permission? Django

  12. 12

    Choosing to have an attribute or model in rails

  13. 13

    How to remove unique constraint for a model attribute of an abstract model after inheritance?

  14. 14

    Yii create a new attribute in the model doesn't work

  15. 15

    Yii create a new attribute in the model doesn't work

  16. 16

    Switch on model attribute doesn't work - laravel 4

  17. 17

    python sklearn pickled model doesn't have the same number of features

  18. 18

    LookupError: App 'users' doesn't have a 'user' model

  19. 19

    through model for an Abstract model

  20. 20

    Django, get an attribute from a model

  21. 21

    Get Attribute type of a model in Django

  22. 22

    Django View/Model Attribute Error

  23. 23

    Django - A model can't have more than one AutoField

  24. 24

    Django - A model can't have more than one AutoField

  25. 25

    How to access parent abstract class of model in Django

  26. 26

    How to extend django abstract base model by inheritance?

  27. 27

    ForeignKey field related to abstract model in Django

  28. 28

    Register abstract model in admin django 1.6

  29. 29

    Django abstract model field name choice

HotTag

Archive