Hi Jon,

On 8/15/06, Jon Atkinson <[EMAIL PROTECTED]> wrote:
> Hi,
>
> One of the things which I love about django is the lack of code I have
> to write. I recently refactored some of my views from approximately 30
> lines of code down to just two, but I'm worried about the readablity
> of my code.
>
> For the simplest view, I think my code looks fine, and it's pretty readable:
>
> def index(request, page=0):
>         paginator = ObjectPaginator(Item.objects.all().order_by('-time'), 15)
>         return render_to_response('planetx/index.html', {'title': "Planet X",
> 'items': paginator.get_page(page)})
[snip]
> Any ideas or tips on style would be appreciated.
>
> --Jon

Your code looks perfectly legible to me (disclaimer: I'm a C++
programmer!). But...

Is there a pressingly good reason you're not using generic views for
your "list" pages? Pagination is exceptionally simple in generic
views, and you can still pass through a custom dictionary (but
pagination variables are automatic). You can also pass through context
processors if needs be.

Generic views look confusing, and look like they have questionable
value, until you start using them. You invariably end up deleting half
your views in favour of generic views - and more than that, it just
feels right :-)

Michael

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to