diff --git a/products/migrations/0003_category_parent_alter_product_table.py b/products/migrations/0003_category_parent_alter_product_table.py new file mode 100644 index 0000000..6a7529c --- /dev/null +++ b/products/migrations/0003_category_parent_alter_product_table.py @@ -0,0 +1,23 @@ +# Generated by Django 6.1 on 2026-08-16 09:56 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('products', '0002_alter_product_options'), + ] + + operations = [ + migrations.AddField( + model_name='category', + name='parent', + field=models.ForeignKey(blank=True, db_column='parent_id', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subcategories', to='products.category'), + ), + migrations.AlterModelTable( + name='product', + table='api_product', + ), + ] diff --git a/products/models.py b/products/models.py index 62d2119..bfa0df3 100644 --- a/products/models.py +++ b/products/models.py @@ -6,6 +6,7 @@ class Category(models.Model): slug = models.SlugField(max_length=100, unique=True, blank=True) is_active = models.BooleanField(default=True) sort_order = models.IntegerField(default=0) + parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='subcategories', db_column='parent_id') class Meta: verbose_name_plural = "Categories"