BTW this is the save method for the model with the rounding function: def save(self): def roundminute(d, r): """Rounds the datetime d to the nearer r multiple If r == 15 => 3:00 -> 3:00 3:05 -> 3:00 3:27 -> 3:30 3:55 -> 4:00
Adds hours correctly """ from datetime import datetime, timedelta m = d.minute if m > (60 - r/2): m = 0 d += timedelta(60*60) else: m = m - (m%r) if (m%r)<(r/2) else m+(r-(m%r)) return d.replace(minute=m, second=0, microsecond=0) if self.price == None: self.price = self.start_price self.start_date = roundminute(self.start_date, 15) self.end_date = roundminute(self.end_date, 15) super(Auction, self).save() On Mon, Oct 27, 2008 at 1:06 PM, Matías Costa <[EMAIL PROTECTED]> wrote: > I have the exact problem. I round end and start dates to 15 minutes. I > mean, user enters 12:10, I write 12:15. So each 15 minutes cron runs a > script with django-commands-extensions runscript. Is a balance between > accuracy and load. > > The perfect should be finding the next success to happen (easy) and program > django-cron or anything else to run at that time (I don't know how) > > I am very interested in the solutions people have found for this > > > On Mon, Oct 27, 2008 at 12:45 PM, redmonkey <[EMAIL PROTECTED] > > wrote: > >> >> Hi, >> >> I'm working on a simple auctioneer's website. My Catalogue app >> consists of a list of Lots arranged into Catalogues. Each catalogue >> has an auction_data field which stores a status and a date and time of >> the sale: >> >> class Catalogue(models.Model): >> DRAFT_STATUS = 1 >> LIVE_STATUS = 2 >> CATALOGUE_CHOICES = ( >> (DRAFT_STATUS, 'Draft'), >> (LIVE_STATUS, 'Live'), >> ) >> status = models.IntegerField("Status", choices=CATALOGUE_CHOICES, >> default=DRAFT_STATUS) >> auction_date = models.DateTimeField("Date of Auction") >> ... >> >> class Lot(models.Model): >> catalogue = models.ForeignKey(Catalogue, related_name="lots") >> ... >> >> Pretty simple stuff. My problem is that I need to run a function at >> the auction_date of the catalogue that will do a few things like >> change the status of the catalogue, and send an email out to some >> admins. >> >> I've done some brief research, and found <a href="http:// >> code.google.com/p/django-cron/" title="django-cron">django-cron</a>, >> and I imagine I could write something that checked each hour to see if >> any catalogues had expried recently, but that seems mad. >> >> Another solution I came up with involved checking for the expiry date >> every time a record is pulled up from the database. But this add's a >> hit to user responsiveness (even if it is tiny) and still doesn't >> allow me to send out the email. >> >> Finally, I read up on Django's signals to decide if I could use that >> mechanism to do other things. Signals sounds ideal, but I don't know >> how to trigger at the right time. >> >> Can anyone help me with this? How do I trigger a custom signal based >> on a DateTimeField value? >> >> Thanks, >> >> >> > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---