当前位置: 首页>>代码示例>>Python>>正文


Python EventForm.save_m2m方法代码示例

本文整理汇总了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))
开发者ID:kevinchipotw,项目名称:URevents,代码行数:29,代码来源:views.py

示例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,
    })
开发者ID:VBelozyorov,项目名称:libcms,代码行数:48,代码来源:views.py


注:本文中的forms.EventForm.save_m2m方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。