Domanda

Does anyone has a working example of django mptt. I am not able to implement it. Maybe category system. Thanks

È stato utile?

Soluzione

Here is my code, part of an accounting app:

from mptt.models import MPTTModel
from mptt.fields import TreeForeignKey

class Category(MPTTModel):
    ledger = models.ForeignKey(Ledger)
    parent = TreeForeignKey(
        'self', null = True, blank = True, default = None,
        related_name = 'children'
    )
    label = models.CharField(max_length = 60)

This simply follows the documentation. Which specific part goes wrong for you?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top