From b4c6d925d95babba44341274af7a05bf4cb83e5e Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:44 +0530 Subject: [PATCH 1/7] First Commit --- babyshop_app/products/models.py | 39 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/babyshop_app/products/models.py b/babyshop_app/products/models.py index 4e37af3..69b437d 100644 --- a/babyshop_app/products/models.py +++ b/babyshop_app/products/models.py @@ -1,30 +1,29 @@ -from datetime import date -from distutils.command.upload import upload -from email.policy import default -from enum import unique -from pyexpat import model -from unicodedata import name from django.db import models +from django.conf import settings class Category(models.Model): - name=models.CharField(max_length=50,null=True) - slug=models.SlugField(max_length=50,unique=True,null=True) + name = models.CharField(max_length=50, null=True) + slug = models.SlugField(max_length=50, unique=True, null=True) def __str__(self): return self.name - - - - class Product(models.Model): - name=models.CharField(max_length=80) - description=models.TextField() - image=models.ImageField(upload_to="products/%Y/%m/%d/",default="products/broken-1.png") - date=models.DateField(auto_now=True) - price=models.DecimalField(max_digits=6,decimal_places=2) - category=models.ForeignKey(Category,null=True,on_delete=models.DO_NOTHING) + name = models.CharField(max_length=80) + description = models.TextField() + image = models.ImageField(upload_to="products/%Y/%m/%d/", default="products/broken-1.png") + date = models.DateField(auto_now=True) + price = models.DecimalField(max_digits=6, decimal_places=2) + category = models.ForeignKey(Category, null=True, on_delete=models.DO_NOTHING) + def __str__(self): + return self.name - def __str__(self) -> str: - return self.name \ No newline at end of file +class Review(models.Model): + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + product = models.ForeignKey(Product, on_delete=models.CASCADE) + rating = models.PositiveSmallIntegerField() + comment = models.TextField() + + def __str__(self): + return f'Review by {self.user.username} for {self.product.name}' From 41b29c06d887a6e2f8b75aba5aac8878d821cf84 Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:45 +0530 Subject: [PATCH 2/7] First Commit --- babyshop_app/products/admin.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/babyshop_app/products/admin.py b/babyshop_app/products/admin.py index bad85ab..c6f0193 100644 --- a/babyshop_app/products/admin.py +++ b/babyshop_app/products/admin.py @@ -1,12 +1,16 @@ -from re import search from django.contrib import admin -from . models import Category, Product +from .models import Category, Product, Review @admin.register(Product) class ProductAdmin(admin.ModelAdmin): - list_display=('name','price') - search_fields=('name',) + list_display = ('name', 'price') + search_fields = ('name',) @admin.register(Category) class CategoryAdmin(admin.ModelAdmin): - prepopulated_fields={'slug':('name',)} + prepopulated_fields = {'slug': ('name',)} + +@admin.register(Review) +class ReviewAdmin(admin.ModelAdmin): + list_display = ('product', 'user', 'rating', 'comment') + search_fields = ('product__name', 'user__username', 'rating') From 3f80fdfe115cc9832bb3287a2170dfa7a84306bb Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:45 +0530 Subject: [PATCH 3/7] First Commit --- babyshop_app/products/views.py | 36 +++++++++------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/babyshop_app/products/views.py b/babyshop_app/products/views.py index 2fe48ed..0a51b37 100644 --- a/babyshop_app/products/views.py +++ b/babyshop_app/products/views.py @@ -1,29 +1,11 @@ -from datetime import date -from itertools import product -from multiprocessing import context -from unicodedata import category -from django.shortcuts import get_object_or_404, render -from . models import Product -from . models import Category -def product_list(request,category_slug=None): - products=Product.objects.all().order_by('-date') - categories=Category.objects.all().order_by('name') - if category_slug != None: - category_page=get_object_or_404(Category,slug=category_slug) - products=Product.objects.filter(category=category_page) +from django.db import models +from django.contrib.auth.models import User - context={ - 'products':products, - 'categories':categories - } +class Review(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + product = models.ForeignKey(Product, on_delete=models.CASCADE) + rating = models.PositiveIntegerField() + comment = models.TextField() - - return render(request,'products.html',context=context) -def product_detail(request,category_slug,product_id): - product=Product.objects.get(category__slug=category_slug,id=product_id) - products=Product.objects.all().order_by('-date') - context={ - 'product':product, - 'products':products[0:5], - } - return render(request,'product.html',context) \ No newline at end of file + def __str__(self): + return f"Review by {self.user.username} for {self.product.name}" From 4ee0731e67b85d64e76f918e73513348c85021bc Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:45 +0530 Subject: [PATCH 4/7] First Commit --- babyshop_app/products/urls.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/babyshop_app/products/urls.py b/babyshop_app/products/urls.py index 11bfdf4..0053e4a 100644 --- a/babyshop_app/products/urls.py +++ b/babyshop_app/products/urls.py @@ -1,9 +1,10 @@ from django.urls import path from . import views -urlpatterns=[ - path('',views.product_list,name='products'), - path('categories/',views.product_list,name="products_by_category"), - path('/',views.product_detail,name="product_detail") - -] \ No newline at end of file +urlpatterns = [ + path('', views.product_list, name='products'), + path('categories/', views.product_list, name="products_by_category"), + path('/', views.product_detail, name="product_detail"), + # New URL pattern for adding a review + path('/add_review/', views.add_review, name="add_review"), +] From 8a4b84ef38d4f6a0502808994114afb33f91475a Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:46 +0530 Subject: [PATCH 5/7] First Commit --- babyshop_app/templates/product.html | 79 ++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/babyshop_app/templates/product.html b/babyshop_app/templates/product.html index ad5f6be..71bd4a9 100644 --- a/babyshop_app/templates/product.html +++ b/babyshop_app/templates/product.html @@ -1,33 +1,62 @@ {% extends 'partoftemp/_dashboard.html' %} {% block content %} -
-
-
-

{{product.name}}

-
{{product.price}} ₺
-

{{product.description}}

-
Satın Al
-
-
- +
+
+
+

{{ product.name }}

+
{{ product.price }} ₺
+

{{ product.description }}

+
Satın Al
+
+
+ +
+
+
-
-
+ +
+

Product Reviews

+ {% for review in product.reviews.all %} +
+ {{ review.user.username }} - {{ review.rating }}/5 +

{{ review.comment }}

+
+ {% empty %} +

No reviews yet.

+ {% endfor %} +
+ + +
+

Add a Review

+
+ {% csrf_token %} +
+ +
-
- {% for product in products %} -
- -
-
{{product.name}}
-
{{product.price}} ₺
-

{{product.description | truncatechars:80}}

- Detayına Git -
-
- {% endfor %} +
+ +
+ + +
+
+ {% for product in products %} +
+ +
+
{{ product.name }}
+
{{ product.price }} ₺
+

{{ product.description | truncatechars:80 }}

+ Detayına Git +
+
+ {% endfor %} +
-{% endblock %} \ No newline at end of file +{% endblock %} From d86725a1a0082f3847881828daf6e5bbe14bdfbd Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:43:46 +0530 Subject: [PATCH 6/7] First Commit --- babyshop_app/products/tests.py | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/babyshop_app/products/tests.py b/babyshop_app/products/tests.py index 7ce503c..88ded5d 100644 --- a/babyshop_app/products/tests.py +++ b/babyshop_app/products/tests.py @@ -1,3 +1,41 @@ from django.test import TestCase +from django.contrib.auth.models import User +from .models import Product, Category, Review -# Create your tests here. +class ReviewTestCase(TestCase): + def setUp(self): + # Create a user + self.user = User.objects.create_user(username='testuser', password='testpassword') + + # Create a category + self.category = Category.objects.create(name='Electronics', slug='electronics') + + # Create a product + self.product = Product.objects.create( + name='Test Product', + description='Test Description', + price=9.99, + category=self.category + ) + + # Create a review + self.review = Review.objects.create( + user=self.user, + product=self.product, + rating=5, + comment='Great product!' + ) + + def test_review_content(self): + # Test the review content + self.assertEqual(self.review.user, self.user) + self.assertEqual(self.review.product, self.product) + self.assertEqual(self.review.rating, 5) + self.assertEqual(self.review.comment, 'Great product!') + + def test_product_reviews(self): + # Test that the product has the correct review + reviews = self.product.review_set.all() + self.assertIn(self.review, reviews) + + # Add more tests as needed for your application From d98ce91df8a69ac20c193928123cdc9fadbd0fc2 Mon Sep 17 00:00:00 2001 From: redex-ai <149960054+redex-ai@users.noreply.github.com> Date: Tue, 28 Nov 2023 02:03:37 +0530 Subject: [PATCH 7/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d9bb45c..b91bc3b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ - Python - Django - Venv +- Other ### Photos