Answer the question
In order to leave comments, you need to log in
How to make nested ForeignKeys in admin?
Hello, I'm trying to make an analogue of a book, this is how the model looks like: Book -> Subsection -> Paragraph
models.py
# Раздел книги: Механика, Молекулярная, Электричество...
class Book(models.Model):
book_title = models.CharField(max_length=64, blank=True, null=True)
book_text = models.TextField()
def __str__(self):
return self.book_title
# Подраздел книги: Кинематика, Динамика, Статика...
class Section(models.Model):
section_title = models.CharField(max_length=128, blank=True, null=True)
section_text = models.TextField()
section_book = models.ForeignKey(Book)
def __str__(self):
return self.section_title
# Параграф подраздела: Перемещение, Путь и т.д.
class Paragraph(models.Model):
paragraph_title = models.CharField(max_length=256, blank=True, null=True)
paragraph_text = models.TextField()
paragraph_date = models.DateTimeField()
paragraph_section = models.ForeignKey(Section)
def __str__(self):
return self.paragraph_title
Answer the question
In order to leave comments, you need to log in
https://docs.djangoproject.com/en/1.8/ref/contrib/...
or djbook.ru/rel1.7/ref/contrib/admin/index.html#inli...
Here is an example, there is an operation model, and the operation date model clings to it, in the admin panel it looks like this:
class OperationDateInline(admin.TabularInline):
model = OperationDate
@admin.register(Operation)
class OperationAdmin(admin.ModelAdmin):
inlines = [OperationDateInline, ]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question