Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Generic Views with flair?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Lachlan Musicman  
View profile  
 More options May 6 2012, 6:57 pm
From: Lachlan Musicman <data...@gmail.com>
Date: Sun, 6 May 2012 15:57:50 -0700 (PDT)
Local: Sun, May 6 2012 6:57 pm
Subject: Generic Views with flair?
I've happily worked out how to work @login_required for entries in
views.py, but since the latest tutorial (which I followed) recommends
moving to the Generic Views my code is now like this:

urls.py

...
        url(r'^people/$',
            ListView.as_view(
                queryset=Person.objects.all())),

        url(r'^person/(?P<pk>\d+)/$',
            DetailView.as_view(
                model=Person)),
...

How would I set the @login_required for these? Do I have to go back to
writing them up in views.py for this functionality?

Further, the Person model is FK'd to a bunch of other traits like
Certificates, (Work) Experience and Qualifications. They come up fine
in the admin interface, using inlines. I read in the docs that there
are some extra Generic Views so I've added a CreateView and an
UpdateView to my urls.py

        url(r'^person/add/$',
            CreateView.as_view(
                #model=Person)),
                template_name='ner/person_create.html',
                form_class=PersonForm)),

        url(r'^person/(?P<pk>\d+)/edit/$',
            UpdateView.as_view(
                model=Person)),

But now I'm uncertain how I can include the extra traits within these
two functions - they don't appear by default, I'm just getting the raw
Person model. I would like to have it like I can in the admin
interface via the Inlines?

Cheers
L.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Sokolowski  
View profile  
 More options May 7 2012, 11:09 am
From: "Daniel Sokolowski" <daniel.sokolow...@klinsight.com>
Date: Mon, 7 May 2012 11:09:50 -0400
Local: Mon, May 7 2012 11:09 am
Subject: Re: Generic Views with flair?
For your first question you can:

url(r'^people/$',
        login_required(ListView.as_view(
            queryset=Person.objects.all()))),

or in your view decorate the dispatch method:

@method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ProtectedView, self).dispatch(*args, **kwargs)

See:
https://docs.djangoproject.com/en/dev/topics/class-based-views/#decor...

For the second question I can only suggest you look into overriding the
default ModelForm of the view and using that. The docs are a still little
lacking but see
https://docs.djangoproject.com/en/dev/ref/class-based-views/#editing-...
and also take a look at the code itself
https://github.com/django/django/blob/master/django/views/generic/edi....
Doing the latter part thought me a lot about using class based views.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sbrandt  
View profile  
 More options May 9 2012, 8:59 am
From: sbrandt <s.brandt.ber...@googlemail.com>
Date: Wed, 9 May 2012 05:59:53 -0700 (PDT)
Local: Wed, May 9 2012 8:59 am
Subject: Re: Generic Views with flair?
There is another way: Class Based View decorators:
http://djangosnippets.org/snippets/2668/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »