Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 838B

12345678910111213141516171819202122232425262728
  1. from __future__ import unicode_literals
  2. from django import forms
  3. from django.utils import six
  4. from django.utils.translation import ugettext as _
  5. from taggit.utils import edit_string_for_tags, parse_tags
  6. class TagWidget(forms.TextInput):
  7. def format_value(self, value):
  8. if value is not None and not isinstance(value, six.string_types):
  9. value = edit_string_for_tags([
  10. o.tag for o in value.select_related("tag")])
  11. return super(TagWidget, self).format_value(value)
  12. class TagField(forms.CharField):
  13. widget = TagWidget
  14. def clean(self, value):
  15. value = super(TagField, self).clean(value)
  16. try:
  17. return parse_tags(value)
  18. except ValueError:
  19. raise forms.ValidationError(
  20. _("Please provide a comma-separated list of tags."))