本文整理匯總了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!')