Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date in the database schema #29

Closed
lord63 opened this issue Nov 5, 2015 · 2 comments
Closed

date in the database schema #29

lord63 opened this issue Nov 5, 2015 · 2 comments

Comments

@lord63
Copy link
Owner

lord63 commented Nov 5, 2015

int or string? I haven't touch the source code for a while, so I need time to decide to choose which one.

@lord63
Copy link
Owner Author

lord63 commented Nov 30, 2015

CharField 和 IntegerField(peewee 数据字段) 其实都是能工作的,看了下感觉应该是 CharField 比较合适吧,因为本身就是直接使用 '20151129' 这样的比较多,而且日期间的比较也是没有问题的。
照理来说好像要用 DateField,这样的话要稍微自定义下数据字段,不然每次都用 date 类型也是麻烦的,所以还是应该 '20151129' 这样的字符串传进去,调用时返回的应该也是 '20151129' 这样的。但这样的话,其实就是存的时候是 date 类型,出去进来都是 string 形式的,感觉就是多此一举了,不如直接使用 CharField。
其实我什么都不知道 >_<

@lord63
Copy link
Owner Author

lord63 commented Nov 30, 2015

比如说像这样的自定义字段

class ZhiDateField(Field):
    db_field = 'zhidate'

    def db_value(self, value):
        year, month, day = map(int, [value[:4], value[4:6], value[6:]])
        return date(year, month, day)

    def python_value(self, value):
        return value.replace('-', '')

@lord63 lord63 closed this as completed Dec 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant