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