Skip to content

Commit 0c33661

Browse files
committed
added example views to show extendability
1 parent 21b94fc commit 0c33661

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Features:
4545
- Define your own custom queryset for list view
4646
- Inline Formset support for parent child models
4747
- Default Bootstrap3 CSS
48+
- All the generated views are extendable.
4849

4950
Prerequisites
5051
-------------

docs/source/overview.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Features
1818
- Define your own custom queryset for list view
1919
- Inline Formset support for parent child models
2020
- Default Bootstrap3 CSS
21+
- All the generated views are extendable.
2122

2223

2324
Requirements and Compatibility

example/example/urls.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
from django.conf.urls import include, url
22
from django.contrib import admin
3+
from example.views import(
4+
MyCustomPersonListView,
5+
MyCustomPersonCreateView
6+
)
37

48
urlpatterns = [
59
# Examples:
610
# url(r'^$', 'example.views.home', name='home'),
711
# url(r'^blog/', include('blog.urls')),
812

13+
url(r'^mycustom_people/$', MyCustomPersonListView.as_view(), name='mycustom-people'),
14+
url(r'^mycustom_people/create/$', MyCustomPersonCreateView.as_view(), name='mycustom-create'),
15+
916
url(r'^admin/', include(admin.site.urls)),
10-
url(r'^auth/', include('django.contrib.auth.urls')),
11-
url(r'^crud/', include('crudbuilder.urls')),
12-
]
17+
url(r'^auth/', include('django.contrib.auth.urls')),
18+
url(r'^crud/', include('crudbuilder.urls'))
19+
]

example/example/views.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from django.core.urlresolvers import reverse
2+
from django.http import HttpResponseRedirect
3+
4+
from crudbuilder.views import ViewBuilder
5+
from example.crud import PersonCrud
6+
7+
builder = ViewBuilder('example', 'person', PersonCrud)
8+
builder.generate_crud()
9+
10+
PersonListView = builder.classes['PersonListView']
11+
PersonCreateView = builder.classes['PersonCreateView']
12+
PersonUpdateView = builder.classes['PersonUpdateView']
13+
PersonDetailView = builder.classes['PersonDetailView']
14+
15+
16+
class MyCustomPersonListView(PersonListView):
17+
def get_context_data(self, **kwargs):
18+
context = super(MyCustomPersonListView, self).get_context_data(**kwargs)
19+
context['your_template_variable'] = 'Your new template variable'
20+
return context
21+
22+
def get_queryset(self):
23+
# return super(MyCustomPersonListView, self).get_queryset()
24+
return self.model.objects.none()
25+
26+
27+
class MyCustomPersonDetailView(PersonDetailView):
28+
def get_context_data(self, **kwargs):
29+
context = super(MyCustomPersonDetailView, self).get_context_data(**kwargs)
30+
# context['form'] = YourAnotherForm
31+
return context
32+
33+
def post(self, request, *args, **kwargs):
34+
self.object = self.get_object()
35+
# form = YourAnotherForm(request.POST)
36+
# if form.is_valid():
37+
# Do your custom logic here
38+
# pass
39+
return HttpResponseRedirect(
40+
reverse(
41+
'person-detail',
42+
args=[self.object.id]
43+
)
44+
)
45+
46+
47+
class MyCustomPersonCreateView(PersonCreateView):
48+
def form_valid(self, form):
49+
instance = form.save(commit=False)
50+
instance.created_by = self.request.user
51+
instance.save()
52+
# # your custom logic goes here
53+
return HttpResponseRedirect(reverse('mycustom-people'))

0 commit comments

Comments
 (0)