开发者

FloatField instead of IntegerField in admin

开发者 https://www.devze.com 2023-03-06 09:34 出处:网络
I am storing data as Integers: class Something(models.Model): value = models.IntegerField(blank = True)

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/#

0

精彩评论

暂无评论...
验证码 换一张
取 消