On Wed, May 5, 2010 at 5:33 PM, LeeRisq <[email protected]> wrote: > This is mostly me just venting, but why is it if you run a query like > this: > > a = Model.objects.get(pk=1) > > Which has an attribute with an output of: > > a.date = None > > I pass that to a template, change some other attribute and then > attempt to pass it back in: > > date = request.GET['a.date'] > b = Model.object.get(date=date) > > And I get a ValidationError stating that I must enter a date in a > valid format. sigh > Shouldn't the output validate as input? Unless someone knows of a good > reason for this? >
If you try: Model.object.get(date=None) from a Python manage.py shell I believe you will see that would be accepted. The problem is you are not getting back Python None from request.GET['a.date']. The problem is likely in the round trip to the browser and back and you've rather left out a lot of details in "pass that to a template...pass it back in": what exactly are you doing here? What gets passed to the template and what is in the template? (And are you really processing changed data values via GET and not POST?) Note if you were using a ModelForm for this model to handle display and update, it would just work. The form field for the date would clean the submitted data (an empty string, since HTML has no "None") and normalize the empty submitted value to Python None. One other note: Model.object.get(date=None) looks a bit dangerous. Are you sure you will only ever have exactly one of these models with no date? Attempting to get on a field that is not guaranteed to be unique will raise an exception when zero or more than one matches are found. Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

