Monday, September 10, 2012

Re: Override save or other options?

11.9.2012 7:23, Lachlan Musicman kirjoitti:
> 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.

Rather than creating individual series of events from recurring I would
do a concept called "recurring event". So it would be just a single
event that is projected to spesific days as necessary. It requires a
slightly more work but it's easier to maintain - for example entry would
just state:

recurring = True
frequence = WEEKLY
start_date = 2012-09-11
end_date = 2012-12-01
start_time = 09:00
end_time = 10:00

Then I would roll out custom non-database concept of "calendar day" that
would be projected from database using both individual entries and
recurring entries.

Later on it would be very easy to modify existing recurring events and
for example add cancellation of single event by creating overriding
events concept.

This way amount of data will be kept relatively small, it's much easier
to read and modify. Of course drawback is that you need top level
mechanisms to work with single calendar entries that map to your
database representation.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate