Django MONTH_CHOICES
Have you ever wanted to give your model some month choices relating to integers
1-12. I would guess it's pretty common - common enough to be included in
django.contrib
. Well, it is. Here is a quick tip on how to include it in a
model:
from django.db import models
from django.utils.dates import MONTHS
class RevenueGoal(models.Model):
month = models.PositiveSmallIntegerField(choices=MONTHS.items())
year = models.PositiveIntegerField()
goal = models.DecimalField('Revenue Goal', max_digits=8, decimal_places=2)