add color field and in stuck model
This commit is contained in:
@@ -1,18 +1,27 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
from unfold.admin import ModelAdmin
|
||||
from unfold.admin import ModelAdmin, TabularInline
|
||||
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
|
||||
from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from unfold.widgets import (
|
||||
UnfoldAdminColorInputWidget,
|
||||
)
|
||||
|
||||
class InStuckColorsInLine(TabularInline):
|
||||
model = InStuckColors
|
||||
extra = 1
|
||||
formfield_overrides = {
|
||||
models.CharField: {"widget": UnfoldAdminColorInputWidget()},
|
||||
}
|
||||
|
||||
@admin.register(ProductModel)
|
||||
class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
|
||||
inlines = [InStuckColorsInLine]
|
||||
readonly_fields = ('slug', )
|
||||
|
||||
compressed_fields = True
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-01 15:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0004_alter_subcategorymodel_parent'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='dollormodel',
|
||||
options={'verbose_name': 'مدل دلار', 'verbose_name_plural': 'مدل دلار'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='productmodel',
|
||||
options={'verbose_name': 'محصول', 'verbose_name_plural': 'محصولات'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='productmodel',
|
||||
name='color',
|
||||
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='color'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-01 15:32
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0005_alter_dollormodel_options_alter_productmodel_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='InStuckColors',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('color', models.CharField(blank=True, max_length=255, null=True, verbose_name='color')),
|
||||
('in_stuck', models.PositiveIntegerField(default=0)),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='colors', to='product.productmodel')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'تعداد موجود رنگ',
|
||||
'verbose_name_plural': 'تعداد موجود رنگ ها',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-01 15:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0006_instuckcolors'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='productmodel',
|
||||
name='in_stock',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='instuckcolors',
|
||||
name='in_stuck',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='تعداد موجود'),
|
||||
),
|
||||
]
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 5.1.2 on 2025-02-01 15:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0007_remove_productmodel_in_stock_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='productmodel',
|
||||
name='color',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='instuckcolors',
|
||||
name='color',
|
||||
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='رنگ'),
|
||||
),
|
||||
]
|
||||
@@ -3,7 +3,7 @@ from django.utils.text import slugify
|
||||
from account.models import User
|
||||
from django.urls import reverse
|
||||
import requests
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class MainCategoryModel(models.Model):
|
||||
name = models.CharField(max_length=50, verbose_name='نام')
|
||||
@@ -103,7 +103,6 @@ class ProductModel(models.Model):
|
||||
show = models.BooleanField(default=False, verbose_name='نمایش در خانه')
|
||||
view = models.IntegerField(default=0, verbose_name='بازدید')
|
||||
sell = models.IntegerField(default=0, verbose_name='فروش')
|
||||
in_stock = models.IntegerField(default=0, verbose_name="تعداد موجود")
|
||||
discount = models.SmallIntegerField(default=0, verbose_name='تخفیف')
|
||||
slug = models.SlugField(max_length=50, unique=True, blank=True, null=True, allow_unicode=True,
|
||||
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
|
||||
@@ -149,6 +148,16 @@ class ProductModel(models.Model):
|
||||
verbose_name_plural = 'محصولات'
|
||||
|
||||
|
||||
class InStuckColors(models.Model):
|
||||
color = models.CharField(_("رنگ"), null=True, blank=True, max_length=255)
|
||||
in_stuck = models.PositiveIntegerField(default=0, verbose_name="تعداد موجود")
|
||||
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='colors')
|
||||
class Meta:
|
||||
verbose_name = 'تعداد موجود رنگ'
|
||||
verbose_name_plural = 'تعداد موجود رنگ ها'
|
||||
def __str__(self):
|
||||
return f'{product} - {color}'
|
||||
|
||||
class CommentModel(models.Model):
|
||||
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')
|
||||
content = models.TextField(verbose_name='محتوای نظر')
|
||||
|
||||
Reference in New Issue
Block a user