本文整理汇总了Python中models.Order.school方法的典型用法代码示例。如果您正苦于以下问题:Python Order.school方法的具体用法?Python Order.school怎么用?Python Order.school使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Order
的用法示例。
在下文中一共展示了Order.school方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import school [as 别名]
def view_order(request, compete_id=1):
if compete_id is None:
compete_id = 1
school = get_object_or_404(School, user=request.user)
competition = get_object_or_404(Competition, pk=compete_id)
groups = set(request.user.groups.all())
available_competitions = [c for c in Competition.objects.all()
if any(g in groups for g in c.available_for.all())]
parallels_for_competition = CompetitionForParallel.objects.filter(competition=competition)
parallels_for_competition_dict = dict((pc.parallel, pc) for pc in parallels_for_competition)
if competition not in available_competitions:
raise Http404('this competition is unavalilable for you')
if competition.state == 4:
return render_to_response('cabinet_order.html', {
'school': school,
'competitions': available_competitions,
'selected_competition': competition,
'form': None,
'message': '',
'parallels': parallels_for_competition,
}, context_instance=RequestContext(request))
else:
message = ''
messagestatus = 1
is_new = True
order_status = 'не подана'
blank_status = ''
try:
current_order = Order.objects.get(school=school, competition=competition)
order_status = current_order.get_status_display()
if competition.state == 3:
blank_status = current_order.get_blank_status_display()
is_new = False
except Order.DoesNotExist:
current_order = Order()
current_order.create_time = datetime.now()
current_order.competition = competition
current_order.school = school
if request.method == 'POST':
form = OrderForm(dict(request.POST.items()), instance=current_order)
if form.is_valid():
message = ('Заявка поступила на рассмотрение'
if is_new else
'Заявка изменена')
form.save()
else:
message='Неправильно указаны поля'
messagestatus = 0
if is_new:
current_order = None
#form = OrderForm(instance=current_order)
#form.errors = src_form.errors
else:
form = OrderForm(instance=current_order)
if is_new:
current_order = None
total = 0
total_cost = 0
if current_order:
order_parallels = OrderParallel.objects.filter(order=current_order)
total = sum(op.count for op in order_parallels)
total_cost = sum(op.count * parallels_for_competition_dict[op.parallel].cost for op in order_parallels if op.parallel in parallels_for_competition_dict)
return render_to_response('cabinet_order.html', {
'total': total,
'parallels': parallels_for_competition,
'total_cost': total_cost,
'competitions': available_competitions,
'selected_competition': competition,
'form': form,
'message': message,
'messagestatus': messagestatus,
'order': current_order,
'school': school,
}, context_instance=RequestContext(request))