need to change logic of a helper

0 views
Skip to first unread message

stranger

unread,
Apr 9, 2008, 2:27:06 AM4/9/08
to Django users
hello group,

I am writing a blog application. I am not using generic view
as I have customized things. Now I wrote a helper.py in which I have
def get_post(year, month, day, slug):
year, month, day = int(year), int(month), int(day)

try:
return Post.objects.get(
pub_date__year=year, pub_date__month=month,
slug__exact=slug)

Now I want my url to be /2008/apr/08 instead of 2008/04/08. Thats
means the 'apr' string coming from url should be converted to 04
integer for comparision. Any help....

Rajesh Dhawan

unread,
Apr 9, 2008, 10:47:13 AM4/9/08
to Django users
Hi,

>
> Now I want my url to be /2008/apr/08 instead of 2008/04/08. Thats
> means the 'apr' string coming from url should be converted to 04
> integer for comparision. Any help....

Try this in your view where you need this conversion:

from django.utils.dates import MONTHS_3_REV
month_int = MONTHS_3_REV[month_string]

Where month_string is the 3-character month in string format (apr,
mar, etc.)

-Rajesh D

stranger

unread,
Apr 9, 2008, 11:52:17 AM4/9/08
to Django users
Thanks a lot it worked... I never heard of MONTHS_3_REV. Must be a new
one or I shouldn't have went through documentation. Anyway thanks

Rajesh Dhawan

unread,
Apr 9, 2008, 11:56:56 AM4/9/08
to Django users


On Apr 9, 11:52 am, stranger <strangersqu...@gmail.com> wrote:
> Thanks a lot it worked... I never heard of MONTHS_3_REV. Must be a new
> one or I shouldn't have went through documentation. Anyway thanks

It's not documented but there are a lot of such helpful gems hidden
in django.utils.*

stranger

unread,
Apr 9, 2008, 3:52:04 PM4/9/08
to Django users
I hope they are documented to some extent. Is there any resource to
know such hidden gems... Its really very helpful at times.
Reply all
Reply to author
Forward
0 new messages