On Tue, Feb 8, 2011 at 8:20 AM, Tres Finocchiaro
<[email protected]> wrote:
>
> Ok this seems fairly simple. Essentially I'll be adding a
> one-function-python templatetags file and importing it into my template? (or
> modifying an already existing templatetags file to have this new feature,
> correct?
>
This is correct. When customizing / extending satchmo as you describe,
it is best to do so in a way that doesn't change the satchmo codebase
(by making use of template directories, signals, context processors,
etc.). This makes future upgrades easier, among other advantages.
So anyway, I think the optimal way to implement your custom template
filter would be to create a new django app and include it in your
installed apps. In that app you would create the templatetags file
with the custom filter. Otherwise, if you don't care about keeping the
satchmo codebase pristine, the easiest way to create your feature
would be to simply create a total_qty property on the Order class.
> Since "order" is a built in object for Satchmo (i believe), and since I've
> never made my own template file before does anyone have a sample template
> file that uses "orders"? If there's one built-in, I'd be happy to use that
> too.
I think your templatetags directory would contain a myfilters.py with
something like this...
from django import template
register = template.Library()
@register.filter
def total_qty(order):
total = 0
for line_item in order.orderitem_set.all():
total += line_item.quantity
return total
-------------------------------------
Sorry about the clunky python; I have C brain-damage.
Then in your template -- have a look at
apps/satchmo_store/shop/templates/shop/_order_details.html for
example. You would copy this file into your templates directory and
update it as you wish. At the top you would add something like {% load
myfilters %} and then right above Contact Information (circa line 16)
you could add something like...
Total Quantity: {{ order|total_qty }} <br/>
I think that's about all there is to it.
--Stuart
> Reading an existing file will likely help bridge the knowledge-gap, since
> the language is still relatively new to me!! Thanks again!!!
> -Tres
> --
> - [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Satchmo users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/satchmo-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Satchmo users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/satchmo-users?hl=en.