[英]How can i do pagination for M2M Django
class Movie(models.Model):
title= models.CharField(max_length=100,)
votes=models.IntegerField(null=True)
year=models.IntegerField(null=True)
aspect_ration=models.CharField(max_length=50,)
mpaa=models.CharField(max_length=200,)
rating =models.CharField(max_length=20,)
imdbid=models.CharField(max_length=50,)
top_250_rank=models.IntegerField(null=True)
cover_url=models.CharField(max_length=500,)
plot_outline=models.TextField(blank=True, null=True)
summary= models.TextField(blank=True, null=True)
pub_date = models.DateTimeField(null=True, blank=True,default=datetime.today())
akas_id = models.ManyToManyField('Akas', verbose_name=u'Akas ID',related_name="Akas_M2M_Movie")
class Akas(models.Model):
name=models.CharField(max_length=500,)
def __unicode__(self):
return u'%s' % (self.name)
class Meta:
verbose_name = 'Other Movie Title'
verbose_name_plural = 'Other Movie Titles'
db_table = 'Akas'
In the 'Akas' table i have 2225188 record So The Change view takes long time to load this field. 在“ Akas”表中,我有2225188条记录,因此“更改”视图需要很长时间才能加载此字段。 What is the solution to resolve this issue ? 解决此问题的解决方案是什么? Can i do pagination for the m2m widget ? 我可以对M2m小部件进行分页吗?
Can any one help for this issue ? 有人可以帮忙解决此问题吗? In admin.py i am using filter_horizontal = ['Akas',] 在admin.py中,我正在使用filter_horizontal = ['Akas',]
It's much better to use a custom widget than the default widget for Many-to-many fields or even Foreign Key fields in this case. 在这种情况下,使用自定义窗口小部件要比用于多对多字段甚至外键字段的默认窗口小部件好得多。 Since you have a huge number of Akas
instances, the HTML page itself becomes very large and hence takes time to load. 由于您有大量的Akas
实例,因此HTML页面本身变得非常大,因此加载时间很长。
You can create a custom widget on your own, with pagination. 您可以通过分页自行创建自定义窗口小部件。 Although my suggestion is that you use an auto-complete widget. 尽管我的建议是您使用自动完成的小部件。 You can look for existing django packages here and use the one which suits your needs. 您可以在此处查找现有的django软件包,然后使用适合您需求的软件包。 The basic idea here would be to use ajax requests to dynamically get data from server instead of loading everything at once. 这里的基本思想是使用ajax请求从服务器动态获取数据,而不是立即加载所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.