Re: django - adding a counter for every ManyToMany field added

2012-11-14 Thread Tom Evans
On Tue, Nov 13, 2012 at 8:49 PM, luke lukes wrote: > Hi everyone. hi have these models: > > #models.py > > class Subject(models.Model): > name = models.CharField("Name",max_length=50, blank=True) > ... > ... > > class Activity(models.Model): > label = models.CharField("Act. name",max_length=

Re: django - adding a counter for every ManyToMany field added

2012-11-14 Thread Bill Freeman
On Tue, Nov 13, 2012 at 11:44 PM, Vibhu Rishi wrote: > Would this not work : > > count = i.objects.filter(activities=Activity).count() > > Where you would put the count in a for loop for the Activity and iterate > over it. > > V. > > > On Wed, Nov 14, 2012 at 5:05 AM, Nikolas Stevenson-Molnar < >

Re: django - adding a counter for every ManyToMany field added

2012-11-13 Thread Vibhu Rishi
Would this not work : count = i.objects.filter(activities=Activity).count() Where you would put the count in a for loop for the Activity and iterate over it. V. On Wed, Nov 14, 2012 at 5:05 AM, Nikolas Stevenson-Molnar < nik.mol...@consbio.org> wrote: > I'm not sure I understand. Do you want

Re: django - adding a counter for every ManyToMany field added

2012-11-13 Thread Nikolas Stevenson-Molnar
I'm not sure I understand. Do you want the value of the "count" field in the Activity model? In that case, you could use values: activity_counts = i.activities.all().values('id', 'count') #Will give you something like [{'id': 1, 'count': 3}, {'id': 2, 'count': 5}, ...] _Nik On 11/13/2012 3:09 PM

Re: django - adding a counter for every ManyToMany field added

2012-11-13 Thread luke lukes
Hi. I don't need a total counter for all related activities. I need a counter for each related Activity: Invoice instance: activity A -> counter: 3 activity B -> counter: 5 ... ... is this possible? thanks, Luke Il giorno martedì 13 novembre 2012

Re: django - adding a counter for every ManyToMany field added

2012-11-13 Thread Nikolas Stevenson-Molnar
With an Invoice instance, you can easily get the number of related Activity objects: i = Invoice.objects.get(pk=1) num_activities = i.activities.all().count() _Nik On 11/13/2012 12:49 PM, luke lukes wrote: > Hi everyone. hi have these models: > > #models.py > > class Subject(models.Model):

django - adding a counter for every ManyToMany field added

2012-11-13 Thread luke lukes
Hi everyone. hi have these models: #models.py class Subject(models.Model): name = models.CharField("Name",max_length=50, blank=True) ... ... class Activity(models.Model): label = models.CharField("Act. name",max_length=150) price = models.DecimalField("price", max_digits=10, decimal_place