Skip to content Skip to sidebar Skip to footer

Django Daterangefield Issue

I have a problem with DateRangeField inserting to database using Forms. model.py from django.contrib.postgres.fields import DateRangeField from django.db import models class Even

Solution 1:

After digging into the django source code, you should append number suffix for range field like that:

date_from = '2011-01-01'
date_to = '2011-01-31'data = {
    "name" : "Test Name",
    "datefromto_0" : date_from,
    "datefromto_1" : date_to
}

form = Event_form(data)
if form.is_valid():
    form.save()
else:
    print(form.errors)

I have used pdb to trace the code inside django, and found this trick...

And when you get stuck with other the issues in django next time, you can make use of pdb to trace. it is really a great tool for python debugging...

hope it would help... :).

Post a Comment for "Django Daterangefield Issue"