Yes, it sounds like a custom manager will do the job. Here's what I added:
class CurrentManager(models.Manager): def get_query_set(self): return super(CurrentManager, self).get_query_set().filter(event_date > datetime.date.today()) class Event(models.Model): ATTIRE_CHOICES = ( ('C', 'Casual'), ('F', 'Formal'), ) slug = models.SlugField(prepopulate_from=('name',), unique=True, help_text='This field will prepopulate from the name field.') name = models.CharField(max_length=200) location = models.ForeignKey('Location') description = models.TextField(help_text='Please use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.') event_date = models.DateField() start_time = models.TimeField() finish_time = models.TimeField() attire = models.CharField(max_length=1, choices=ATTIRE_CHOICES) featured_event = models.BooleanField() featured_event_photo = models.ForeignKey(Photo, blank=True, raw_id_admin=True, null=True) category = models.ForeignKey(Category) objects = models.Manager() current = CurrentManager() Only, when I try to get the current Event objects via the Django shell, I receive an error: >>> Event.current.all() Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/ypknox/webapps/django/lib/python2.5/django/db/models/ manager.py", line 67, in all return self.get_query_set() File "/home/ypknox/webapps/django/ypknox/apps/events/models.py", line 8, in get_query_set return super(CurrentManager, self).get_query_set().filter(event_date > datetime.date.today()) NameError: global name 'event_date' is not defined It sounds like I'm using "event_date" without defining it first. But the examples in the Django documentation do the same thing. What am I doing wrong? On Jun 30, 9:02 am, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 30 juin, 14:53, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > > > I'm wanting to display only current (vs. expired) calendar events via > > my Django events app. Each event has a date that it will occur. But > > I'm not sure of the best method to get only the current events in the > > db. > > > Current events are those whose date is less than or equal to the > > present date. They are expired when the present date is greater than > > the event date. > > > I have been able to display only the current events in the generic > > list view for all events by doing the following in my URLs: > > > event_list_info = { > > 'queryset' : Event.objects.filter(date__gte=datetime.date.today()), > > 'allow_empty' : True, > > > } > > > What's the best way to do this in my models? > > Use a custom manager, definitively. cf James Bennett's post on this > topic:http://www.b-list.org/weblog/2008/feb/25/managers/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---