Django is slow with large base

Dear All,

When I put this modal form in my code (cf. template.html), it make django soooo slowly
This kind of modal form works fine with small base but not with a large base my ‘People_Main’ database is around 30 000 object.
class Peoples_Affaires_Clients(models.Model):
   affaire = models.ForeignKey(Affaires_Main, on_delete=models.SET_NULL, null=True)
   people = models.ForeignKey(Peoples_Main, on_delete=models.SET_NULL, null=True)
   Affaires_Clients_FormSet	= inlineformset_factory(Affaires_Main, Peoples_Affaires_Clients, can_delete=True, fields=('people', ))
   my_affaire_clients_formset_form = Affaires_Clients_FormSet(instance=my_affaire_main)

<!-- Modal Infos -->
<form method="POST" enctype="multipart/form-data">
	{% csrf_token %}
	{{ my_affaire_clients_formset_form.management_form }}

	<div class="modal fade" id="ModalClients" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-info modal-xl" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title">Modifications - Clients</h4>
				<div class="modal-body">
					<table class="table table-hover table-borderless table-sm" id="table">
							{% for uform in my_affaire_clients_formset_form %}
								{{ }}
										<div class="form-group input-group">
											{% render_field uform.people class="form-control" placeholder="[-- people --]" %}
							{% endfor %}
				<div class="modal-footer">
					<button class="btn btn-light" type="button" data-dismiss="modal">Close</button>
					<button class="btn btn-secondary" name="btn_affaire_clients" type="submit">Save</button>

If you have an idea :wink:
Thanks a lot


30k objects in a drop-down are going to be really slow. I would consider adding the ability to search for a list of people first to narrow it down. Even if you can filter down by the first letter or two, it might make it a bit more manageable.

Thanks Jeff for your help.
That what I espected …

So, what is this tips to associate to an object another one from a big list ?
Are you using jQuery for this ? But in jQuery you nedd to give the full list …

If any idea I take it …


Look at tools like select2. They work by allowing the user to type in part of the requested items, and passes that search term to the server for the server to provide a filtered list. (Using this in django requires a custom view to perform that filtering. See django-select2.)

1 Like