我是姜戈和干草堆的新手。我遵循了haystack网站提供的示例教程,并知道如何执行基本搜索,我能够获得输出值,但页面显示不正确。Haystack默认表单是searchForm,但在我的示例中,默认形式是ModelSearchForm。我不知道为什么,也不知道怎么改变。
这是我的search.html页面中的表单。
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td> </td>
<td>
<input type="submit" value="Search" class="btn btn-default">
</td>
</tr>
</table>
</form>在我的搜索页面中,haystack总是显示一个默认的表单。它有预定义的标签,它总是向我展示带有复选框的模型名,我无法从它显示这些值的位置以及如何修改这些值中找出。
我的search_index.py文件
import datetime
from haystack import indexes
from signups.models import SignUp
class SignUpIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
first_name = indexes.CharField(model_attr='first_name')
last_name = indexes.CharField(model_attr='last_name')
email = indexes.CharField(model_attr='email')
def get_model(self):
return SignUp
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()我的model.py文件
from django.db import models
from django.utils.encoding import smart_unicode
class SignUp(models.Model):
first_name = models.CharField(max_length = 120,null = True, blank= True)
last_name = models.CharField(max_length = 120,null = True, blank= True)
email = models.EmailField()
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
update = models.DateTimeField(auto_now_add = False, auto_now = True)
def __unicode__(self):
return smart_unicode(self.email)我希望增加一个形象,以更有效地沟通,但无法做到,因为声誉较少。:(
发布于 2014-08-29 15:15:01
您可以在urls.py中更改表单类和视图类。类似于:
from haystack.views import SearchView, search_view_factory
from haystack.forms import HighlightedModelSearchForm
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mamotwo.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^search/', include('haystack.urls')),
url(r'^mysearch/$', search_view_factory(view_class=SearchView, form_class=HighlightedModelSearchForm), name='mysearch'),
url(r'^admin/', include(admin.site.urls)),
)https://stackoverflow.com/questions/24536903
复制相似问题