B
B
Boldy2014-11-20 20:34:27
Django
Boldy, 2014-11-20 20:34:27

Why doesn't sorting work in django templates?

There are two classes:

class TreeNode(MPTTModel):
    contract_date = models.DateField(null=False, blank=False)
    parent = TreeForeignKey('self', verbose_name='родитель', null=True, blank=True, related_name='children')
    
    class Meta:
        ordering = ['contract_date']

class ClientToCompanyPayment(models.Model):
    total = models.PositiveIntegerField(verbose_name='Сумма платежа', blank=False, null=False)
    date = models.DateField(verbose_name='Дата платежа', blank=False)
    client = models.ForeignKey(TreeNode, verbose_name='Участник', related_name="filterpayments")

    class Meta:
        abstract = True


class CashPayment(ClientToCompanyPayment):

    class Meta:
        ordering = ['date']

For some reason sorting by Meta.ordering in
{% for payment in user.treenode.filterpayments.all %} (возвращает объекты типа CashPayment)

works, but does not work. What can be wrong?
{% for child1 in user.treenode.children.all %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2014-11-20
@Boldy

I remember that in MPTTModel it was required to specify a certain ordering value . It seems by tree_id and lft .
I wouldn't bother; you can make the procedure ordered_children in the model, which displays the necessary elements and in the right order, and call it from the template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question