在选择中使用整数而不是字符串的任何理由?

时间:2016-06-10 00:40:45

标签: django database performance django-models

请考虑以下事项:

class Thing(models.Model):
  PRIORITY_LOW = 0
  PRIORITY_NORMAL = 1
  PRIORITY_HIGH = 2
  PRIORITIES = (
    (PRIORITY_LOW, 'Low'),
    (PRIORITY_NORMAL, 'Normal'),
    (PRIORITY_HIGH, 'High'),
  )

  priority = models.IntegerField(default=0, choices=PRIORITIES)

有没有理由不这样做,而是?

class Thing(models.Model):      
  PRIORITIES = (
    ('low', 'Low'),
    ('normal', 'Normal'),
    ('high', 'High'),
  )

  priority = models.CharField(max_length=10, default="low", choices=PRIORITIES)

好处:代码更少,现在我只需输入"normal"而不是models.Thing.PRIORITY_NORMAL

是否存在任何缺点,可能是从数据库的角度来看?

0 个答案:

没有答案