Issue
Hello I have two models
class A(models.Model):
slug = models.SlugField()
class Meta:
abstract = True
class B(A):
slug = models.CharField()
class Meta:
abstract = True
I get error AttributeError: Manager isn't available; B is abstract
How do can to redefine attribute in abstract class?
class A
cannot be changedю
Solution
Abstract models don't have a manager on them because they don't map to a database table. They are used to define reusable mixins that you can compose into concrete models. To make B
a concrete model remove the abstract
flag and then it will have an objects
attribute defined on its instances.
class A(models.Model):
slug = models.SlugField()
class Meta:
abstract = True
class B(A):
slug = models.CharField()
As an aside, as things stand with your models this is a pointless hierarchy because the slug
field on B
overrides the slug
field that is being inherited from A
and therefore there is currently zero shared custom functionality between the two definitions. You may as well just have B
inherit from models.Model
directly.
Answered By - jhrr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.