Django Admin Inline如何改写queryset

转载自:https://stackoverflow.com/questions/15976683/overriding-queryset-for-inline-admin


主要针对数据库较大时网页内容塞入整个数据表导致卡顿的情况


class MyInline(admin.TabularInline):
	model = PlayerRelation
	def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
		if db_field.name == 'Player':
			kwargs['queryset'] = Player.objects.filter(device = device)
		return super(MyInline, self).formfield_for_foreignkey(db_field, request, **kwargs)

以上

你可能感兴趣的:(django)