Skip to main content

django-fav

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

It comes with a Graphene (GraphQL) Query to enable favs in your queries.

Requirements

  • Python 3.4+
  • Django 1.11

Installation

pip install django-fav
  • Add the app to your settings.py
INSTALLED_APPS = [
  ...
  "fav",
  ...
]
  • Sync your database:
python manage.py migrate

Usage:

Favorites Manager

  • Create a Favorite instance for a user and object:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='gengue')
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.create(user, song)
or:
>>> fav = Favorite.objects.create(user, 1, Song)
or:
>>> fav = Favorite.objects.create(user, 1, "music.Song")
  • Get the objects favorited by a given user:
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(username='gengue')
>>> 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:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='gengue')
>>> 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:
>>> 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:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='gengue')
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.get_favorite(user, song)
  • Get all Favorite instances for a given object
>>> from music.models import Song
>>> song = Song.objects.get(pk=1)
>>> fav = Favorite.objects.for_object(song)

Thanks

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fav-0.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file django-fav-0.1.tar.gz.

File metadata

  • Download URL: django-fav-0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-fav-0.1.tar.gz
Algorithm Hash digest
SHA256 2c28773d6c506d4989ad1d5623e54254f0c3b8bafde0a8e7386e8a0c5f6e467c
MD5 326bb0f33fe9acf309bb180793e1d8cc
BLAKE2b-256 d5a0faffa3663af07fcb4ea1e46519dc7e49bc5cc637ff6825fb2af7db6c4cf7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page