Answer the question
In order to leave comments, you need to log in
How to add an unlimited number of branches to the organization model in the django admin?
Hello. At me such problem
Is the organization and there are its branches. Each organization can have several branches, and therefore in the admin panel it was necessary to make sure that the fields of branches are added dynamically.
To do this, I created 2 models (Organization, Branches) and linked them in the admin panel via admin.StackedInline
models.py
class Branches(models.Model):
phone = models.CharField('Телефон', max_length=50)
address = models.CharField('Адрес', max_length=50)
branch = models.ForeignKey('Organization', null=True, blank=True)
class Organization(models.Model):
title = models.CharField('Заголовок', max_length=50)
phone = models.CharField('Телефон', max_length=50)
address = models.CharField('Адрес', max_length=50)
class BranchesInline(admin.StackedInline):
model = Branches
extra = 1
class OrganizationAdmin(admin.ModelAdmin):
inlines = [BranchesInline]
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