> status.effectivedate is when a status 'starts', (like closed for repairs.)
> How do I get the 'current status based on current date' ?
> 
> so if the following 3 records are in the table:
> status
> effective date, description
> 1/1/2007 - open for business
> 3/24/2007 - closed for remodeling
> 5/1/2007 - open with a new look.
> 11/14/2007 - closed for Christmas
> 1/1/2008 - open - happy new year.
> 
> So right now, the status is "open with a new look."   when it is 11/14, the 
> current status will be "closed for Christmas."
> 
> The SQL is a big ugly, hoping the ORM will make it for me.

IIUC, you want the most recent status with a date earler than 
now, which should be doable via something like

  from datetime import datetime
  status = Status.objects.filter(
    effectivedate__lt = datetime.now()
    ).latest('effectivedate')


I'm not sure the SQL is all that ugly either, as it would be 
something like

   SELECT *
   FROM app_status
   WHERE effectivedate < NOW()
   ORDER BY effectivedate DESC
   LIMIT 1

but it's nice to have it abstracted in the ORM to avoid backend 
peculiarities regarding the NOW function and the syntax for 
limiting to one row.  ("now()" vs. "curdate"; "LIMIT" vs. "TOP")

As a side note, if you work someplace that closes for Christmas 
on 11/14, I want to work there! :)

-tim






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to