I'd like to see you model structure, but based on what I think it is:

class Entry(model.Model):
    categories=models.ManyToManyField(Category)

class Content(models.Model):
    entry=models.ForeignKey(Entry)

You have a Content Instance
You want to see other entries belonging to one or more of the
categories for that Content instances Entry instance

You could do a custom template tag like yours:

{% get_related_entries content_instance.entry  as related_entries %}

That tag would do something like the following :

#fetching primary key only since we don't need the whole thing
category_ids=content_instance.entry.categories.values("pk")
context['related_entries']=Entry.objects.filter(pk__in=category_ids)

That would work, but my choice would probably be to add a method to
your Entry class.

class Entry(models.Model):
    categories=models.ManyToManyField(Category)

    def related_entries(self,**filters):
        return
Entry.objects.filter(pk__in=self.categories.filter(**filters).values("pk"))

That way you don't need a tag at all.  Just do:

{% for related_entry in content.entry.related_entries %}
...
{% endfor %}

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