Curious, we had to do a similar thing for billing periods on our VoIP
system a while back.

We ended up using dateutil, here's a bit of a code dump.

This was all triggered from populate_billing_periods() which was called at
the point of processing billing info (which happens every 24 hours)

Would strongly recommend looking at dateutil tho

=====
def get_billing_periods(self, date):
return list(
    rrule.rrule(
        rrule.MONTHLY,
        dtstart=self.effective_start_date,
        until=date
    )
)

def populate_billing_periods(self, *args, **kwargs):
    # Now calculate all of our billing dates
    _billing_dates = self._get_billing_date_range()

    # this ensures we have all the correct billing periods
    for billing_date in _billing_dates:
        # create the billing period for this billing date
        billing_period, created = DomainBillingPeriod.objects.get_or_create(
            billing_date = billing_date,
            domain = self
        )
=====

Apologies for the messy dump, hope it helps a little tho.

Cal

On Tue, Sep 11, 2012 at 5:23 AM, Lachlan Musicman <data...@gmail.com> wrote:

> Hi All,
>
> Simplistically, I have an event type model (for a "school class") with
> a date field.
>
> On saving of the first event, I want to add recurring objects.
> Specifics for this project are "up to a latest date" (ie, end of term)
> and "recur weekly only" (not daily, monthly, yearly, etc - for the
> school's weekly timetable)
>
> I have just tried overriding the save method on the object to auto
> create these objects.
>
> def save(self):
>    super(Event, self).save()
>
>    last_date = self.term.end_date
>    series_date = self.date + datetime.timedelta(7)
>    while series_date < last_date:
>       super(Session, self).save(date = series_date)
>
> I've realised that this will most probably not make new objects, but
> will only update the date on the current object. Quite separately, I'm
> also getting keyword argument error on "date".
>
> How would you go about creating a series of events from a single save
> press? Should I be using some sort of external system (celery or ???)
> or should I write an additional method for the model that does the
> auto-creation?
>
> At some point after working this out, I will have a need to delete the
> series as well...and I don't even want to think about editing the
> series. Let's start with creating a recurring event and I'll work on
> that later.
>
> Cheers
> L.
>
>
>
>
> --
> ...we look at the present day through a rear-view mirror. This is
> something Marshall McLuhan said back in the Sixties, when the world
> was in the grip of authentic-seeming future narratives. He said, “We
> look at the present through a rear-view mirror. We march backwards
> into the future.”
>
> http://www.warrenellis.com/?p=14314
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to