update product name

This commit is contained in:
Parsa Nazer
2024-12-12 21:52:50 +03:30
parent ec19f2ded9
commit 0a63bc275c
4 changed files with 23 additions and 6 deletions
+2 -2
View File
@@ -3,8 +3,8 @@ from .models import *
from unfold.admin import ModelAdmin
@admin.register(Product)
class ProductAdmin(ModelAdmin):
@admin.register(ProductModel)
class ProductModelAdmin(ModelAdmin):
pass
@@ -0,0 +1,17 @@
# Generated by Django 5.1.2 on 2024-12-12 18:22
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('product', '0003_commentmodel_user'),
]
operations = [
migrations.RenameModel(
old_name='Product',
new_name='ProductModel',
),
]
+2 -2
View File
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.text import slugify
from django.contrib.auth.models import User
class Product(models.Model):
class ProductModel(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
price = models.PositiveIntegerField(default=0)
@@ -42,7 +42,7 @@ class Product(models.Model):
class CommentModel(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')
content = models.TextField(verbose_name='محتوای نظر')
user = models.ForeignKey(User, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now_add=True, verbose_name='زمان ثبت کامنت')
+2 -2
View File
@@ -13,14 +13,14 @@ class CommentView(APIView):
serializer_class = CommentSerializer
permission_classes = [IsAuthenticatedOrReadOnly]
def get(self, request, pk):
product = get_object_or_404(Product, id=pk)
product = get_object_or_404(ProductModel, id=pk)
comments = product.comments.filter(show=True)
comments_ser = self.serializer_class(instance=comments, many=True)
return Response({'comments': comments_ser.data}, status=status.HTTP_200_OK)
def post(self, request, pk):
comment_ser = CommentSerializer(data=request.data)
product = get_object_or_404(Product, id=pk)
product = get_object_or_404(ProductModel, id=pk)
if comment_ser.is_valid():
comment_ser.save(product=product)
#TODO comment_ser.save(product=product, user=request.user)