Django oscar – customizing StockRecordForm form
Question:
I am trying to customize StockRecordForm
in django-oscar administration. What I have:
- Forked
dashboard
app, also catalogue_dashboard
- Included new
StockRecord
attribute in models.py
- 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?
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.
About that need to update the templates as well,
follow steps,
-
Create a templates directory under your project.
-
-
Create the oscar directory under the template directory then the dashboard directory then catalogue,
-
Create file name product_update.html
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.
I am trying to customize StockRecordForm
in django-oscar administration. What I have:
- Forked
dashboard
app, alsocatalogue_dashboard
- Included new
StockRecord
attribute inmodels.py
- 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?
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.
About that need to update the templates as well,
follow steps,
-
Create a templates directory under your project.
-
Create the oscar directory under the template directory then the dashboard directory then catalogue,
-
Create file name product_update.html
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.