1. How to extend django SHOP models — django SHOP 0.1.1.dev0 documentation

### Navigation

- index
- modules |
- next |
- previous |
- django SHOP 0.1.1.dev0 documentation »

# 1. How to extend django SHOP models

(Instead of the default ones)

Some people might feel like the django SHOP models are not suitable for their project, or want to extend functionality for their specific needs.

This is a rather advanced use case, and most developers should hopefully be happy with the default models. It is however relatively easy to do.

All models you can override have a corresponding setting, which should contain the class path to the model you wish to use in its stead.

Note

While your models will be used, they will still be “called” by their default django SHOP name.

## 1.1. Example

Extending the Product model in django SHOP works like this:

    # In myproject.models
    from shop.models_bases import BaseProduct
    class MyProduct(BaseProduct):
        def extra_method(self):
            return 'Yay'

        class Meta:
            pass

    # In your project's settings.py, add the following line:
    SHOP_PRODUCT_MODEL = 'myproject.models.MyProduct'

Important

Your model replacement must define a `Meta` class. Otherwise, it will inherit its parent’s `Meta`, which will break things. The `Meta` class does not need to do anything important - it just has to be there.

From a django interactive shell, you should now be able to do:

    >>> from shop.models import Product
    >>> p = Product.objects.all()[0] # I assume there is already at least one
    >>> p.extra_method()
    Yay
    >>> p.__class__
    <class object's class>

## 1.2. Settings

All available settings to control model overrides are defined in General Settings

### Navigation

- index
- modules |
- next |
- previous |
- django SHOP 0.1.1.dev0 documentation »