categories.base.CategoryBase

CategoryBase#

class categories.base.CategoryBase(*args, **kwargs)[source]#

This base model includes the absolute bare-bones fields and methods.

One could simply subclass this model, do nothing else, and it should work.

Parameters:

Relationship fields:

Parameters:

parent (TreeForeignKey to CategoryBase) – Parent

Methods

check(**kwargs)

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields.

clean_fields([exclude])

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

date_error_message(lookup_type, field_name, ...)

delete(*args, **kwargs)

Calling delete on a node will delete it as well as its full subtree, as opposed to reattaching all the subnodes to its parent node.

from_db(db, field_names, values)

full_clean([exclude, validate_unique])

Call clean_fields(), clean(), and validate_unique() on the model.

get_ancestors([ascending, include_self])

Creates a QuerySet containing the ancestors of this model instance.

get_children()

Returns a QuerySet containing the immediate children of this model instance, in tree order.

get_deferred_fields()

Return a set containing names of deferred fields for this instance.

get_descendant_count()

Returns the number of descendants this model instance has.

get_descendants([include_self])

Creates a QuerySet containing descendants of this model instance, in tree order.

get_family()

Returns a QuerySet containing the ancestors, the model itself and the descendants, in tree order.

get_leafnodes([include_self])

Creates a QuerySet containing leafnodes of this model instance, in tree order.

get_level()

Returns the level of this node (distance from root)

get_next_sibling(*filter_args, **filter_kwargs)

Returns this model instance's next sibling in the tree, or None if it doesn't have a next sibling.

get_previous_sibling(*filter_args, ...)

Returns this model instance's previous sibling in the tree, or None if it doesn't have a previous sibling.

get_root()

Returns the root node of this model instance's tree.

get_siblings([include_self])

Creates a QuerySet containing siblings of this model instance.

insert_at(target[, position, save, ...])

Convenience method for calling TreeManager.insert_node with this model instance.

is_ancestor_of(other[, include_self])

Returns True if this model is an ancestor of the given node, False otherwise.

is_child_node()

Returns True if this model instance is a child node, False otherwise.

is_descendant_of(other[, include_self])

Returns True if this model is a descendant of the given node, False otherwise.

is_leaf_node()

Returns True if this model instance is a leaf node (it has no children), False otherwise.

is_root_node()

Returns True if this model instance is a root node, False otherwise.

move_to(target[, position])

Convenience method for calling TreeManager.move_node with this model instance.

prepare_database_save(field)

refresh_from_db([using, fields])

Reload field values from the database.

save(*args, **kwargs)

Save the category.

save_base([raw, force_insert, force_update, ...])

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too.

serializable_value(field_name)

Return the value of the field name for this instance.

unique_error_message(model_class, unique_check)

validate_unique([exclude])

Check unique constraints on the model and raise ValidationError if any failed.

Attributes

active

Type: BooleanField

name

Type: CharField

objects

parent

Type: TreeForeignKey to CategoryBase

parent_id

Internal field, use parent instead.

pk

slug

Type: SlugField

tree