I fear your only option is to write a recursive function which you feed with what you define to be "the end of the chain". You can collect all the entries in a mutable list. Some example, untested, code:
def get_all_parents(list_, current): for entry in current.following_to.all(): list_.append(entry) list_.extend(get_all_parents(list_, entry) return list_ current = A parents = [] get_all_parents(parents, current) print parents Excuse me if I didn't get it right but it should get you started. On Aug 25, 10:11 am, Sven Richter <sver...@googlemail.com> wrote: > Hi, > > i implemented a many-to-many field in my model like: > class Entries(models.Model): > following_to = models.ManyToManyField('self', blank=True, null=True) > > Now i can get all related Entries in a template with entry.following_to.all. > But i want to go deeper in relationships. > > Lets say i have 4 Entries A, B, C, D. > A is following_to to B and > B is following_to to C and > C is following_to to D. > A.following_to.all gives back B. > > But what i need is to follow until the end of the chain is reached. > I need something like: > A.following_to.give_all_related_entries which then returns: > B, C, D > > Do i have to write my own template tag for that or is it already implemented > in Django? > Or maybe there is a better approach to solve my issue? > > I couldnt find a similar question or answer in the docs. > > Greetings > Sven --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---