<<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-custom-model-fields
>
> 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...@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-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