本文整理汇总了Python中django.views.generic.CreateView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python CreateView.as_view方法的具体用法?Python CreateView.as_view怎么用?Python CreateView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.generic.CreateView
的用法示例。
在下文中一共展示了CreateView.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def __init__(self):
self.create = login_required(CreateView.as_view(
model=self.model,
fields=('name',),
success_url=reverse_lazy('laboratory:laboratory_list'),
template_name=self.template_name_base + 'form.html'
))
self.edit = login_required(UpdateView.as_view(
model=self.model,
fields=('name',),
success_url=reverse_lazy('laboratory:laboratory_list'),
template_name=self.template_name_base + 'form.html'
))
self.delete = login_required(DeleteView.as_view(
model=self.model,
success_url=reverse_lazy('laboratory:laboratory_list'),
template_name=self.template_name_base + 'delete.html'
))
self.list = login_required(ListView.as_view(
model=self.model,
paginate_by=10,
template_name=self.template_name_base + 'list.html'
))
示例2: test_works_with_create_view_get
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def test_works_with_create_view_get(self):
viewfn = CreateView.as_view(
form_class=UserProfileMultiForm,
template_name='noop.html',
)
factory = RequestFactory()
request = factory.get('/')
# This would fail as CreateView passes instance=None
viewfn(request)
示例3: user_register
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def user_register(request, pk=None):
view_kwargs = {
'model': User,
'form_class': UserRegisterForm,
'template_name': "people/register_form.html",
}
if pk is None:
view_kwargs['success_url'] = "/people/profile/%(id)d/"
return CreateView.as_view(**view_kwargs)(request)
else:
return UpdateView.as_view(**view_kwargs)(request, pk=pk)
示例4: route
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def route(request, view_kwargs={}, pk=None):
"""
Route to the correct view based on Method or the existance of
pk.
"""
if request.method == "DELETE":
return DeleteView.as_view(**view_kwargs)(request=request, pk=pk)
else:
if pk:
return UpdateView.as_view(**view_kwargs)(request=request, pk=pk)
else:
return CreateView.as_view(**view_kwargs)(request=request)
示例5: test_works_with_create_view_post
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def test_works_with_create_view_post(self):
viewfn = CreateView.as_view(
form_class=BadgeMultiForm,
# required after success
success_url='/',
template_name='noop.html',
)
factory = RequestFactory()
request = factory.post('/', data={
'badge1-name': 'foo',
'badge1-color': 'blue',
'badge2-name': 'bar',
'badge2-color': 'purple',
})
resp = viewfn(request)
self.assertEqual(resp.status_code, 302)
self.assertEqual(Badge.objects.count(), 2)
示例6: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
from django.conf.urls import patterns, include, url
from django.views.generic import ListView, CreateView, DetailView, UpdateView, DeleteView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from entries.models import Entry
from entries.forms import HTML5Form
urlpatterns = patterns('',
url(r'^$',
ListView.as_view(
queryset = Entry.objects.order_by('-pub_date'),
template_name = 'entries/entry_list.html')),
url(r'^create/$',
CreateView.as_view(
model = Entry,
success_url = '/entries/',
template_name = 'entries/entry_form.html',
form_class = HTML5Form)),
url(r'^detail/(?P<pk>\d+)/$',
DetailView.as_view(
model = Entry,
template_name = 'entries/entry_detail.html'),
name = "entry_detail"),
url(r'^update/(?P<pk>\d+)/$',
UpdateView.as_view(
model = Entry,
template_name = 'entries/entry_form.html',
form_class = HTML5Form)),
url(r'^delete/(?P<pk>\d+)/$',
DeleteView.as_view(
model = Entry,
示例7: import
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
CourseHole,)
from courses.views import (ArenaDetailView,
CourseDetailView,)
urlpatterns = patterns('',
# TODO: Break these out into multiple urlpatterns
# Arena
url(r'^arenas/$', ListView.as_view(
model=Arena,
context_object_name="arenas",
), name="golfstats-courses-arenas"),
url(r'^arenas/create/$', CreateView.as_view(
model=Arena,
success_url=reverse_lazy('golfstats-courses-arenas'),
), name="golfstats-courses-arenas-create"),
url(r'^arenas/(?P<pk>\d+)/$', ArenaDetailView.as_view(
model=Arena,
context_object_name="arena",
), name="golfstats-courses-arenas-detail"),
url(r'^arenas/(?P<pk>\d+)/edit/', UpdateView.as_view(
model=Arena,
context_object_name="arena",
success_url=reverse_lazy('golfstats-courses-arenas'),
), name="golfstats-courses-arenas-edit"),
url(r'^arenas/(?P<pk>\d+)/delete/$', DeleteView.as_view(
model=Arena,
示例8: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
urlpatterns = patterns('',
url(r'^feature-types/?$',
FeatureTypeListView.as_view(queryset=FeatureType.objects.all()),
name='feature-type-list'),
url(r'^features/create/?$',
login_required(CreateFeatures.as_view()),
name='feature-create'),
url(r'^features/edit/?$',
login_required(EditFeatures.as_view()),
name='feature-edit'),
url(r'^feature-types/create/?',
login_required(CreateView.as_view(template_name='core/generic_form.html',
form_class=FeatureTypeForm)),
name='feature-type-create'),
url(r'^feature-types/update/(?P<pk>\d+)/?$',
login_required(UpdateView.as_view(template_name='core/generic_form.html',
queryset=FeatureTypeForm.Meta.model.objects.all(),
form_class=FeatureTypeForm)),
name='feature-type-update'),
url(r'^feature-types/delete/(?P<pk>\d+)/?$',
login_required(FeatureTypeDelete.as_view()),
name='feature-type-delete'),
# Map list
url(r'^maps/?$', MapListView.as_view(queryset=Map.objects.all()),
name='map-list'),
示例9: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, DetailView, CreateView
from sujets.models import Question
from sujets.views import vote, OptionCreateView
urlpatterns = patterns('',
url(r'^$', ListView.as_view(model=Question)),
url(r'^(?P<pk>\d+)/$', DetailView.as_view(model=Question), name='question_detail'),
url(r'^new/$', CreateView.as_view(model=Question), name='question_new'),
url(r'^(?P<question>\d+)/new/$', OptionCreateView.as_view(), name='option_new'),
url(r'^vote/$', vote, name="vote"),
)
示例10: OrderCreateView
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
from django.core.urlresolvers import reverse, reverse_lazy
from django.views.generic import ListView
from django.views.generic import DetailView
from django.views.generic import CreateView
from django.views.generic import UpdateView
from .models import Product
from .models import Order
from .forms import ProductForm
from .forms import OrderForm
product_list = ListView.as_view(model=Product)
product_detail = DetailView.as_view(model=Product)
product_new = CreateView.as_view(model=Product, form_class=ProductForm)
# success_url=reverse_lazy('shop:product_list'))
product_edit = UpdateView.as_view(model=Product, form_class=ProductForm)
# order_new = CreateView.as_view(model=Order, form_class=OrderForm)
class OrderCreateView(CreateView):
model = Order
form_class = OrderForm
def form_valid(self, form):
product = get_object_or_404(Product, pk=self.kwargs['product_pk'])
order = form.save(commit=False)
示例11: post_new
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
def post_new(request):
if request.method =='POST':
form = PostForm(request.POST)
if form.is_valid():
post = form.save()
return redirect(post)
# return redirect('blog:post_detail', post.pk)
else :
form = PostForm()
return render(request, 'blog/post_form.html', {
'form':form,
})
#upgrade version. overwirte
post_new = CreateView.as_view(model=Post, form_class=PostForm)
def comment_new(request, post_pk):
if request.method =='POST':
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False) #innerside, do not run model instance 'save' function
comment.post = Post.objects.get(pk=post_pk) #add post _ id
comment.save()
return redirect('blog:post_detail', comment.post.pk)
else :
示例12: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
urlpatterns = patterns('',
url(r'^node_list/$', ListView.as_view(
queryset=NetworkNode.objects.all(),
context_object_name='nodes',
template_name='django_dhcp/list.html'), name="node_list"),
url(r'^(?P<pk>[0-9]+)/$',
DetailView.as_view(
model=NetworkNode,
template_name='django_dhcp/detail.html',
context_object_name='node'
), name="detail"),
url(r'^create/$', CreateView.as_view(
model=NetworkNode,
template_name='django_dhcp/create.html',),
name="create"),
url(r'^update/(?P<pk>[0-9]+)/$',
UpdateView.as_view(model=NetworkNode,
template_name='django_dhcp/update.html'),
name="update"),
)
try:
from djangoautoconf import create_tastypie_resource
urlpatterns += (r'^api/node/', include(create_tastypie_resource(NetworkNode)))
except:
pass
示例13: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, CreateView
from models import Thing
from djangoratings.views import AddRatingFromModel
from django.core.urlresolvers import reverse
urlpatterns = patterns('ratings.views',
url(r'^$', ListView.as_view(
model=Thing,
paginate_by=10
)),
url(r'^add/$', CreateView.as_view(
model=Thing,
success_url='/'
)),
url(r'^rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(), {
'app_label': 'ratings',
'model': 'thing',
'field_name': 'rating',
}),
)
示例14: get_context_data
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
context_object_name = 'books'
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(BookList, self).get_context_data(**kwargs)
context['count_published'] = Book.objects.published().count()
return context
class BookDetail(DetailView):
model = Book
context_object_name = 'book'
class BookCreate(CreateView):
model = Book
form_class = BookForm
class BookUpdate(UpdateView):
model = Book
form_class = BookForm
author_list = ListView.as_view(model=Author)
author_detail = DetailView.as_view(model=Author)
author_create = CreateView.as_view(
model=Author, fields=['name'], success_url=r('bookstore:author_list'))
示例15: patterns
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import as_view [as 别名]
# -*- coding: UTF-8 -*-
from django.conf.urls.defaults import *
from django.views.generic import ListView, CreateView
import forms
import models
urlpatterns = patterns('',
url(r'^$',
ListView.as_view(
queryset=models.Guestbook.published.all(),
paginate_by=5
),
name='list_guestbook'),
url(r'^new/$',
CreateView.as_view(
form_class=forms.GuestbookForm,
model=models.Guestbook,
),
name='new_guestbook'),
)