X
X
xxx2018-02-13 22:14:11
Django
xxx, 2018-02-13 22:14:11

How to use _set for OneToOne models?

You need to create a queryset that will contain all the fields of connected models.

class Route(models.Model):
    name = models.CharField(max_length = 254, db_index=True, verbose_name='Имя")
    description = models.TextField(max_length = 600, verbose_name='Описание')

class Post(models.Model):
    title = models.CharField(max_length=100, verbose_name='Название', db_index=True)
    description = models.TextField(max_length=600, verbose_name='Описание')
    route = models.OneToOneField(Route, on_delete=models.CASCADE, verbose_name="Маршрут")

I know that you need to use _set in the request if there is no related_name in the database, but how can I make a request in one instance, so that later it has all the fields of the parent model and connected models and how to display this in the template?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question