redseam

Syndicate content
Dustin Davis reviews... the internet.
Updated: 1 week 2 days ago

Django MONTH_CHOICES

Tue, 2013-03-26 10:10 -

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)

Related posts:

  1. Python, Django & the Google Adsense API I have been tasked with updating our real-time revenue stats...
  2. Django Textile/Markdown Template Caching Speedup I’ve been putting some time into updating an old site...
  3. Django Custom Upload Handler to Compress Image Files I got a somewhat unique request on a project the...

Related posts brought to you by Yet Another Related Posts Plugin.