Skip to content

Commit

Permalink
Implement haystack
Browse files Browse the repository at this point in the history
  • Loading branch information
pta2002 committed May 15, 2017
1 parent 9081d20 commit dd4bed7
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,54 @@ ENV/
.ropeproject

# End of https://www.gitignore.io/api/dj,django,python

# Created by https://www.gitignore.io/api/emacs

### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# End of https://www.gitignore.io/api/emacs
16 changes: 16 additions & 0 deletions shop/search_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import datetime
from haystack import indexes
from .models import *

class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
product_name = indexes.CharField(model_attr='product_name')
price = indexes.DecimalField(model_attr='price')
currency = indexes.CharField(model_attr='price_currency')


def get_model(self):
return Product

def index_queryset(self, using=None):
return self.get_model().objects.filter(approved=True)
3 changes: 3 additions & 0 deletions shop/templates/search/indexes/shop/product_text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ object.product_name }}
{{ object.product_discription }}
{{ object.seller.username }}
4 changes: 2 additions & 2 deletions shop/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pylint: disable=C0321
from django.conf.urls import url
from django.conf.urls import url, include
from . import views

app_name = 'shop'
urlpatterns = [
url(r'^$', views.homepage, name='homepage'),
url(r'^search/$', views.search, name='search'),
url(r'^search/', views.search, name='search'),
url(r'^product/(?P<id>\d*[1-9]\d*)/$', views.view_product,
name='viewproduct'),
url(
Expand Down

0 comments on commit dd4bed7

Please sign in to comment.