Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: How to call class-based generic views in views.py?

I want to call class-based generic views in views.py

Please see my code...

urls.py

from django.conf.urls import patterns, include, url
from crm.views import *

urlpatterns = patterns('',
    (r'^workDailyRecord/$', workDailyRecord),
)

and my views.py.... please watch...

views.py

from django.views.generic import TodayArchiveView
from crm.models import *

def workDailyRecord(request):
    if request.method == 'GET':
        tView.as_view() # I want call class-based generic views at this line.
    elif:
        """
        Probably this part will be code that save the data.
        """
        pass

class tView(TodayArchiveView):
    model = WorkDailyRecord
    context_object_name = 'workDailyRecord'
    date_field = 'date'
    template_name = "workDailyRecord.html"

What should I do?

like image 463
chobo Avatar asked Dec 21 '22 10:12

chobo


1 Answers

Try this:

def workDailyRecord(request):
    if request.method === 'GET':
        return tView.as_view()(request)
like image 70
dusty Avatar answered Dec 28 '22 08:12

dusty