Answer the question
In order to leave comments, you need to log in
Multi-linked list of models in Django?
In general, you need to make something like this structure of models. Each model has two fields - the previous elements and the next (each field can contain several objects). It suggests itself to use ManyToMany, but for some reason it does not work out. The code was written like this:
class Post(models.Model):
title = models.CharField(max_lenth=50)
next_posts = models.ManyToManyField('self', related_name='prev_posts', blank=True)
Answer the question
In order to leave comments, you need to log in
Once again, I answer to myself (lul can help someone later).
It turned out that it was necessary to add the symmetrical=False parameter (and it also turned out that it was better to search in English):
class Post(models.Model):
title = models.CharField(max_lenth=50)
next_posts = models.ManyToManyField('self', related_name='prev_posts', symmetrical=False, blank=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question