我有这样的模特:
class Table(models.Model):
table_name = models.CharField(max_length=255, unique=True, blank=True, null=True)
class Row(models.Model):
table_title = models.BooleanField(default=False)
table = models.ManyToManyField(Table, through="TableRowRelation")
title = models.CharField(max_length=255)
class TableRowRelation(models.Model):
table = models.ForeignKey(Table)
row = models.ForeignKey('Row', related_name='row')
top_padding = models.BooleanField(default=False)
在admin中我想通过inline
块
管理:
class TableAdmin(admin.ModelAdmin):
list_display = ["table_name"]
inlines = [TableRowRelationInline]
class TableRowRelationInline(admin.TabularInline):
model = TableRowRelation
extra = 0
看起来一切正常
但是sql查询存在问题。在每个内联项的select中,每次调用sql-query。但这些查询是一样的。 如何仅在内联块中初始化此选择一次并仅进行1次sql查询?