如何在Django存储年份

时间:2022-12-10 16:57:23

What would be the best way to store year (YYYY) in a django model? I'm using a mysql backend.

什么是在django模型中存储年份(YYYY)的最佳方式?我正在使用mysql后端。

start_year = models.SmallIntegerField(blank=True, null=True) 

??

1 个解决方案

#1


3  

On second thought, since you're storing years, make it nonnegative.

在第二个想法,因为你存储了几年,使它成为非负。

start_year = models.PositiveSmallIntegerField(blank=True, null=True)

#1


3  

On second thought, since you're storing years, make it nonnegative.

在第二个想法,因为你存储了几年,使它成为非负。

start_year = models.PositiveSmallIntegerField(blank=True, null=True)