- Author:
- I159
- Posted:
- November 16, 2011
- Language:
- Python
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
if you have multiple choice field in front and you need just a string contains chosen values this is it! Unicode encoding row related with another snippet - "Switched value typed choice field", In typical cases, you do not need to call additional methods.
1 2 3 4 5 6 7 8 9 10 11 12 | class MultipleTypedChoiceModelField(models.Field):
"""
Saving value of all the checked checkboxes in the string
"""
def get_internal_type(self):
return 'MultipleTypedChoiceModelField'
def get_prep_value(self, value):
# In typical cases, you do not need to call additional methods,
# as incoming list already contains strings.
unicoded_val = [val.__unicode__() for val in value]
return ', '.join(unicoded_val)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.