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, luke lukes wrote:
> 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 23:25:28 UTC+1, Nikolas
> Stevenson-Molnar ha scritto:
>
>     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):
>>     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_places=2,default=0)
>>     count = models.IntegerField("Count", default=0)
>>
>>     def __unicode__(self):
>>        return u"%s" % (self.label)
>>     class Meta:
>>        verbose_name_plural = "Activities"
>>
>>
>>     class Invoice(models.Model):
>>     subject = models.ForeignKey(Subject)
>>     date = models.DateField(default=date.today())
>>     activities = models.ManyToManyField(Activity)
>>     ....
>>     ....
>>
>>
>>     while creating a new Invoice instance on admin, i can select the
>>     many to many fields 'activities', but i'd like to have an
>>     additional counter (eg. an IntegerField) as an Invoice field to
>>     count and save the quantity of each activity added to my Invoice
>>     instance. Is this possible?
>>
>>     I mean: for each 'Activity' added to an Invoice instance, i need
>>     to count the amount of that activity.
>>
>>
>>     thanks,
>>
>>     LuKe
>>
>>
>>     -- 
>>     You received this message because you are subscribed to the
>>     Google Groups "Django users" group.
>>     To view this discussion on the web visit
>>     https://groups.google.com/d/msg/django-users/-/F07dICRAF9kJ
>>     <https://groups.google.com/d/msg/django-users/-/F07dICRAF9kJ>.
>>     To post to this group, send email to django...@googlegroups.com
>>     <javascript:>.
>>     To unsubscribe from this group, send email to
>>     django-users...@googlegroups.com <javascript:>.
>>     For more options, visit this group at
>>     http://groups.google.com/group/django-users?hl=en
>>     <http://groups.google.com/group/django-users?hl=en>.
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/S94XcwpnGkUJ.
> 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.

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

Reply via email to