Answer the question
In order to leave comments, you need to log in
How to display tree structure in Django admin panel?
Good afternoon everyone. There are three models:
class RegionsModel(models.Model):
name = models.CharField(max_length=64,
unique=True, )
def __unicode__(self):
return self.name
class DetachmentsModel(models.Model):
region = models.ForeignKey('RegionsModel',
on_delete=models.CASCADE,
related_name='region_children', )
name = models.CharField(max_length=64,
unique=True,
db_index=True)
def __unicode__(self):
return self.name
class DepartmentsModel(MPTTModel):
detachment = models.ForeignKey('DetachmentsModel',
on_delete=models.CASCADE,
related_name='detachment_children', )
name = models.CharField(max_length=64,
unique=True,
db_index=True, )
slug = models.SlugField(max_length=64,
unique=True,
primary_key=True, )
def __unicode__(self):
return self.name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question