Alex Ezell
unread,Jul 23, 2008, 11:29:17 PM7/23/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I have a model with choices setup like this:
CREDENTIALS_CHOICES = (
('LM', 'Licensed Mover'),
('IN', 'Insured'),
('DR', 'DOT Registered (Interstate)'),
)
credentials = models.TextField(max_length=2, blank=True, null=True,
choices=CREDENTIALS_CHOICES)
In my form, I create the form field like this:
credentials =
forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
choices=Roadshare.CREDENTIALS_CHOICES)
Now, Django wants that field in the DB to be a text[] and not just a
text (this is postgres).
However, if in my view I do something like this to get the meaningful
value from the choices:
post.credentials = post.get_credentials_display()
I get this error:
Traceback:
File "/home/user/lib/python2.5/django/core/handlers/base.py" in
get_response
85. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/user/webapps/str/myproject/posts/views.py" in view_post
108. post = format_values(post,share_model)
File "/home/user/webapps/str/myproject/posts/views.py" in
format_values
278. post.credentials = post.get_credentials_display()
File "/home/user/lib/python2.5/django/utils/functional.py" in _curried
55. return _curried_func(*(args+moreargs), **dict(kwargs,
**morekwargs))
File "/home/user/lib/python2.5/django/db/models/base.py" in
_get_FIELD_display
429. return force_unicode(dict(field.flatchoices).get(value,
value), strings_only=True)
Exception Type: TypeError at /view/truckshare/animal/offer/36/
Exception Value: list objects are unhashable
This is using the latest Django trunk. I just did svn up about two
hours ago.
Thanks for any pointers you can offer.
/alex