On 12/19/08, James PIC <[email protected]> wrote: > On 12/19/08, Alessandro Ronchi <[email protected]> wrote: > > I need a way to change the product price until an expiration date. > > > > satchmo.discount is not the correct solution for me. > > > > Is it possible to create a new model that changes the unity product > > price dinamically, > > until it expires? > > > > something like: > > > > class Offer(models.Model): > > product = models.ForeignKey(Product) > > new_price = models.DecimalField(_("old price"), max_digits=14, > > decimal_places=6, help_text=_("The original price of the product. Will > > be set as the product price after offer is ended") > > expires = models.DateField(_("Expires"), null=True, blank=True) > > > > I dont' want to change the product model or satchmo code, if it's > possible. >
I'll elaborate. Add this field to the Offer class, but don't add it to your OfferAdmin class: normal_price. Implement Offer.save() to set normal_price to self.product.price, and call the parent save(). (now you've backupped the old price transparently! good job Offer class!) Use your Offer model normally: assign a product, new price, expire date. Make a script that has a run(verbose=True) function: - loops over Offer model instances, - updates the price of offerobject.product (set it to new_price or normal_price after testing offerobject.expires). Run the script with: ./manage.py runscript yourapp/yourscript.py (Prices will be updated! good job yourclass.py!) Last step: cron ./manage.py runscript yourapp/yourscript.py everyday or every hour depending on your needs (and server load, quantity of offers etc ...). Hope that helps. Regards, James. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
