Skip to content

Instantly share code, notes, and snippets.

from django.views.generic import ListView
from django.template.defaultfilters import pluralize
from myapp.models.Product
class MyView(ListView):
queryset = Product.objects.all()
template_name = 'product.html'
$ elasticsearch
[2014-05-14 08:15:05,257][INFO ][node ] [Aminedi] version[1.1.1], pid[46224], build[f1585f0/2014-04-16T14:27:12Z]
[2014-05-14 08:15:05,258][INFO ][node ] [Aminedi] initializing ...
[2014-05-14 08:15:05,271][INFO ][plugins ] [Aminedi] loaded [], sites []
[2014-05-14 08:15:07,136][INFO ][node ] [Aminedi] initialized
[2014-05-14 08:15:07,136][INFO ][node ] [Aminedi] starting ...
[2014-05-14 08:15:07,211][INFO ][transport ] [Aminedi] bound_address {inet[/127.0.0.1:9300]}, publish_address {inet[/127.0.0.1:9300]}
[2014-05-14 08:15:10,262][INFO ][cluster.service ] [Aminedi] new_master [Aminedi][X4diAes4TrOMTk4eAdbhnA][mbp.home][inet[/127.0.0.1:9300]], reason: zen-disco-join (elected_as_master)
[2014-05-14 08:15:10,284][INFO ][discovery ] [Aminedi] elasticsearch/X4diAes4TrOMTk4eAdbhnA
[2014-05-14 08:15:10,298][INFO ][http ] [Aminedi] bound_address
pip install django-haystack
pip install pyelasticsearch
# add to installed apps
INSTALLED_APPS = (
...
'haystack',
...
)
# haystack search using elasticsearch
HAYSTACK_CONNECTIONS = {
'default': {
# /opt/elasticsearch-1.1.x/config/elasticsearch.yml
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
cluster.name: elasticsearch
network.host: 127.0.0.1
http.port: 9200
# elasticsearch
export ES_HOME=/opt/elasticsearch-1.1.x
PATH=$ES_HOME/bin:$PATH
tail -f /opt/local/var/db/mysql56/out.log
mysql> SHOW VARIABLES LIKE "general_log%";
+------------------+-----------------------------------+
| Variable_name | Value |
+------------------+-----------------------------------+
| general_log | OFF |
| general_log_file | /opt/local/var/db/mysql56/out.log |
+------------------+-----------------------------------+
2 rows in set (0.00 sec)
mysql> SET GLOBAL general_log = 'ON';
from django import template
register = template.Library()
# truncate chars but leaving last word complete
@register.filter(name='smarttruncatechars')
def smart_truncate_chars(value, max_length):
if len(value) > max_length: