I'd definitely go that route (I think the "serialized data" bit in
your first post made me think you wanted to just wrap it up and be
done with it).

I'd probably even make it a OneToOneField instead of a ForeignKey to
reinforce the concept that an EventDateRange is a dedicated satellite
bit of data to a discrete Event, and just include it in the Event's
form structure as an inline. You also get an in-built interface of
"event.eventdaterange" instead of mucking around with, or aliasing,
"event.eventdaterange_set.all[0]".

On Jul 21, 9:38 am, Brad Buran <bbu...@alum.mit.edu> wrote:
> <<Sorry, last post was incomplete.  Accidentally hit send while composing.>>
>
> Hi Scott:
>
> Thank you for the suggestion.  I reviewed the docs, and it appears like it
> could work but would restrict the functionality.  For example, I would have
> to somehow serialize two datetime types plus a boolean type into a single
> database column.  This would take away a lot of advantages (such as being
> able to filter based on only one of the datetimes).
>
> One other option I am exploring is simply doing:
>
> class DateRange(Model):
>     start = DateTimeField()
>     end = DateTimeField()
>     all_day = BooleanField()
>
> # subclass DateRange so we can reuse it in various models
> class EventDateRange(DateRange):
>     date = ForeignKey(Event)
>
> class Event(Model):
>     #various other fields required for event
>
> Does this seem like it would make more sense?
>
> Thanks,
> Brad
>
>
>
> On Wed, Jul 21, 2010 at 8:03 AM, Scott Gould <zinck...@gmail.com> wrote:
> > My immediate thought upon reading your post was that you should build
> > an accompanying custom model field. Having said that, I haven't had
> > cause to do one that involved (only extend -- simply -- the stock
> > fields) so can't provide any specifics.
>
> >http://docs.djangoproject.com/en/1.2/howto/custom-model-fields/#howto...
>
> > On Jul 20, 10:00 pm, Brad Buran <bbu...@alum.mit.edu> wrote:
> > > I have a group of fields (date_start, date_end, all_day) that I would
> > like
> > > to reuse in several models.  I've defined a MultiWidget that displays two
> > > split datetime fields plus a checkbox (for the all_day toggle).  However,
> > > I'm not sure how to get the MultiWidget to set the value of these three
> > > fields in the model.  If I understand correctly, a MultiWidget can only
> > set
> > > the value of a single model field.  Hence, I would need to create some
> > sort
> > > of field (e.g. "combined_date_info") that MultiWidget saves the
> > serialized
> > > data from these three form fields.  Once I have done this, then I would
> > use
> > > model.save() to deserialize the data in the combined_date_info field and
> > > save it to the appropriate model fields.
>
> > > This solution seems a bit hackish and not very DRY.  Are there better
> > > approaches?
>
> > > Brad
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google 
> > groups.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-us...@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