Answer the question
In order to leave comments, you need to log in
Why is the processing of large tables (ManyToManyField) slow in the Django admin interface?
Hello dear community. Faced with a problem, I rely on your comprehensive knowledge.
The essence of the problem:
There are the following application models for the book catalog (elcat):
1.
# Таблица с книгами
class book(models.Model):
book_id = models.BigIntegerField(primary_key=True, unique=True)
name = models.CharField(max_length=512)
...
author_id = models.ManyToManyField('author')
...
#Таблица с авторами
class author(models.Model):
author_id = models.BigIntegerField(primary_key=True)
name = models.CharField(max_length=512)
filter_horizontal = (author_id',)
Answer the question
In order to leave comments, you need to log in
When loading the detailed page of a book, all authors are requested. You can set up an admin model for a book
class AdminBook(ModelAdmin):
raw_id_fields = ('author_id', )
site.register(Book, AdminBook)
First, BigIntegerField as a PK is not the best idea in terms of optimization. Omit book_id and author_id in author. Django will substitute AutoField itself. In addition, a relation looks more logical when:
class book(models.Model):
name = models.CharField(max_length=512)
...
author = models.ManyToManyField('author')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question