Package expedient :: Package common :: Package utils :: Module managers :: Class GenericObjectManager
[hide private]
[frames] | no frames]

Class GenericObjectManager

source code


Adds methods to retrieve generic objects when the model uses the contenttypes framework.

Instance Methods [hide private]
 
__init__(self, ct_field='content_type', fk_field='object_id')
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
get_or_create_from_instance(self, instance, **kwargs)
Similar to the get_or_create method, but accepts an instance object to be used for the generic foreign key relation.
source code
 
filter_from_instance(self, instance)
Get the generic objects pointing to the instance.
source code
 
filter_from_queryset(self, queryset)
Get a filtered queryset that contains all the objects for all instances in queryset.
source code
 
filter_for_class(self, klass, **kwargs)
Convenience function to filter for generic objects related to a particular class.
source code
 
get_objects_queryset(self, klass, generic_filter_args, object_filter_args)
Convenience function to filter both the generic objects and the objects they point to, and return a queryset for the class klass.
source code
 
filter_for_objects(self, klass, **object_filter_args)
Filter the generic objects to return the queryset that contains objects of class klass filtered by the rest of the keywords.
source code

Inherited from django.db.models.manager.Manager: aggregate, all, annotate, complex_filter, contribute_to_class, count, create, dates, db_manager, defer, distinct, exclude, exists, extra, filter, get, get_empty_query_set, get_or_create, get_query_set, in_bulk, iterator, latest, none, only, order_by, raw, reverse, select_related, update, using, values, values_list

Inherited from django.db.models.manager.Manager (private): _copy_to_model, _insert, _set_creation_counter, _update

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  use_for_related_fields = True

Inherited from django.db.models.manager.Manager: creation_counter

Properties [hide private]

Inherited from django.db.models.manager.Manager: db

Inherited from object: __class__

Method Details [hide private]

__init__(self, ct_field='content_type', fk_field='object_id')
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • ct_field - name of the ForeignKey field pointing to ContentType. Default is "content_type".
  • fk_field - name of the ID field for objects. Default is object_id.
Overrides: object.__init__
(inherited documentation)

filter_from_instance(self, instance)

source code 

Get the generic objects pointing to the instance.

Parameters:
  • instance - instance to retrieve the object for.
Returns:
QuerySet containing all generic object.

filter_from_queryset(self, queryset)

source code 

Get a filtered queryset that contains all the objects for all instances in queryset. This will only return a query set of the objects found. Some may not exist.

Parameters:
  • queryset - QuerySet of objects whose generic counterparts we wish to find.
Returns:
QuerySet that contains the generic objects.

filter_for_class(self, klass, **kwargs)

source code 

Convenience function to filter for generic objects related to a particular class. Accepts same arguments as the normal filter() method.

Parameters:
  • klass - Class to filter by.