Re: help with query set

2013-07-14 Thread Mike Dewhirst

On 15/07/2013 1:11am, Bobby Roberts wrote:

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.


I haven't looked at your code but your words above indicate you want all 
announcements which haven't expired. I think that means a 
discontinueDate in future?


If so, you probably want one which is greater 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




--
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




help with query set

2013-07-14 Thread Bobby Roberts
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: need help in query set

2009-05-14 Thread Michael
On Thu, May 14, 2009 at 12:01 PM, Prabhjyot Singh  wrote:

>
> I am using
>resultset = queryset.get(status__in=['pending'])
> but it is giving me error which says:
>
> Exception Type: MultipleObjectsReturned
> Exception Value:
>
> get() returned more than one WapAd -- it returned 3! Lookup parameters were
> {'status__in': ['pending']}
>
> Exception Location:
> /usr/lib/python2.5/site-packages/django/db/models/query.py in get, line 277
>
>
> what should I do?
>

get tries to return only one item. If you want a queryset or multiple items
you want to use filter instead of get.

Hope that helps,
Michael

>
> >
>

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



need help in query set

2009-05-14 Thread Prabhjyot Singh

I am using
resultset = queryset.get(status__in=['pending'])
but it is giving me error which says:
   
Exception Type: MultipleObjectsReturned
Exception Value:

get() returned more than one WapAd -- it returned 3! Lookup parameters were 
{'status__in': ['pending']}

Exception Location: 
/usr/lib/python2.5/site-packages/django/db/models/query.py in get, line 277


what should I do?

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