Objects defined here are only used if you store bookmarks using default Django model backend.
A user’s bookmark for a content object.
This is only used if the current backend stores bookmarks in the database using Django models.
the bookmarked instance content type
the bookmarked instance id
the bookmarked instance
the bookmark key
the user who bookmarked the instance (as a fk to django.contrib.auth.models.User)
the bookmark creation datetime
the manager used is bookmarks.managers.BookmarksManager (see below)
In bulk selections¶
annotate_bookmarks(queryset_or_model, key, user, attr='is_bookmarked')¶
Annotate queryset_or_model with bookmarks, in order to retreive from the database all bookmark values in bulk.
The first argument queryset_or_model must be, of course, a queryset or a Django model object. The argument key is the bookmark key.
The bookmarks are filtered using given user.
A boolean is inserted in an attr named attr (default=’is_bookmarked’) of each object in the generated queryset.
for article in annotate_bookmarks(Article.objects.all(), 'favourite', myuser, attr='has_a_bookmark'): if article.has_a_bookmark: print u"User %s likes article %s" (myuser, article)
Mixin for bookmarkable models.
Models subclassing this abstract model gain a bookmarks attribute allowing accessto the reverse generic relation to the bookmarks.models.Bookmark.
Manager used by Bookmark model.
get_for(self, content_object, key, **kwargs)¶
Return the instance related to content_object and matching kwargs. Return None if a bookmark is not found.
filter_for(self, content_object_or_model, **kwargs)¶
Return all the instances related to content_object_or_model and matching kwargs. The argument content_object_or_model can be both a model instance or a model class.
Return all instances retreiving content objects in bulk in order to minimize db queries, e.g. to get all objects bookmarked by a user:
for bookmark in Bookmark.objects.filter_with_contents(user=myuser): bookmark.content_object # this does not hit the db
add(self, user, content_object, key)¶
Add a bookmark, given the user, the model instance and the key.
Raise a Bookmark.AlreadyExists exception if that kind of bookmark is present in the db.
remove(self, user, content_object, key)¶
Remove a bookmark, given the user, the model instance and the key.
Raise a Bookmark.DoesNotExist exception if that kind of bookmark is not present in the db.
Remove all bookmarks for the given model instance.
The application uses this whenever a bookmarkable model instance is deleted, in order to mantain the integrity of the bookmarks table.