Dynamicaly alter django model's field return value
Let's say I have a setup similar to this:
class UnitsOfMeasure(models.Model):
name = models.CharField(max_length=40)
precision = models.PositiveIntegerField()
class Product(models.Model):
name = models.CharField(max_length=100)
uom = models.ForeignKey(UnitsOfMeasure)
qty_available = models.DecimalField(max_tigits=10, decimal_places=10)
Now lets say we have a product related to Units of measure instance with
precision = 2. How can I do that qty_available would return 5.50 instead
of 5.5000000000?
I know I can use property decorator, but this does not solve my problem,
since I want to use qty_available as a field in forms.
Custom Field type? How can I pass and access related model instance then??
Your ideas are very appreciated!
No comments:
Post a Comment