hi. I need help with this simple setup. i need to get a list of
announcements where active =1 and the discontinueDate is either null OR
less than NOW. There are two issues:
1) the filter doesn't work
2) numannouncements always equals 1 even when nothing is returned....
any ideas?
*
model:*
active_choices=(
(1,"Yes"),
(0,"No"),
)
class Announcement (models.Model):
Id = models.AutoField (primary_key=True)
adminTag = models.CharField (max_length=50, blank=False,
db_index=True,help_text=_("Shows in Admin for quick reference."))
active = models.IntegerField(blank=False, choices=active_choices)
synopsis = models.TextField (blank=False,
max_length=2000,help_text=_("Appears on sermon audio page."))
announcementDate = models.DateField(blank=False)
discontinueDate = models.DateField(blank=True)
class AnnouncementAdmin(admin.ModelAdmin):
list_display =
('adminTag','announcementDate','discontinueDate','active')
search_fields = ['adminTag','synopsis']
admin.site.register(Announcement,AnnouncementAdmin)
*view:*
def getAnnouncements (request):
dateNow = datetime.datetime.now().strftime("%Y-%m-%d")
try:
tms =
Announcement.objects.filter(active__exact=1).filter(discontinueDate__lt=dateNow).order_by('announcementDate')
numannouncements = Announcement.objects.count()
except:
tms = ''
numannouncements = 0
assert False, tms.active
return render_to_response('announcements/listpage.html',{'tms':
tms,'numannouncements':numannouncements},
context_instance=RequestContext(request))
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.