# Campaign that needs to be sent out to People
class Campaigns (models.Model):
userProfile = models.ForeignKey(UserProfile)
groups = models.ManyToManyField(Groups, blank=True, null=True)
# Groups of People
class Groups (models.Model):
userProfile = models.ForeignKey(UserProfile)
name = models.CharField( maxlength=100 )
groups_hash = models.CharField( maxlength=16 )
description = models.CharField( maxlength=100 )
If I have a campaign object that has 3 groups in it. And I want to
find all the reminder objects that are in those groups ... unless of
course it's a campaign with no groups in it - in which case I'd like
all the reminders associated with that campaign ?
This is my attempt, the second reminders statement won't work. I'm
wondering what the best way to go about a query like this would be ?
# campaign object from db
campaign = <campaign_object>
groups_list = campaign.groups.all()
# Are there groups ?
if groups_list.count() > 0 :
# find the reminders ??????
reminders = campaign.groups.reminders_set.all()
else:
reminders = Reminders.objects.get(campaigns=campaign)
if campaign.group_set.count():
reminders =
Reminders.objects.filter(campaigns__groups__id__in=[g.id for g in
campaign.group_set.all())
else:
reminders = Reminders.objects.filter(campains__pk=campaign.id)
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
Why hasn't anyone thought of something like capistrano for django. (Yeah
I know it can work, but there're a few features for RoR'ers).
Lots of people have thought of it. What they haven't done is written
it. Want to be the first? ;)
CH> Sure. Anyone to join me?
Show me a code and I'll join, since have a nagging need for such tool.
--
Andrey V Khavryuchenko
Django NewGate - http://www.kds.com.ua/djiggit/
Development - http://www.kds.com.ua
Call akhavr1975 on www.gizmoproject.com
I've been trying to mess about with it and what I've gotten so far is
this ...
# Get the details of the reminders to whom this campaign
will be
sent
if campaign.groups.all() > 0 :
# Each campaign has groups and each group has reminder
profiles
reminders_list =
Reminders.objects.filter(campaigns__groups__id__in=[g.id for g in
campaign.groups.all()])
else:
# Campaigns have no groups - send to
all
reminders_list =
Reminders.objects.filter(campaigns__pk=campaign.id)
The first time I try to access reminders_list for the 'if' clause ...
i get a programming error ...
thanks btw
On Sep 8, 1:31 pm, "James Bennett" <ubernost...@gmail.com> wrote:
>Hmm, I'm not entirely sure where you got the campaign.groups_set
>construction there James. There is no campaign.groups_set afaik ...
>
>
>
Probably from here :
http://djangoproject.com/documentation/db-api/#related-objects
Did you try it or just assume that James made a mistake ?
Chris
Yes, I tried it - and I tried many other combinations as well ...
Thanks