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