Base models¶
-
class
shopkit.category.basemodels.CategoryBase(*args, **kwargs)¶ Bases:
django.db.models.base.ModelAbstract base class for a category.
The in_shop property should be a
Managercontaining all the items which should be enabled in the shop’s frontend.-
classmethod
get_categories()¶ Gets all the available categories.
-
classmethod
get_main_categories()¶ Gets the main categories, which for unnested categories implies all of them. This method exists purely for uniformity reasons.
-
get_products()¶ Get all active products for the current category.
-
classmethod
-
class
shopkit.category.basemodels.NestedCategoryBase(*args, **kwargs)¶ Bases:
shopkit.category.basemodels.CategoryBaseAbstract base class for a nested category.
-
classmethod
get_main_categories()¶ Gets the main categories; the ones which have no parent.
-
get_parent_list(reversed=False)¶ Return a list of all parent categories of the current category.
By default it lists the categories from parent to child, ie.:
[<categoryt>, <subcategory>, <subsubcategory>, ...]
If the argument reversed evaluates to True, the list runs in reverse order. This saves an extra reverse operation.
Todo
Cache this. It is a slow operation which requires as many queries as the category tree is deep.
-
get_products()¶ Get all active products for the current category.
For performance reasons, and added control, this only returns only products explicitly associated to this category - as opposed to listing also products in subcategories of the current category.
This would take a lot more requests and is probably not what we should wish for.
-
get_subcategories()¶ Gets the subcategories for the current category.
-
classmethod
-
class
shopkit.category.basemodels.MPTTCategoryBase(*args, **kwargs)¶ Bases:
mptt.models.MPTTModel,shopkit.category.basemodels.NestedCategoryBase-
classmethod
get_main_categories()¶ Gets the main categories; the ones which have no parent.
-
get_products()¶ Get all active products for the current category.
As opposed to the original function in the base class, this also includes products in subcategories of the current category object.
-
get_subcategories()¶ Gets the subcategories for the current category.
-
classmethod