Generate recommendations in Django.
Project description
Use pyrecommend in Django projects.
Warning: not yet suitable for production.
django_recommend/ is the actual Django app intended for use in projects.
simplerec/ is a Django project used for testing.
Important note: Model classes/database schemas are only supported if they have unique integer primary keys.
Quickstart
Add django_recommend to your INSTALLED_APPS, and run python manage.py migrate.
Set SESSION_SAVE_EVERY_REQUEST=True in your settings, to ensure anonymous users can be tracked.
In your views, call django_recommend.set_score(request, object, score) to start recording user scores. (Currently this is assumed to be implicit feedback.) Note: This will use session keys to store scores for users who aren’t authenticated.
In your templates, use {% load django_recommend %} and {{ obj|similar_objects }} to show similar objects to visitors. This filter returns a list, so you may also do, for example:
{% load django_recommend %} {% with similar_products as product|similar_objects %} {% if similiar_products %} <h2>Other users also liked:</h2> <ul> {% for product in similar_products %} <li><a href=
"{{ product.get_absolute_url }}">{{ product }}</a></li> {% endfor %} </ul> {% endif %} {% endwith %}
Notes
There can be some potentially confusing behavior from this library if your application involves objects that get deleted/deactivated. Currently I am not sure how feasible it is to filter by a flag like ‘deactivated’; tests for that kind of functionality will be put into a future version.
If your data is ever deleted, by default, django_recommend will attempt to delete all recommendation information about it at the next available chance. This most notably can occur in ObjectSimilarityQueryset.get_instances_for, where you may, for example, have a queryset like:
suggested_books = similar_books.order_by( '-score')[:5].get_instances_for(curr_book)
If one of the books that would be suggested for this book has since been deleted, the default behavior will be to in fact give you a list of four instances. This is because retrieving the deleted instances raises an ObjectDoesNotExist error in the Django ORM; the default behavior is to simply delete that object’s information from the recommendation data and skip the object for now.
This can be controlled by the RECOMMEND_PURGE_MISSING_DATA boolean setting. If this is False, the exception will be propagated, so you may handle it in a different way.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-recommend-0.1.dev8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5d6d0e3120befb05f56ec0968c08b7f9d3f5d268ade40b1a663d572778c5aaf |
|
MD5 | cb57fcd34330c754cfce5f16588ff8ff |
|
BLAKE2b-256 | f788f12eec6675bf1ddd1f152b70eb72f50727aebcf5472082f90c5bc2f9f1cb |
Hashes for django_recommend-0.1.dev8-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac5b922d2d73617e6f86a6ac913ccd6c5476445c29fcfad7bcf9acf1de109be |
|
MD5 | e8947eab0f551e5c69a8aa3e07b73ca0 |
|
BLAKE2b-256 | 902d2f1294f7bd75e872801d94a162a588f685fced5c2dd3f2161eda75fcbb71 |