0

I'm trying to change the way to load models on the admin page, especially foreign keys, because I have a delay to load them, the option for this was to exclude the field, but I want to have another option, thanks

# model.service.py
class Service(BaseModel):
    # Service data
    client = models.ForeignKey(Client, on_delete=models.CASCADE, null=True)
    Any = models.CharField()...


# service_form.py

class ServiceForm(forms.ModelForm):
    class Meta:
        model = models.Service
        exclude = ["client"]


# admin.py

class serviceAdmin(admin.ModelAdmin):
    model = models.service

admin.site.register(models.service, ServiceAdmin)

this way I exclude the field for loading, but is there a way to do it that doesn't take so long to load?

John_B
  • 41
  • 8

2 Answers2

0

You can optimization your admin page with following attributes:

class serviceAdmin(admin.ModelAdmin):
    ...
    autocomplete_fields = ('client',) 
    list_select_related = ('client',) 

more info: autocomplete_fields , list_select_related

0

"""

class AdminClass(admin.ModelAdmin): list_display = [ "id", "client" ] raw_id_fields = ('client',)

"""

With raw_id_fields, this change provides the load of admin site, take of this questions

John_B
  • 41
  • 8