try to use django generic class view

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

Sorting  is added  by adding  next construction to the  your class view:




class  yourclassview(ListView):
    """
    model =  yourmodel

    context_object_name = 'object_or_list'

    template_name = 'yourtemplate.html'

    def get_queryset(self):
        qs = yourmodel.objects.all().order_by('sortingcriteria
        return qs


2012/4/3 Barry Morrison <bdmorri...@gmail.com>:
> If you could point me to a more recent tutorial, I'm more than willing to go
> through it.
>
> Basically what I have now, is a list of links. I want to sort those links
> based on source (Reddit) then subreddit (Python).  The source and subreddits
> are fed from my DB and I want to select them from a drop-down menu.
>
>
> On Monday, April 2, 2012 1:34:58 PM UTC-7, skhohlov wrote:
>>
>> Ok.
>>  I'm not definitely sure  what  you want  to have but  I'm proposing
>> to do  simple  project with next functionality:
>>
>> 1)  prepare list of the links
>> 2)  ability  to click at the link  and receive some additional
>> information about link
>> 3)  button for deleting of  the link
>> 4)  button for creating new one
>>
>>  Which are be covered :
>>  class based view
>>  generic view
>> passing  values from view to form or template
>>
>>  If you are interested we can start. Also if you would like to add
>> some other areas let me know
>>
>>  Thanks,
>>  Serge
>>
>> 2012/4/2 Barry Morrison <bdmorri...@gmail.com>:
>> > Too much code? I'd rather too much than not enough, but if it'd help, I
>> > can
>> > cut down on future posts.
>> >
>> > Thanks for the information/guidance.  I'll try your suggestions and post
>> > my
>> > findings.
>> >
>> > Much appreciated!
>> >
>> > On Monday, April 2, 2012 2:18:29 AM UTC-7, skhohlov wrote:
>> >>
>> >> So much code ;-)
>> >>  at first I'm proposing  to add  some code for  form.is_valid block
>> >>  for example :
>> >> if form.is_valid():
>> >>             source = Sources.objects.get(name=source)
>> >>             allPosts = Posts.objects.filter(PostSource=source)
>> >>             subreddits = SubReddits.objects.all()
>> >>             source = form.cleaned_data['foo']
>> >>             return render_to_response('feeds.html',
>> >>                 {'allPosts': allPosts,
>> >>                 'subreddits': subreddits},
>> >>                 context_instance=RequestContext(request))
>> >>   else:
>> >>  print form.error
>> >>
>> >>  This  will help to catch error  with form .
>> >>
>> >>  Also it is not correct to use this construction:
>> >>
>> >> class SourceSelection(forms.Form):
>> >>     sources = Sources.objects.all()
>> >>     foo = forms.ChoiceField(choices=sources)
>> >>
>> >> This mean  that you never add  any sources. or sources object are add
>> >> before starting application. For dynamic  loading objects in the form
>> >> use form constructor.
>> >>  and last one point :
>> >>
>> >>  Please separate views and form in the different files : views.py
>> >> forms.py
>> >>
>> >> 2012/4/2 Barry Morrison <bdmorri...@gmail.com>:
>> >> > Full Disclosure: I've been using Python for 5-6 months. Django for
>> >> > maybe
>> >> > 3
>> >> >
>> >> > I have this: https://gist.github.com/a934fe08643e0c3ee017
>> >> >
>> >> > In an effort to teach myself, I'm simply building a Django app. For
>> >> > teaching
>> >> > purposes only. It's an aggregator of favorites across multiple sites.
>> >> > Right
>> >> > now, I'm simply dealing with saved items from Reddit.
>> >> >
>> >> > The problem I'm having is the drop-down selector POST'ing and
>> >> > creating a
>> >> > the
>> >> > new URL.
>> >> >
>> >> > http://imgur.com/a/FL32I << Screen shots
>> >> >
>> >> > 1) root or /feeds/
>> >> > 2) Select Reddit from drop-down
>> >> > 3) Displays Reddit items only /feeds/Reddit/
>> >> > 4) Select 'Python' from drop-down, displays items from r/Python with
>> >> > URL
>> >> > /feeds/Reddit/Python
>> >> >
>> >> > This works (manually entering URL's), the drop down does not.
>> >> >
>> >> > I currently get "Error 1" from the gist.
>> >> >
>> >> > On views.py, if I uncomment lines 16 - 19, and comment the lines 21 -
>> >> > 23, I
>> >> > get a different error: "Error2" from the gist.  What I don't
>> >> > understand
>> >> > regarding the 2nd error, is that it is in fact returning: source:
>> >> > u'Reddit'
>> >> > and that exists in the Model, so it makes me think it's expecting
>> >> > something
>> >> > other than u'Reddit'.
>> >> >
>> >> > I'm at a loss, so this is me asking for help.  Sorry for the long
>> >> > post
>> >> > and
>> >> > crazy amounts of information.
>> >> >
>> >> > Any help is GREATLY APPRECIATED!
>> >> >
>> >> > Thanks!
>> >> >
>> >> > POST
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Django users" group.
>> >> > To view this discussion on the web visit
>> >> > https://groups.google.com/d/msg/django-users/-/zXNmsoqAfdMJ.
>> >> > To post to this group, send email to django-users@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > django-users+unsubscr...@googlegroups.com.
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/django-users?hl=en.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/django-users/-/S3mhDHD8nu4J.
>> >
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Tgz68neJN0AJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to