views:

23

answers:

1

In AppEngine, I have a form that prompts a user for a date. The problem is that when the clicks enter there is an error: "Enter a Valid Date"

How do I make my Form accept (for example) %d-%b-%Y as the date format? Is there a more elegant way to accomplish this?

# Model and Forms
class Task(db.Model):
  name=db.StringProperty()
  due=db.DateProperty()

class TaskForm(djangoforms.ModelForm): 
  class Meta: 
    model = Task 

# my get function has the following.
# using "now" for example. Could just as well be next Friday.
tmStart = datetime.now()  
form = TaskForm(initial={'due': tmStart.strftime("%d-%b-%Y")})
template_values = {'form': form }
A: 

Simply specify a custom field (and optionally, widget) in your TaskForm for that field, and set the properties as appropriate - see the django forms docs for details on how to specify fields.

Nick Johnson