How to customize Django Oscar Models, Views and URL's

Reading Time : ~ .

In order to customize models, views and urls, you need to fork an Oscar core app in which model/view resides. Then you should be able to override any model/view classes.

Steps to fork/customize an app:

    1. If you are forking an Oscar app for the first time, then you have to create a root apps-folder in which all your forked apps will exists:

$ mkdir yourappsfolder
$ touch yourappsfolder/

    2. Create a python module with the same 'app-label' as the Oscar app:

        Ex: Customising oscar.apps.catalogue app

$ mkdir yourappsfolder/catalogue
$ touch yourappsfolder/catalogue/

    3. If the Oscar app has a, then you have to create a file in your local app.

# your custom models go here
from oscar.apps.catalogue.models import *

        NOTE: To customise Oscar’s models, you must add your custom one before importing Oscar’s models. Then, your models file will have two models with the same name within an app, Django will only use the first one.

        Ex: To add a active field to the product model:

# yourappsfolder/catalogue/

from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractProduct

class Product(AbstractProduct):
    active = models.BooleanField(default=False)

from oscar.apps.catalogue.models import *

    4. Create an '' file in your local app.

# yourappsfolder/catalogue/
from oscar.apps.catalogue.admin import *

    5. Then copy the 'migrations' directory from oscar/apps/catalogue and put it into your new local catalogue app.

    6. Added it as Django app by replacing Oscar’s app with your own in INSTALLED_APPS.


from oscar import get_core_apps
    # all your non-Oscar apps
] + get_core_apps(['yourappsfolder.catalogue'])

        NOTE: get_core_apps([]) will return a list of Oscar core apps or else if you give a list of your custom apps, they will replace the Oscar core apps.

    7. Finally, create migrations using 'makemigrations' management command and apply the migrations by using 'migrate catalogue' management command. Then, you can see that a new column is been added to the product model.

Steps for customizing URL's:

    1. Follow the same above steps described in customizing an app.

    2. In Oscar, each app will have its own URLs in the '' file and each app comes with an application instance with 'urls' property, which used to access the list of URL's of an app.

        * Modify 'yourproject/' file to include Oscar URL's.

from django.conf.urls import include, url
from import application

urlpatterns = [
   # Your other URLs
   url(r'', include(application.urls)),

    3. To change the URL for the basket app from 'basket' to 'cart', you need to customize root app instance by creating a sub-class of it and overriding the 'get_urls' method.

# yourproject/

from oscar import app

class Shop(app.Shop):
    def get_urls(self):
        urlpatterns = [
            url(r'^cart/', include(self.basket_app.urls)),
            # ...
            # Remianing urls here
        return urlpatterns

application = Shop()

Steps for customizing or adding views to an app:

    1. Follow the same above steps described in customizing an app.

    2. Create a new view class or create a sub-class of Oscar's view in file:

        Ex: Add extra context to the home page.

from oscar.apps.promotions.views import HomeView as CoreHomeView

class HomeView(CoreHomeView):
    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)

        context["latest_products"] = Product.objects.filter(

        return context
    By Posted On

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Django webpacker - A compression tool to bundles css, js files Nikhila Mergu

django-webpacker is a django compressor tool which bundles css, js files to a single css, js file with webpack and updates your html files with ...

Continue Reading...
Django - migrating from function based views to class based views Anjaneyulu Batta

The single most significant advantage in Django class-based views is inheritance. On a large project it's likely that we will have lots of similar views. ...

Continue Reading...
Introduction to Django's Class based views - Understanding how a class based view works Ashwin Kumar

Django has MVT architecture. A view in django is just a callable that takes a request and returns a response. But this can be more ...

Continue Reading...

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties