adding product app

This commit is contained in:
AmirHossein Shirazi
2024-12-12 16:39:25 +03:30
parent 07e0a744c5
commit f1659f4289
8 changed files with 63 additions and 7 deletions
View File
+3
View File
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ProductConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'product'
+41
View File
@@ -0,0 +1,41 @@
from django.db import models
from django.utils.text import slugify
class Product(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
price = models.PositiveIntegerField(default=0)
image = models.ImageField(upload_to='product_images/')
rating = models.PositiveIntegerField(default=0)
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="این فیلد را خالی بگذارید")
link_of_metas = models.CharField(max_length=400, verbose_name='لینک استخراج متا', null=True, blank=True)
meta_description = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید')
meta_keywords = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید')
meta_rating = models.FloatField(default=5, help_text='امتیاز محصول')
def format_discount_price(self):
discount_price = int(self.price * (100 - self.discount) / 100)
formatted_num = "{:,.0f}".format(discount_price)
return formatted_num
def discount_price(self):
discount_price = int(self.price * (100 - self.discount) / 100)
return discount_price
def format_price(self):
price = self.price
formatted_num = "{:,.0f}".format(price)
return formatted_num
def __str__(self):
return self.name
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name, allow_unicode=True)
super().save(*args, **kwargs)
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+3
View File
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
+7 -7
View File
@@ -1,11 +1,11 @@
services: services:
frontend: # frontend:
build: # build:
context: ./frontend # context: ./frontend
ports: # ports:
- "80:3000" # - "80:3000"
depends_on: # depends_on:
- django # - django
django: django:
build: build: