Tuesday, November 26, 2013

Re: Filtering by month doesn't work

I am no using that condition,
I am absolutely sure that I have november dates in my DB (i am using MySQL).
I tried everything in terms of using datetime to compare db month with, no luck so far....

Dne úterý, 26. listopadu 2013 3:54:09 UTC+1 Начаров Михаил napsal(a):
Hi Tranta.
In my projects this functionality works fine. 
What version of django did you used? 
Do you sure that field end in Event table contains November dates?

Also, you can use today.month instead of  int(today.strftime('%m')) and today.year instead of  int(today.strftime('%Y')).
And in django docs says that it necessary to validate your form before use it:
if event_form.is_valid():
    event = event_form.save()

вторник, 26 ноября 2013 г., 5:24:21 UTC+6 пользователь Vojtěch Tranta написал:
Hi,
do you have any clue why this does not work?

def index(request):
if request.method == 'POST' and request.POST:
event_form = EventForm(request.POST)
event = event_form.save()

today = datetime.date.today();
year = int(today.strftime('%Y'))
month = int(today.strftime('%m'))
events = Event.objects.filter(end__month='11')
# events = Event.objects.all()
pdb.set_trace()
cal = jvccalendar.HTMLCalendar(jvccalendar.MONDAY).formatmonth(year, month, events)
form = EventForm()
return render_to_response('jvc/index.html', {'cal': cal, 'side_form': form}, context_instance=RequestContext(request))

I am still getting "events" as empty, filtering using filter(end_start='2013') works, but filtering by month does not, I googled as much as I could, but no luck. I copied code from StackOverflow, but no luck.... 
Thank you!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2798f193-8853-4f67-897c-160a2b3babc9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment