On Mon, Mar 16, 2009 at 11:26 PM, luxagraf <luxag...@gmail.com> wrote:

>
> Hello all-
>
> I'm working of a site that will store various business listings
> (restaurants, bars, clubs etc) and then I'd like to also track the
> hours each business is open... The ultimate goal being something like
> lawrence.com's "open now" feature and other time-related queries of
> that type. I'm trying to figure out the best way to store the hours
> data and was wondering if anyone had any suggestions...
>
> Because the open and close times vary by day of the week, storing them
> directly in the business model (or the models inheriting from it in
> this case) isn't possible.
>
> My instinct is to use a separate model for the hours and then tie it
> to the business model using generic relations to span various models.
> I know that would work, but I can't shake the feeling that there's a
> better way and I'm just not seeing it, so I thought I'd throw it out
> there and see what others think.
>
> I also should note that I'm not terribly concerned with the admin
> interface aspect (I don't plan to enter most of this data through the
> admin, it's already in a spreadsheet so I'll likely just load it all
> at once using a script and make the occasional update via the admin).
> My primary concern is optimizing for speed, i.e. the less joins, multi-
> table and other expensive database queries the better.
>
> If anyone has any suggestions or tips I'd love to hear them.
>
> cheers
> Scott Gilbertson
> luxag...@gmail
>
> >
>
I designed something like this a while back(but never had to implement it).
Basically I had a DayHour model that had a foreign key to the "store" model
and kept the start hour and close hour for a given day of the week.  So a
query like what is open now would look like:

Model.objects.filter(hours__day="M",
hours__open__lte=datetime.datetime.now().hour,
hours__close__gte=datetime.datetime.now().hour)

I guess technically you could just have 14 fields on the mode(open and close
for each day of the week), which is fine since days of the week are a static
number of things but that felt bulky to me(though it's probably more
preformant).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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