我的模型是Client,ClientSubUser
Client(models.Modal):
name = ...
address = ...
user = models.ForeignKey(User)
ClientSubUser(models.Model):
client = models.ForeignKey(Client)
user = models.ForeignKey(User)
管理:
class ClientSubUserInline( admin.StackedInline ):
model = ClientSubUser
extra = 0
class ClientAdmin( admin.ModelAdmin ):
form = ClientAdminForm
search_fields = ('name',)
list_display = ('name','adress')
inlines = (ClientSubUserInline,)
class Media:
css = {
'all': ("select2/select2.css",),
} jQuery("#id_user").select2({'placeholder': "Select a Locality"});
js = ("select2/select2.js, client_admin_utils.js")
现在如果我必须让客户端用户作为搜索和选择, 然后我只需在client_admin_utils中的java脚本中选择字段,
jQuery(“#id_user”)。select2({'placeholder':“Select a Locality”});
它变成了搜索n选择, 但问题出现在内联中,导致内联填充只有当我们点击“添加另一个”链接时,即通过django admin jquery本身,
我想要同样的搜索并选择内联添加为client_subuser需要覆盖它的小部件在准备好的js