Re: M2M with self throught int. table, how to access related items?

2011-08-16 Thread Nan
> For example, given a post, how to get set of posts which have traffic from 
> the post (post.tfrom_set ? )

Have you tried:

class Post(models.Model):
  ...
  def posts_with_traffic_from_here(self):
return Post.objects.filter(tto__tfrom=self)

> how to get post with a max "count" which is trafficked to the post

https://docs.djangoproject.com/en/1.2/topics/db/aggregation/#aggregating-annotations



On Aug 16, 2:36 pm, Yaşar Arabacı  wrote:
> Hi,
>
> I have tried to sent this e-mail before, but I guess it didn't make its way
> to the groups so I am trying to resent it, if this is a double post, I am
> sorry. I am having trouble understanding m2m relation to self with a
> intermediary table. Here is my table setup stripped:
>
>    class Post(models.Model):
>
>        relevancy =
> models.ManyToManyField("self",
> through="Traffic",symmetrical=False,related_name="relevant",blank=True)
>
>    class Traffic(models.Model):
>        tfrom = models.ForeignKey(Post,related_name="tfrom")
>        tto = models.ForeignKey(Post,related_name="tto")
>        count = models.PositiveIntegerField(default=0)
>
> This is to be a simple visitor tendency tool, which I keep records of
> which link clicked on which post. I am confused about, getting related
> items. For example, given a post, how to get set of posts which have
> traffic from the post (post.tfrom_set ? ), or how to get post with a
> max "count" which is trafficked to the post
> ( post.tto_set.max("count") ? ) etc.
>
> And also, what is the recommended way of getting, for example, given a post,
> which is the post with max "count" value from this post. Like, get a list of
> traffics where tfrom is given post, and get a Traffic object with max
> "count" and get tto post of that traffic.
>
> PS: English is not my main language. Sorry if I wasn't clear

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



M2M with self throught int. table, how to access related items?

2011-08-16 Thread Yaşar Arabacı
Hi,

I have tried to sent this e-mail before, but I guess it didn't make its way
to the groups so I am trying to resent it, if this is a double post, I am
sorry. I am having trouble understanding m2m relation to self with a
intermediary table. Here is my table setup stripped:

   class Post(models.Model):

   relevancy =
models.ManyToManyField("self",
through="Traffic",symmetrical=False,related_name="relevant",blank=True)

   class Traffic(models.Model):
   tfrom = models.ForeignKey(Post,related_name="tfrom")
   tto = models.ForeignKey(Post,related_name="tto")
   count = models.PositiveIntegerField(default=0)

This is to be a simple visitor tendency tool, which I keep records of
which link clicked on which post. I am confused about, getting related
items. For example, given a post, how to get set of posts which have
traffic from the post (post.tfrom_set ? ), or how to get post with a
max "count" which is trafficked to the post
( post.tto_set.max("count") ? ) etc.

And also, what is the recommended way of getting, for example, given a post,
which is the post with max "count" value from this post. Like, get a list of
traffics where tfrom is given post, and get a Traffic object with max
"count" and get tto post of that traffic.

PS: English is not my main language. Sorry if I wasn't clear

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



M2M with self throught int. table, how to access related items?

2011-08-16 Thread Yaşar Arabacı
Hi,

I am not a django guru (yet) and I am having what I would guess a
trivial django question. Here is my table setup stripped:

class Post(models.Model):

relevancy =
models.ManyToManyField("self",through="Traffic",symmetrical=False,related_name="relevant",blank=True)

class Traffic(models.Model):
tfrom = models.ForeignKey(Post,related_name="tfrom")
tto = models.ForeignKey(Post,related_name="tto")
count = models.PositiveIntegerField(default=0)

This is to be a simple visitor tendency tool, which I keep records of
which link clicked on which post. I am confused about, getting related
items. For example, given a post, how to get set of posts which have
traffic from the post (post.tfrom_set ? ), or how to get post with a
max "count" which is trafficked to the post
( post.tto_set.max("count") ? ) etc.

PS: English is not my main language. Sorry if I wasn't clear

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