FloatField instead of IntegerField in admin
I am storing data as Integers:
class Something(models.Model):
value = models.IntegerField(blank = True)
but I would like to allow user to edit this as FloatField in django admin site, for instance - I am storing price in dollars as the number of cents, but I would like users to edit the price in ordinary way, and then do necess开发者_运维知识库ary math and transform floats to integers.
Is this possible, and if so, how would I do that?
This is all form-related stuff.
Read up on widgets and validation. You can replace the data during validation, that's why the method is called clean
.
http://docs.djangoproject.com/en/1.3/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets
http://docs.djangoproject.com/en/1.3/ref/forms/validation/#
精彩评论