#2122: get_FIELDNAME_display() fails on instance returned by
AddManipulator.save().
----------------------------+-----------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Core framework | Version: SVN
Severity: normal | Keywords:
----------------------------+-----------------------------------------------
Invoking get_FIELDNAME_display() on a model instance returned by
MODELNAME.AddManipulator.save() does not produce the expected result.
After working with malcolmt on #django we decided it might be a good idea
to file a ticket.
Problem: the value returned by get_FIELDNAME_display() is the string
representation of the field itself rather than the decoded field value.
The database seems to be intact, so I'd guess the severity/priority to be
normal. Possible work arounds include using the saved instance (after
extracting it from the db) rather than the instance returned by
MODELNAME.AddManipulator.save().
Here's a simple example. I've included an "Example" model rather than the
actual model to simplify the description of the problem.
{{{
IFIELD_CHOICES = (
(0, 'foo'),
(1, 'bar'),
(2, 'baz'),
)
DEFAULT_IFIELD_CHOICE = 1
class Example(models.Model):
ifield = models.IntegerField(choices=IFIELD_CHOICES,
default=DEFAULT_IFIELD_CHOICE,
blank=False)
another_field = models.CharField(maxlength=16, blank=False)
def __str__(self):
return '%s: %s' % (self.get_ifield_display(), self.another_field)
class Admin: pass
}}}
Given this model, the following code redirects to '1' when an Example is
successfully saved. I'd expect it to redirect to 'bar'.
{{{
def example_add_form(request):
"""Add an example to the db."""
manipulator = Example.AddManipulator()
new_data = {}
errors = {}
if request.POST:
new_data = request.POST.copy() # Need mutable POST data.
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data)
# Note: isinstance(new_data['top_level'], str)
# returns True here
example = manipulator.save(new_data)
return HttpResponse(example.get_ifield_display())
# Create the form and load it into the example Django HTML
template.
form = forms.FormWrapper(manipulator, new_data, errors)
return render_to_response('example.dht', {'form': form},
context_instance=RequestContext(request))
}}}
I'm using Ubuntu v.6.06, Apache v.2.0.55, Mod_python v.3.1.4, Python
v.2.4.3, Django Rev.3103 (SVN).
I hope this helps. Please contact me if you need further clarification.
--
Ticket URL: <http://code.djangoproject.com/ticket/2122>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates
-~----------~----~----~----~------~----~------~--~---