4

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?

1
  • === is not a thing in python. Commented Feb 26, 2013 at 14:17

2 Answers 2

10

Try this:

def workDailyRecord(request):
    if request.method === 'GET':
        return tView.as_view()(request)
Sign up to request clarification or add additional context in comments.

2 Comments

url(r'^customer/(?P<slug>[^/]+)/$', customerDetailView.as_view())
def test(request):  return customerDetailView.as_view(slug=slug)
1
 def common_act(request, way, pk):
     types = {'grp':[10,'Group'],'std':[20,'Student']}
     events = {'crt':[1,'Create'], 'edt':[2,'Edit'], 'dlt':[3,'Delete']}
     ress = way.split('_')
     act_code = str(types[ress[1]][0] + events[ress[0]][0])

     action_way = {
            '11': CrtGroup,
           '12': EdtGroup,
           '13': DltGroup,
           '21': CrtStudent,
           '22': EdtStudent,
           '23': DltStudent
           }
return action_way[act_code].as_view()(request,pk=pk)

it`s work)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.