Dearest Django community,
I'm working on a ecommerce framework to help keep my sites
efficient/modular/maintainable. I'm pretty happy with my backend, but
I can't work out how I want it to be made accessible to
views/templates.
Currently it uses a declarative syntax to define the items, extras and
totals that a cart has, eg:
from rollyourown import shopping
from myapp.tax import calculate_tax
class CartPurchase(shopping.ModelPurchase):
# ITEMS
items = shopping.Items(attribute="items",
item_amount_from="model.item_price")
vouchers = shopping.Items(attribute="vouchers",
item_amount_from="self.get_voucher_amount")
# EXTRAS
tax = shopping.Extra("GST", amount=calculate_tax, included=True)
discount = shopping.Extra()
delivery = shopping.Extra()
# TOTALS
items_total = shopping.Total('items')
items_pretax = shopping.Total('items', '-tax')
vouchers_total= shopping.Total('vouchers')
total = shopping.Total(prevent_negative=True)
def get_delivery_amount(self, instance):
return "10.01"
def get_voucher_amount(self, instance):
return (-Decimal(instance.percent * self.items_total) /
100).quantize(Decimal("0.01"))
from myapp import models
shopping.register(models.Cart, CartPurchase)
(See http://code.google.com/p/rollyourown/wiki/RollyourownShopping for
more info on this)
That bit's fine! But the views and templates somehow need to know
about these totals and amounts. They generally have access to an
instance of your Cart (or Order etc) model, but that wont have these
totals in it. I really need some help deciding on how to:
1) let the developer access these totals. Currently, the come with an
object that has to be retrieved eg "shopping.get(MyModel, request)".
2) what should such an object look like. Current I'm automatically
generating a proxy model, with a ._shopping attribute which provides
all the totals. But I don't like the look of this. Maybe the system
should just return the object with the totals and a link to the
original model. Maybe the view should provide both as separate
variables.
So my question to everyone is:
* What sort of an object would you have in your views/templates? A
modified model (with all your special methods) with the cart totals
attached somehow? A cart totals object with the model attached or some
sort of evil hybid monster?
* How should this object be retrieved? Through a central repository,
or maybe automatically attached to the model (I'm not sure that's even
possible).
I hope this all makes sense, it's a bit tricky to describe a project
and its design problem in a short email. Thanks to anyone who takes
the time to understand what's going on here. I hope that the framework
I end up with will be useful (it's pretty damn useful to me so far :-)
Cheers,
Will
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---