本文整理汇总了Python中models.Course.position方法的典型用法代码示例。如果您正苦于以下问题:Python Course.position方法的具体用法?Python Course.position怎么用?Python Course.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Course
的用法示例。
在下文中一共展示了Course.position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: course_admin_update
# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import position [as 别名]
def course_admin_update(request, course_id, prefix):
if request.is_ajax():
form = CourseForm(request.POST) if prefix == 'None' else CourseForm(request.POST, prefix=prefix)
if form.is_valid():
try:
course = Course.objects.get(pk=course_id)
course.teacher = form.cleaned_data['teacher']
course.name = form.cleaned_data['name']
course.save()
return HttpResponse('OK')
except ObjectDoesNotExist:
# create new object
position = None
if Course.objects.count() > 0:
course = Course.objects.order_by('-position').all()[0]
position = course.position
else:
position = 1
newcourse = Course()
newcourse.teacher = form.cleaned_data['teacher']
newcourse.name = form.cleaned_data['name']
newcourse.position = position
newcourse.save()
response = {'created_object_id': newcourse.pk}
return HttpResponse(json.dumps(response), mimetype="application/json")
else:
errors_dict = {}
if form.errors:
for error in form.errors:
e = form.errors[error]
field = prefix+"-"+error;
errors_dict[field] = unicode(e)
print errors_dict
return HttpResponseBadRequest(json.dumps(errors_dict))
else:
return HttpResponseNotFound('You do not have permission to access this page!')