Hi Doug,

Thanks for your reply. I've been trying to get something together to
see if I can figure this all out. In the end I came up with something
like this (so far):

from myproject.shop.models import Product
from django import template

register = template.Library()

def get_latest_products(parser, token):
    # Get list of products by date.
    latestProducts = Product.objects.all().order_by('pub_date')[:5]
    return latestProductsNode()

class latestProductsNode(template.Node):

    def __init__(self):
        # Get list of products by date.
        self.latestProducts =
Product.objects.all().order_by('pub_date')[:5]

    def render(self, context):
        return self.latestProducts

register.tag('latest_products', get_latest_products)

Something tells me this is not the way to go about what I want to do.
Anyone care to give me any pointers on this?

Thanks,

James

On Jun 29, 7:08 pm, Doug Van Horn <[EMAIL PROTECTED]> wrote:
> On Jun 29, 12:59 pm,dystopia<[EMAIL PROTECTED]> wrote:
>
> > [snip]... Would I
> > then have have to implement the functionality of this in every view by
> > calling an cartSummary method and pushing that out into the template?
> > Or is it better to somehow compile all this functionality into a
> > template tag itself - if that's possible?
>
> > Any ideas appreciated,
>
> > James
>
> I've taken the latter approach in my projects.  Something like:
>
> {% load cart_tags %}
> {% get_cart as cart %}
> {% for items in cart %}
> ...
> {% endfor %}
>
> Then, you might put that code somewhere higher up in the template
> hierarchy:
>
> {% block shopping_cart %}
> <snip from above>
> {% endblock %}
>
> or you might include it as a template:
>
> {% include "shopping_cart.snippet..html" %}
>
> Whatever you do, I would recommend taking the approach of loading the
> shopping cart a tag.
>
> That's my opinion, anyway.
>
> doug.


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to