0👍
✅
Try to select the related fields from get_queryset
:
class AlignedScan_Inline(admin.TabularInline):
...
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).select_related('scan', 'alignment')
1👍
Try adding the scan
field to raw_id_fields
.
class AlignedScan_Inline(admin.TabularInline):
raw_id_fields = ['scan']
...
This is useful because ModelForms do some inefficient things out of the box in regards to relationship fields. This obviously has been exacerbated by having many inlines on the admin. By removing the relationship field from the rendering process, you eliminate that inefficiency.
1👍
Additional answer:
This also fixed the problem:
class AlignedScan_Manager(models.Manager):
def get_queryset(self):
return super().get_queryset().select_related('scan', 'alignment')
In my initial attempt I had only pre-selected ‘scan’, not both ‘scan’ and ‘alignment’.
If I use this manager for my AlignedScan model, I can remove the get_queryset() override from AlignedScan_Inline
Source:stackexchange.com