本文整理汇总了Python中models.Item.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python Item.full_clean方法的具体用法?Python Item.full_clean怎么用?Python Item.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.full_clean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_list
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import full_clean [as 别名]
def view_list(request, list_id):
list_ = List.objects.get(id=list_id)
error = None
if request.method == 'POST':
try:
item = Item(text=request.POST['item_text'], list=list_)
item.full_clean()
item.save()
return redirect(list_)
except ValidationError:
error = "You can't have an empty list item"
return render(request, 'list.html', {'list': list_, 'error': error})
示例2: test_todo_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import full_clean [as 别名]
def test_todo_item(self):
"""Tests the todo item model"""
# Does validation fail on an invalid item?
item = Item()
validatedSuccessfully = False
try:
item.full_clean()
except ValidationError:
validatedSuccessfully = True
self.assertEquals(validatedSuccessfully, True)
# Does validation pass on a valid item?
item.name = "test"
item.user = self.user
validatedSuccessfully = True
try:
item.full_clean()
except ValidationError:
validatedSuccessfully = False
self.assertEquals(validatedSuccessfully, True)