Skip to content

Instantly share code, notes, and snippets.

@Nagasaki45
Created October 31, 2014 22:15
Show Gist options
  • Select an option

  • Save Nagasaki45/75ec0d61899ce1c3cee5 to your computer and use it in GitHub Desktop.

Select an option

Save Nagasaki45/75ec0d61899ce1c3cee5 to your computer and use it in GitHub Desktop.
TDD with Python book. p. 221: Better implementation for field validation.
def clean_text(self):
data = self.cleaned_data['text']
if data in [item.text for item in self.instance.list.item_set.all()]:
raise forms.ValidationError(DUPLICATE_ITEM_ERROR)
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment