This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
# django-favit

A simple reusable app for django that makes it easy to deal with faving
and unfaving any object from any application.

## Installation

* Install django-favit in your vilrtual env:

```
pip install django-favit
```

* Add the app to your settings.py

```python
INSTALLED_APPS = [
...
"favit",
...
]
```

* Add favit urls to your project's `urls.py` file:

```python
urlpatterns = patterns('',
...
(r'^favit/', include('favit.urls')),
...
)
```

* Sync your database:

```
python manage.py syncdb
```

* Make sure you have jQuery ajax CSRF configuration right

See https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax

## Usage:


### Template tags:

* Get the favorited objects for a given user:

```python
{% with user_favorites <user> "app_label.model" as favorite_list %}
{% for fav_obj in favorite_list %}
{# do something with fav_obj #}
{% endfor %}
{% endwith %}
```


* Given an object `obj` you may show it fav count like this:

```python
<p>Favorite Count {{ obj|favorites_count }}</p>
```


* Get Favorite instance for an object (obj) and a user (user)

```python
{% with obj|get_favorite_for:user as fav_object %}
...
{% endwith %}
```

* Favorite Button for an object `my_obj`:

```python
{% favorite_button my_obj %}
```


### Favorites Manager

* Create a Favorite instance for a user and object:

```python
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.create(user, song)
```

or:

```python
>>> fav = Favorite.objects.create(user, 1, Song)
```

or:

```python
>>> fav = Favorite.objects.create(user, 1, "music.Song")
```

* Get the objects favorited by a given user:

```python
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(username='jdoe')
>>> Favorite.objects.for_user(user)
>>> [<favorite: favorite="" object="" 1="">, <favorite: favorite="" object="" 2="">, <favorite: favorite="" object="" 3="">]
```

* Now, get user favorited objects belonging to a given model:

```python
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> Favorite.objects.for_user(user, model=Song)
>>> [<favorite: favorite="" object="" 1="">, <favorite: favorite="" object="" 2="">, <favorite: favorite="" object="" 3="">]
```

* Get the favorited object instances of a given model favorited by any user:

```python
>>> from music.models import Song
>>> Favorite.objects.for_model(Song)
>>> [<favorite: favorite="" object="" 1="">, <favorite: favorite="" object="" 2="">, <favorite: favorite="" object="" 3="">]
```

* Get a Favorite instance for a given object and user:

```python
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.get_favorite(user, song)
```

* Get all Favorite instances for a given object

```python
>>> from music.models import Song
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.for_object(song)
```
Release History

Release History

0.2.5

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_favs_sc-0.2.5-py2-none-any.whl (10.5 kB) Copy SHA256 Checksum SHA256 py2 Wheel Mar 13, 2015
django-favs-sc-0.2.5.tar.gz (7.6 kB) Copy SHA256 Checksum SHA256 Source Mar 13, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting