update product name
This commit is contained in:
@@ -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',
|
||||
),
|
||||
]
|
||||
@@ -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='زمان ثبت کامنت')
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user