feat: add self-referencing parent field to Category model and rename Product table to api_product
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 23s

This commit is contained in:
vickytechkey 2026-08-16 15:30:15 +05:30
parent f904cad860
commit d3a1c243ea
2 changed files with 24 additions and 0 deletions

View file

@ -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',
),
]

View file

@ -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"