本文整理汇总了Python中forms.EventForm.save_m2m方法的典型用法代码示例。如果您正苦于以下问题:Python EventForm.save_m2m方法的具体用法?Python EventForm.save_m2m怎么用?Python EventForm.save_m2m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EventForm
的用法示例。
在下文中一共展示了EventForm.save_m2m方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save_m2m [as 别名]
def create(request):
if request.POST:
form = EventForm(request.POST, request.FILES)
if form.is_valid():
Event = form.save(commit=False)
Event.author = request.user
Event.pub_date = datetime.datetime.now()
Event = Event.save()
form.save_m2m()
return HttpResponseRedirect(reverse('event.views.home'))
else:
form = EventForm()
eighthour_advanced = datetime.datetime.now()+timedelta(hours=8)
d = eighthour_advanced.strftime("%Y-%m-%d %H:%M")
return render_to_response('create_event.html',
{'form': form,
'organizations': Organization.objects.order_by('title'),
'categories': Category.objects.order_by('title'),
'users': User.objects.order_by('username'),
'time2': d },
context_instance = RequestContext(request))
示例2: create_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save_m2m [as 别名]
def create_event(request, library_code, managed_libraries=[]):
library = org_utils.get_library(library_code, managed_libraries)
if not library:
return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')
if request.method == 'POST':
event_form = EventForm(request.POST, request.FILES, prefix='event_form')
event_content_forms = []
for lang in settings.LANGUAGES:
event_content_forms.append({
'form': EventContentForm(request.POST, prefix='event_content' + lang[0]),
'lang': lang[0]
})
if event_form.is_valid():
valid = False
for event_content_form in event_content_forms:
valid = event_content_form['form'].is_valid()
if not valid:
break
if valid:
event = event_form.save(commit=False)
event.library = library
event.save()
for event_content_form in event_content_forms:
event_content = event_content_form['form'].save(commit=False)
event_content.lang = event_content_form['lang']
event_content.event = event
event_content.save()
event_form.save_m2m()
return redirect('participant_events:administration:events_list', library_code=library_code)
else:
event_form = EventForm(prefix="event_form")
event_content_forms = []
for lang in settings.LANGUAGES:
event_content_forms.append({
'form': EventContentForm(prefix='event_content' + lang[0]),
'lang': lang[0]
})
return render(request, 'participant_events/administration/create_event.html', {
'library': library,
'event_form': event_form,
'event_content_forms': event_content_forms,
})