我正在尝试在表单中的foreignkey字段上实现自动完成搜索。我已经浏览过文档,但不确定我需要做些什么才能让它正常工作。我只是在foreignkey字段上获得了正常的下拉框。
这是我的尝试:
settings.py
INSTALLED_APPS = (
'crispy_forms',
'autocomplete_light',
)
urls.py
url(r'^autocomplete/', include('autocomplete_light.urls')),
models.py
class Client(models.Model):
...
class Branch(models.Model):
client = models.ForeignKey(Client, related_name='clients')
...
forms.py
import autocomplete_light
class BranchForm(autocomplete_light.ModelForm):
class Meta:
model = Branch
autocomplete_fields = ('client')
exclude = ('creation', 'last_modified')
form.html
<form method="POST" action="">{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit" />
<a href="{% url 'branch' %}"><button type="button" class="btn btn-danger">Cancel</button></a>
</form>
答案 0 :(得分:0)
最终计算出来。需要注册。
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"view will appear called");
}