For example, there are two models and Message Manager.
class Manager(models.Model): name = models.CharField(max_length=255) create = models.DateTimeField(auto_now_add=True)
class Message(models.Model): text = models.TextField() manager = models.ForeignKey(Manager, models.SET_NULL, null=True)
Need to get the last 5 created Manager and to each of them belonging to the message.
How can I do that in the template to use a single object?
Or it is necessary in the first view to Manager
Managers = Manager.objects.all().order_by('-create')[:5]
And then using a loop to query
Messages = Enc.objects.filter(manager=Managers[i])
B as it is to try to combine in a single object or a list then cycles in the display template.
Is there a simpler way?