Answer the question
In order to leave comments, you need to log in
How to add one field for product in admin panel?
Good day.
I'm developing a store on Django-Oscar and I need to enter the tax level for each product.
I first added a field tax_rate
in the product itself:
from django.utils.translation import ugettext_lazy as _
from django.db import models
from oscar.apps.partner.abstract_models import AbstractStockRecord
from django.core.validators import MinValueValidator
class StockRecord(AbstractStockRecord):
tax_rate = models.DecimalField(
_("Tax rate"), decimal_places=2, max_digits=12,
blank=True, null=True, validators=[MinValueValidator(0)])
from oscar.apps.partner.models import *
apps/dashboard/catalogue/forms.py:
class StockRecordForm(forms.ModelForm):
def __init__(self, product_class, user, *args, **kwargs):
# The user kwarg is not used by stock StockRecordForm. We pass it
# anyway in case one wishes to customise the partner queryset
self.user = user
super(StockRecordForm, self).__init__(*args, **kwargs)
# If not tracking stock, we hide the fields
if not product_class.track_stock:
del self.fields['num_in_stock']
del self.fields['low_stock_threshold']
else:
self.fields['price_excl_tax'].required = True
self.fields['num_in_stock'].required = True
self.fields['tax_rate'].required = True # добавил
class Meta:
model = StockRecord
fields = ['partner', 'partner_sku', 'price_currency', 'price_excl_tax', 'tax_rate', # добавил
'price_retail', 'cost_price', 'num_in_stock', 'low_stock_threshold',]
apps.dashboard.catalogue
, then in it (local) I created a file forms.py
in which I added (already corrected), but it still does not work.
Someone can help me? I will be very grateful for your help.
P.S. sorry for my bad english. class StockRecordForm(forms.ModelForm)
Answer the question
In order to leave comments, you need to log in
Then I forked the app
from oscar import get_core_apps
INSTALLED_APPS += get_core_apps([
'path.to.local.folder.dashboard.catalogue',
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question