Catalogue

This is an essential Oscar app which exposes functionality to manage your product catalogue. oscar.apps.catalogue.abstract_models.AbstractProduct is it’s main model. The catalogue app also includes views specific to viewing a list or individual products.

Abstract models

class oscar.apps.catalogue.abstract_models.AbstractAttributeEntity(*args, **kwargs)[source]

Provides an attribute type to enable relationships with other models

class oscar.apps.catalogue.abstract_models.AbstractAttributeEntityType(*args, **kwargs)[source]

Provides the name of the model involved in an entity relationship

class oscar.apps.catalogue.abstract_models.AbstractAttributeOption(*args, **kwargs)[source]

Provides an option within an option group for an attribute type Examples: In a Language group, English, Greek, French

class oscar.apps.catalogue.abstract_models.AbstractAttributeOptionGroup(*args, **kwargs)[source]

Defines a group of options that collectively may be used as an attribute type

For example, Language

class oscar.apps.catalogue.abstract_models.AbstractCategory(*args, **kwargs)[source]

A product category. Merely used for navigational purposes; has no effects on business logic.

Uses django-treebeard.

move(target, pos=None)[source]

Moves the current node and all its descendants to a new position relative to another node.

See https://tabo.pe/projects/django-treebeard/docs/1.61/api.html#treebeard.models.Node.move # noqa

update_slug(commit=True)[source]

Updates the instance’s slug. Use update_children_slugs for updating the rest of the tree.

class oscar.apps.catalogue.abstract_models.AbstractOption(*args, **kwargs)[source]

An option that can be selected for a particular item when the product is added to the basket.

For example, a list ID for an SMS message send, or a personalised message to print on a T-shirt.

This is not the same as an ‘attribute’ as options do not have a fixed value for a particular item. Instead, option need to be specified by a customer when they add the item to their basket.

class oscar.apps.catalogue.abstract_models.AbstractProduct(*args, **kwargs)[source]

The base product object

If an item has no parent, then it is the “canonical” or abstract version of a product which essentially represents a set of products. If a product has a parent then it is a specific version of a catalogue.

For example, a canonical product would have a title like “Green fleece” while its children would be “Green fleece - size L”.

attribute_summary[source]

Return a string of all of a product’s attributes

calculate_rating()[source]

Calculate rating value

get_absolute_url(*args, **kwargs)[source]

Return a product’s absolute url

get_missing_image()[source]

Returns a missing image object.

get_product_class()[source]

Return a product’s item class

get_title()[source]

Return a product’s title or it’s parent’s title if it has no title

has_stockrecord[source]

Test if this product has a stock record

has_stockrecords[source]

Test if this product has any stockrecords

is_available_to_buy[source]

Test whether this product is available to be purchased

is_discountable = None

Determines if a product may be used in an offer. It is illegal to discount some types of product (e.g. ebooks) and this field helps merchants from avoiding discounting such products

is_purchase_permitted(user, quantity)[source]

Test whether this product can be bought by the passed user.

is_review_permitted(user)[source]

Determines whether a user may add a review on this product.

Default implementation respects OSCAR_ALLOW_ANON_REVIEWS and only allows leaving one review per user and product.

Override this if you want to alter the default behaviour; e.g. enforce that a user purchased the product to be allowed to leave a review.

is_top_level[source]

Test if this product is a parent (who may or may not have children)

is_variant[source]

Return True if a product is not a top level product

min_variant_price_excl_tax[source]

Return minimum variant price excluding tax

min_variant_price_incl_tax[source]

Return minimum variant price including tax

primary_image()[source]

Returns the primary image for a product. Usually used when one can only display one product image, e.g. in a list of products.

product_class

“Type” of product. None for Product variants, they inherit their parent’s product class

stockrecord[source]

Return the stockrecord associated with this product. For backwards compatibility, this defaults to choosing the first stockrecord found.

update_rating()[source]

Recalculate rating field

class oscar.apps.catalogue.abstract_models.AbstractProductAttribute(*args, **kwargs)[source]

Defines an attribute for a product class. (For example, number_of_pages for a ‘book’ class)

is_value_valid(value)[source]

Check whether the passed value is valid for this attribute

class oscar.apps.catalogue.abstract_models.AbstractProductAttributeValue(*args, **kwargs)[source]

The “through” model for the m2m relationship between catalogue.Product and catalogue.ProductAttribute. This specifies the value of the attribute for a particular product

For example: number_of_pages = 295

summary()[source]

Gets a string representation of both the attribute and it’s value, used e.g in product summaries.

value_as_html[source]

Returns a HTML representation of the attribute’s value. To customise e.g. image attribute values, declare a _image_as_html property and return e.g. an <img> tag. Defaults to the _as_text representation.

value_as_text[source]

Returns a string representation of the attribute’s value. To customise e.g. image attribute values, declare a _image_as_text property and return something appropriate.

class oscar.apps.catalogue.abstract_models.AbstractProductCategory(*args, **kwargs)[source]

Joining model between products and categories. Exists to allow customising.

class oscar.apps.catalogue.abstract_models.AbstractProductClass(*args, **kwargs)[source]

Used for defining options and attributes for a subset of products. E.g. Books, DVDs and Toys. A product can only belong to one product class.

At least one product class must be created when setting up a new Oscar deployment.

Not necessarily equivalent to top-level categories but usually will be.

options

These are the options (set by the user when they add to basket) for this item class. For instance, a product class of “SMS message” would always require a message to be specified before it could be bought.

requires_shipping = None

Some product type don’t require shipping (eg digital products) - we use this field to take some shortcuts in the checkout.

track_stock = None

Digital products generally don’t require their stock levels to be tracked.

class oscar.apps.catalogue.abstract_models.AbstractProductImage(*args, **kwargs)[source]

An image of a product

display_order = None

Use display_order to determine which is the “primary” image

is_primary()[source]

Return bool if image display order is 0

class oscar.apps.catalogue.abstract_models.MissingProductImage(name=None)[source]

Mimics a Django file field by having a name property.

sorl-thumbnail requires all it’s images to be in MEDIA_ROOT. This class tries symlinking the default “missing image” image in STATIC_ROOT into MEDIA_ROOT for convenience, as that is necessary every time an Oscar project is setup. This avoids the less helpful NotFound IOError that would be raised when sorl-thumbnail tries to access it.

class oscar.apps.catalogue.abstract_models.ProductAttributesContainer(product)[source]

Stolen liberally from django-eav, but simplified to be product-specific

To set attributes on a product, use the attr attribute:

product.attr.weight = 125
class oscar.apps.catalogue.abstract_models.ProductRecommendation(*args, **kwargs)[source]

‘Through’ model for product recommendations

Views

class oscar.apps.catalogue.views.ProductCategoryView(**kwargs)[source]

Browse products in a given category

get_categories()[source]

Return a list of the current category and it’s ancestors

get_summary()[source]

Summary to be shown in template

oscar.apps.catalogue.views.get_product_base_queryset()[source]

Deprecated. Kept only for backwards compatibility. Product.browsable.base_queryset() should be used instead.