Мне действительно нужна помощь, чтобы понять, почему администратор django вызывает проблемы с производительностью?таблица visvists
имеет около 1 строки, и мне нужно объединить около 8 различных классов моделей (с внешним ключом), чтобы получить полный набор данных посещений.Я много искал / читал об оптимизации администрирования Django, и я также получил некоторую идею, но не смог реализовать ее в существующем проекте.ниже приведен снимок моего файла admin.py и models.py.
admin.py
class VisVisitsAdmin(admin.ModelAdmin):
list_display = ('visit_id','program_name','state_name','district_name','block_name','school_name')
fieldsets = [
['General information', {
'fields': ['school_program','visit_id','user']
}],
['Optional Field', {
'classes': ['collapse'],
'fields': [('visit_no', 'is_valid','ac_year')],
}],
]
def block_name(self, obj):
if obj.school_program:
# return obj.village.cluster.block.block_name
return obj.school_program.school.cluster.block.block_name
block_name.short_description = 'block name'
def district_name(self, obj):
if obj.school_program:
# return obj.village.cluster.block.district.district_name
return obj.school_program.school.cluster.block.district.district_name
district_name.short_description = 'district name'
def state_name(self, obj):
if obj.school_program:
# return obj.village.cluster.block.district.state.name_of_state
return obj.school_program.school.cluster.block.district.state.name_of_state
state_name.short_description = 'state name'
def program_name(self,obj):
if obj.school_program:
return obj.school_program.program.program_name
def school_name(self,obj):
if obj.school_program:
return obj.school_program.school.school_name
admin.site.register(VisVisits,VisVisitsAdmin)
model.py
class VisVisits(models.Model):
visit_id = models.IntegerField(primary_key=True)
visit_no = models.IntegerField(blank=True, null=True)
school_program = models.ForeignKey(SchProgramForSchools, models.DO_NOTHING, blank=True, null=True)
user = models.ForeignKey(UsrUsers, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = False
db_table = 'vis_visits'
def __str__(self):
return str(self.visit_id)
class SchPrograms(models.Model):
program_id = models.IntegerField(primary_key=True)
program_name = models.CharField(max_length=200, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_programs'
def __str__(self):
return self.program_name
class SchPartneredStates(models.Model):
state_id = models.IntegerField(primary_key=True)
name_of_state = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_partnered_states'
def __str__(self):
return str(self.name_of_state)
class SchDistricts(models.Model):
district_id = models.IntegerField(primary_key=True)
state = models.ForeignKey(SchPartneredStates, models.DO_NOTHING, blank=True, null=True)
district_name = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_districts'
def __str__(self):
return str(self.district_name)
class SchBlocks(models.Model):
block_id = models.IntegerField(primary_key=True)
district = models.ForeignKey(SchDistricts, models.DO_NOTHING, blank=True, null=True)
block_name = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_blocks'
def __str__(self):
return str(self.block_name)
class SchClusters(models.Model):
cluster_id = models.IntegerField(primary_key=True)
block = models.ForeignKey(SchBlocks, models.DO_NOTHING, blank=True, null=True)
cluster_name = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_clusters'
def __str__(self):
return str(self.cluster_name)
class SchVillages(models.Model):
village_id = models.IntegerField(primary_key=True)
cluster = models.ForeignKey(SchClusters, models.DO_NOTHING, blank=True, null=True)
village_name = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_villages'
def __str__(self):
return str(self.village_name)
class SchSchools(models.Model):
school_id = models.IntegerField(primary_key=True)
school_name = models.CharField(max_length=500, blank=True, null=True)
cluster = models.ForeignKey(SchClusters, models.DO_NOTHING, blank=True, null=True)
village = models.ForeignKey(SchVillages, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_schools'
def __str__(self):
return str(self.school_name)
class SchProgramForStates(models.Model):
pfst_id = models.IntegerField(primary_key=True)
program = models.ForeignKey(SchPrograms, models.DO_NOTHING, blank=True, null=True)
state = models.ForeignKey(SchPartneredStates, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = False
db_table = 'sch_program_for_states'