Thanks John,
You got me pointing in the right direction.
I reduced my admin.py to this:
from shipping.zone_shipping.models import Carrier, Zone, Tarif
from satchmo.l10n.models import Country
from django.contrib import admin
admin.site.register(Carrier)
admin.site.register(Zone)
class TarifOptions(admin.ModelAdmin):
ordering = ('min_weight', 'max_weight', 'tarif')
admin.site.register(Tarif, TarifOptions)
and modified models.Shipper.cost() to this:
def cost(self):
"""
Complex calculations can be done here as long as the return
value is a dollar figure
"""
country = self.contact.shipping_address.country.name
weight = 0
product_weight = 0
for cartitem in self.cart.cartitem_set.all():
if cartitem.product.weight:
product_weight = cartitem.product.weight
weight += product_weight * cartitem.quantity
tarif = 0
tarif =
Tarif.objects.filter(min_weight__lte=weight).filter(max_weight__gte=weight).filter(zone__country__name=country).filter(carrier__name
= self.carrier.name).values('tarif')
return tarif[0]['tarif']
Now the basic functionality is working, I just have to test it, and
l10n it and it'll be ready to share :D
Sam
On Oct 20, 6:06 pm, [EMAIL PROTECTED] wrote:
> On Oct 20, 2008, at 10:59 AM, nostradamnit wrote:
>
> > Ok, I'm making progress on this module, but I've run into a new
> > problem.
>
> > In the admin, when I try to add a Zone, I get the following error.
> > <class 'satchmo.l10n.models.Country'> has no ForeignKey to <class
> > 'shipping.zone_shipping.models.Zone'>
>
> I think in your admin.py, instead of this...
>
> class Country_Inline(admin.TabularInline):
> model = Country
> extra = 1
>
> class ZoneOptions(admin.ModelAdmin):
> ordering = ('name',)
> inlines = [Country_Inline,]
>
> ... you just want this:
>
> class ZoneOptions(admin.ModelAdmin):
> ordering = ('name',)
> filter_horizontal = ('country',)
>
> John
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---