Django oscar – customizing StockRecordForm form

Question:

I am trying to customize StockRecordForm in django-oscar administration. What I have:

  1. Forked dashboard app, also catalogue_dashboard
  2. Included new StockRecord attribute in models.py
  3. Updated forms.py like this:
from oscar.apps.dashboard.catalogue import forms as base_forms

class StockRecordForm(base_forms.StockRecordForm):


    class Meta(base_forms.StockRecordForm.Meta):
        fields = [
            'partner', 'partner_sku',
            'price_currency', 'price',
            'num_in_stock', 'low_stock_threshold', 'new_attribute',
        ]

Part of my INSTALLED_APPS looks like this:

#'oscar.apps.dashboard.apps.DashboardConfig',
#'oscar.apps.dashboard.catalogue.apps.CatalogueDashboardConfig',
'mikeapps.dashboard.apps.DashboardConfig',
'mikeapps.dashboard.catalogue.apps.CatalogueDashboardConfig',

But modification is not showing up. Is there anything else I should modify?

Asked By: wtdmn

||

Answers:

Allright, I am surprised that in this case I have to actually modify template to show the new fields (unlike ProductForm etc.), I presumpted that all chosen attributes will be shown in forms automatically, but I was wrong.

Answered By: wtdmn

About that need to update the templates as well,

follow steps,

  1. Create a templates directory under your project.

  2. Give templates path to your setting.py
    setting.py

  3. Create the oscar directory under the template directory then the dashboard directory then catalogue,

  4. Create file name product_update.html

should look like this:
update template for stock in oscar

Then extend ‘product_update’ template from your oscar lib

{% extends 'oscar/dashboard/catalogue/product_update.html' %}
{% load form_tags %}
{% load i18n %}

then use {% block stockrecords_content %} and copy all code from it and edit it to your need.
for example your new_attribute add <th>{% trans "new_attribute" %}</th> and

<td>{% include "oscar/dashboard/partials/form_field.html" with field=stockrecord_form.new_attribute nolabel=True %}</td>

it will work fine.

Answered By: SAM
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.