1
|
|
|
from django.http import HttpResponseRedirect |
2
|
|
|
|
3
|
|
|
from crudbuilder.views import ViewBuilder |
4
|
|
|
from crudbuilder.helpers import reverse |
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.pk] |
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')) |
54
|
|
|
|