python – How do I use django mptt? – Education Career Blog

I have a model:

class Company(models.Model):
    name = models.CharField( max_length=100)
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Company, order_insertion_by='name')


class Financials(models.Model):
    year = models.IntegerField()
    revenue = models.DecimalField(max_digits = 10, decimal_places = 2)

So how can I add Financials as a child to Company in the mptt tree structure?


I don’t quite follow your question. A tree stores one type of object, in your case Company. To link Financials to Company just add a foreign key from Financials to Company.

If this doesn’t help please expand your question to give us some more detail about what you are trying to achieve.

Leave a Comment