存储在数据库中以用于下拉单一选择框? (django)
我有下拉单选框“月” ,带有 3选项“ 1月”,“ 2月”和“ 3月” ,如下所示:
这是的代码下拉单一选择框“月” “ date”类下面的代码:
# "store/models.py"
from django.db import models
class Date(models.Model):
class Months(models.TextChoices):
JANUARY = 'JAN', 'January'
FEBRUARY = 'FEB', 'February'
MARCH = 'MAR', 'March'
month = models.CharField(max_length=100, choices=Months.choices)
这是的旧版本代码,下拉单曲单。 中的box“ noter” “ date”类下面等同于上述代码:
# "store/models.py"
from django.db import models
class Date(models.Model):
JANUARY = 'JAN'
FEBRUARY = 'FEB'
MARCH = 'MAR'
MANTHS = [
(JANUARY, 'January'),
(FEBRUARY, 'February'),
(MARCH, 'March')
]
month = models.CharField(max_length=100, choices=MANTHS)
现在,如果我选择“ 2月” ,然后单击 “保存” ,数据库中存储的内容? “ 2月” ? “ feb” ?还是“ 2月” ?
I have the Dropdown Single Select Box "Month" with 3 options "January", "February" and "March" as shown below:
This is the code for the Dropdown Single Select Box "Month" in "Date" class below:
# "store/models.py"
from django.db import models
class Date(models.Model):
class Months(models.TextChoices):
JANUARY = 'JAN', 'January'
FEBRUARY = 'FEB', 'February'
MARCH = 'MAR', 'March'
month = models.CharField(max_length=100, choices=Months.choices)
And, this is the old version code for the Dropdown Single Select Box "Month" in "Date" class below which is equivalent to the above code:
# "store/models.py"
from django.db import models
class Date(models.Model):
JANUARY = 'JAN'
FEBRUARY = 'FEB'
MARCH = 'MAR'
MANTHS = [
(JANUARY, 'January'),
(FEBRUARY, 'February'),
(MARCH, 'March')
]
month = models.CharField(max_length=100, choices=MANTHS)
Now, if I choose "February" and click on "SAVE", what is stored in database? "FEBRUARY"? "FEB"? or "February"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“ feb” 存储在数据库中。实际如下所示,“ 2月” 只是一个变量,“ feb” 是存储在db(数据库)和“ 2月”中的值中显示的选项是 on “添加日期”页面 django admin(GUI):
对于旧下面的版本代码:
如下所示,“ feb” 存储在数据库(sqlite)
” :
您可以在上查看数据库中存储的内容“选择日期更改日期” django admin(GUI),如下所示:
这是下面的完整代码:
,这是以下旧版本的完整代码:
"FEB" is stored in database. Actually as shown below, "FEBRUARY" is just a variable and "FEB" is the value stored in DB(Database) and "February" is the option displayed in the Dropdown Single Select Box "Month" on "Add date" page of Django Admin(GUI):
For the old version code below:
And as shown below, "FEB" is stored in database(SQLite)
In addition, by adding this code below to "Date" class:
You can check what is stored in database on "Select date to change" page of Django Admin(GUI) as shown below:
This is the full code below:
And, this is the full code for the old version below: