mailsender2015
mailsender2015

Reputation: 7

how to override an attribute in the object?

please help solve the problem.

have an object:

class Product:
    title = models.CharField(max_length=255)
    active = models.BooleanField(default=False)

I create a new object:

class Book(Product):
    slogan = models.CharField(max_length=255)
    active = models.BooleanField(default=True)  #???????

I need to override the attribute active. that is, to attribute always been active=True

at the same time I can not change the Product since I do not have access to it

Upvotes: 0

Views: 81

Answers (2)

Sławek Kabik
Sławek Kabik

Reputation: 699

You have two options. You can use save() method in your model or you can use pre_save() signal.

Upvotes: 1

Daniel Hepper
Daniel Hepper

Reputation: 29977

Unfortunately, that is not possible, see https://docs.djangoproject.com/en/dev/topics/db/models/#field-name-hiding-is-not-permitted

Upvotes: 0

Related Questions