I have the model below:
class Actor(Model):
VALUE_CHOICES = (
('int', 'Integer'),
('str', 'String'),
('float', 'Float'),
('bool', 'Boolean')
)
type = models.CharField(max_length=5, choices=VALUE_CHOICES, default='str')
_value = models.CharField(max_length=100, default='', db_column='value')
What I am trying to do is that based on the data selected in 'type' field, the '_value' field will check the input and convert it to the desired type. I was told using django @property could do this, but I'm not sure how it works together.
So far, I have tried this just to test, but to no avail:
@property
def value(self):
return self._value
@value.setter
def value(self, val):
print('This is self ', self, ' and val is ', val, ' and this is self ', self.request)
self._value = val
If anyone has an idea or can lead me in the right direction, I will appreciate it.