Add ProductKit binding to ConfigurableKitProductAttribute values
Implementation of kit binding feature for ConfigurableKitProduct variants: - Added ForeignKey field `kit` to ConfigurableKitProductAttribute * References ProductKit with CASCADE delete * Optional field (blank=True, null=True) * Indexed for efficient queries - Created migration 0007_add_kit_to_attribute * Handles existing data (NULL values for all current records) * Properly indexed for performance - Updated template configurablekit_form.html * Injected available ProductKits into JavaScript * Added kit selector dropdown in card interface * Each value now has associated kit selection * JavaScript validates kit selection alongside values - Updated JavaScript in card interface * serializeAttributeValues() now collects kit IDs * Creates parallel JSON arrays: values and kits * Stores in hidden fields: attributes-X-values and attributes-X-kits - Updated views _save_attributes_from_cards() in both Create and Update * Reads kit IDs from POST JSON * Looks up ProductKit objects * Creates ConfigurableKitProductAttribute with FK populated * Gracefully handles missing kits - Fixed _should_delete_form() method * More robust handling of formset deletion_field * Works with all formset types - Updated __str__() method * Handles NULL kit case Example workflow: Dlina: 50 -> Kit A, 60 -> Kit B, 70 -> Kit C Upakovka: BEZ -> Kit A, V_UPAKOVKE -> (no kit) Tested with test_kit_binding.py - all tests passing - Kit creation and retrieval - Attribute creation with kit FK - Mixed kit-bound and unbound attributes - Querying attributes by kit - Reverse queries (get kit for attribute value) Added documentation: KIT_BINDING_IMPLEMENTATION.md 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
31
myproject/products/migrations/0007_add_kit_to_attribute.py
Normal file
31
myproject/products/migrations/0007_add_kit_to_attribute.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 5.0.10 on 2025-11-18 18:13
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('products', '0006_add_configurablekitoptionattribute'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='configurablekitproductattribute',
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='configurablekitproductattribute',
|
||||
name='kit',
|
||||
field=models.ForeignKey(blank=True, help_text='Какой ProductKit связан с этим значением атрибута', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='as_attribute_value_in', to='products.productkit', verbose_name='Комплект для этого значения'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='configurablekitproductattribute',
|
||||
unique_together={('parent', 'name', 'option', 'kit')},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='configurablekitproductattribute',
|
||||
index=models.Index(fields=['kit'], name='products_co_kit_id_c5d506_idx'),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user