Collections

class philo.models.collections.Collection(*args, **kwargs)

Collections are curated ordered groupings of arbitrary models.

name

CharField with max_length 255

description

Optional TextField

get_count()

Returns the number of items in the collection.

class philo.models.collections.CollectionMember(*args, **kwargs)

The collection member model represents a generic link from a Collection to an arbitrary model instance with an attached order.

objects

A CollectionMemberManager instance

collection

ForeignKey to a Collection instance.

index

The numerical index of the item within the collection (optional).

member

GenericForeignKey to an arbitrary model instance.

class philo.models.collections.CollectionMemberManager
with_model(model)

Given a model class or instance, returns a queryset of all instances of that model which have collection members in this manager’s scope.

Example:

>>> from philo.models import Collection
>>> from django.contrib.auth.models import User
>>> collection = Collection.objects.get(name="Foo")
>>> collection.members.all()
[<CollectionMember: Foo - user1>, <CollectionMember: Foo - user2>, <CollectionMember: Foo - Spam & Eggs>]
>>> collection.members.with_model(User)
[<User: user1>, <User: user2>]

Project Versions

Previous topic

Nodes and Views: Building Website structure

Next topic

Miscellaneous Models

This Page