Features: 1) Add system_attributes JSONField to Stock model; 2) Introduce StockForm with system_attributes widget; 3) Integrate StockForm into StockAdmin in Django admin panel.
Fixes: None; Extra: 1) Update migrations to include addition of `system_attributes`; 2) Modify admin interface to display `system_attributes` in additional_fields.
This commit is contained in:
parent
753a2059d4
commit
d2b3dccda9
4 changed files with 33 additions and 1 deletions
|
|
@ -16,7 +16,7 @@ from modeltranslation.translator import NotRegistered, translator
|
||||||
from modeltranslation.utils import get_translation_fields
|
from modeltranslation.utils import get_translation_fields
|
||||||
from mptt.admin import DraggableMPTTAdmin
|
from mptt.admin import DraggableMPTTAdmin
|
||||||
|
|
||||||
from core.forms import CRMForm, OrderForm, OrderProductForm, VendorForm
|
from core.forms import CRMForm, OrderForm, OrderProductForm, StockForm, VendorForm
|
||||||
from core.models import (
|
from core.models import (
|
||||||
Address,
|
Address,
|
||||||
Attribute,
|
Attribute,
|
||||||
|
|
@ -743,6 +743,7 @@ class PromotionAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # typ
|
||||||
class StockAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # type: ignore [misc, type-arg]
|
class StockAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # type: ignore [misc, type-arg]
|
||||||
# noinspection PyClassVar
|
# noinspection PyClassVar
|
||||||
model = Stock # type: ignore [misc]
|
model = Stock # type: ignore [misc]
|
||||||
|
form = StockForm
|
||||||
list_display = (
|
list_display = (
|
||||||
"product",
|
"product",
|
||||||
"vendor",
|
"vendor",
|
||||||
|
|
@ -777,6 +778,9 @@ class StockAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # type: i
|
||||||
"purchase_price",
|
"purchase_price",
|
||||||
"digital_asset",
|
"digital_asset",
|
||||||
]
|
]
|
||||||
|
additional_fields = [
|
||||||
|
"system_attributes",
|
||||||
|
]
|
||||||
relation_fields = [
|
relation_fields = [
|
||||||
"product",
|
"product",
|
||||||
"vendor",
|
"vendor",
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,15 @@ class OrderProductForm(forms.ModelForm):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class StockForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Product
|
||||||
|
fields = "__all__"
|
||||||
|
widgets = {
|
||||||
|
"system_attributes": JSONTableWidget(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class OrderForm(forms.ModelForm):
|
class OrderForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
|
|
|
||||||
18
core/migrations/0051_stock_system_attributes.py
Normal file
18
core/migrations/0051_stock_system_attributes.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.2.7 on 2025-10-26 16:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0050_remove_attribute_categories'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stock',
|
||||||
|
name='system_attributes',
|
||||||
|
field=models.JSONField(default=dict, verbose_name='system attributes'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -551,6 +551,7 @@ class Stock(ExportModelOperationsMixin("stock"), NiceModel): # type: ignore [mi
|
||||||
verbose_name=_("digital file"),
|
verbose_name=_("digital file"),
|
||||||
upload_to="downloadables/",
|
upload_to="downloadables/",
|
||||||
)
|
)
|
||||||
|
system_attributes = JSONField(default=dict, verbose_name=_("system attributes"))
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.vendor.name} - {self.product!s}"
|
return f"{self.vendor.name} - {self.product!s}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue