model changes

This commit is contained in:
2024-03-03 11:57:08 +03:00
parent 84faba9759
commit 5f80979aa2
6 changed files with 62 additions and 78 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
</component> </component>
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Pipenv (store)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="TemplatesService"> <component name="TemplatesService">
+36 -21
View File
@@ -5,12 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="03e03f4d-45bc-4bed-b39e-371f1d24898e" name="Changes" comment="remove unnecessary hooks"> <list default="true" id="03e03f4d-45bc-4bed-b39e-371f1d24898e" name="Changes" comment="remove unnecessary hooks">
<change afterPath="$PROJECT_DIR$/products/serializers.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/store.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/store.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/products/urls.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/db.sqlite3" afterDir="false" /> <change beforePath="$PROJECT_DIR$/products/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/products/models.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/products/serializers.py" beforeDir="false" afterPath="$PROJECT_DIR$/products/serializers.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/products/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/products/urls.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/products/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/products/views.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/products/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/products/views.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/store/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/store/urls.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -30,6 +30,9 @@
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectColorInfo">{ <component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 0 &quot;associatedIndex&quot;: 0
}</component> }</component>
@@ -41,23 +44,24 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;Django Server.store.executor&quot;: &quot;Run&quot;, "Django Server.store.executor": "Run",
&quot;RunOnceActivity.OpenDjangoStructureViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "RunOnceActivity.pycharm.django.structure.promotion.once.per.project": "true",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "git-widget-placeholder": "main",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager"> <component name="RunManager">
<configuration name="store" type="Python.DjangoServer" factoryName="Django server"> <configuration name="store" type="Python.DjangoServer" factoryName="Django server">
<module name="store" /> <module name="store" />
@@ -100,7 +104,8 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1709421008833</updated> <updated>1709421008833</updated>
<workItem from="1709421138204" duration="8081000" /> <workItem from="1709421138204" duration="9565000" />
<workItem from="1709453354881" duration="1322000" />
</task> </task>
<task id="LOCAL-00001" summary="Initial commit"> <task id="LOCAL-00001" summary="Initial commit">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -151,4 +156,14 @@
<MESSAGE value="remove unnecessary hooks" /> <MESSAGE value="remove unnecessary hooks" />
<option name="LAST_COMMIT_MESSAGE" value="remove unnecessary hooks" /> <option name="LAST_COMMIT_MESSAGE" value="remove unnecessary hooks" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/products/serializers.py</url>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>
-19
View File
@@ -1,23 +1,6 @@
from django.db import models from django.db import models
class Brand(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True)
def __str__(self):
return f"{self.name}"
class Supplier(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
phone = models.CharField(max_length=20)
def __str__(self):
return f"{self.name}"
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
description = models.TextField() description = models.TextField()
@@ -25,8 +8,6 @@ class Product(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2) price = models.DecimalField(max_digits=10, decimal_places=2)
quantity = models.IntegerField(default=0) quantity = models.IntegerField(default=0)
barcode = models.CharField(max_length=100, blank=True, null=True) barcode = models.CharField(max_length=100, blank=True, null=True)
brand = models.ForeignKey(Brand, models.DO_NOTHING)
supplier = models.ForeignKey(Supplier, models.DO_NOTHING)
def __str__(self): def __str__(self):
return f"{self.name}" return f"{self.name}"
+1 -13
View File
@@ -1,18 +1,6 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Brand, Product, Supplier from .models import Product
class BrandSerializer(serializers.ModelSerializer):
class Meta:
model = Brand
fields = "__all__"
class SupplierSerializer(serializers.ModelSerializer):
class Meta:
model = Supplier
fields = "__all__"
class ProductSerializer(serializers.ModelSerializer): class ProductSerializer(serializers.ModelSerializer):
+2 -2
View File
@@ -1,8 +1,8 @@
from django.urls import include, path from django.urls import include, path
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from .views import BrandViewSet from .views import ProductViewSet
router = DefaultRouter() router = DefaultRouter()
router.register(r"Brands", BrandViewSet) router.register(r"Products", ProductViewSet)
urlpatterns = router.urls urlpatterns = router.urls
+22 -22
View File
@@ -1,49 +1,49 @@
from rest_framework import status, viewsets from rest_framework import status, viewsets
from rest_framework.response import Response from rest_framework.response import Response
from .models import Brand, Product, Supplier from .models import Product
from .serializers import BrandSerializer, ProductSerializer, SupplierSerializer from .serializers import ProductSerializer
class BrandViewSet(viewsets.ModelViewSet): class ProductViewSet(viewsets.ModelViewSet):
queryset = Brand.objects.all() queryset = Product.objects.all()
serializer_class = BrandSerializer serializer_class = ProductSerializer
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
data = list(Brand.objects.all().values()) data = list(Product.objects.all().values())
return Response(data, status=status.HTTP_200_OK) return Response(data, status=status.HTTP_200_OK)
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
data = list(Brand.objects.filter(id=kwargs["pk"]).values()) data = list(Product.objects.filter(id=kwargs["pk"]).values())
return Response(data, status=status.HTTP_200_OK) return Response(data, status=status.HTTP_200_OK)
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
brand_serializer_data = BrandSerializer(data=request.data) product_serializer_data = ProductSerializer(data=request.data)
if brand_serializer_data.is_valid(): if product_serializer_data.is_valid():
brand_serializer_data.save() product_serializer_data.save()
status_code = status.HTTP_201_CREATED status_code = status.HTTP_201_CREATED
return Response({"message": "Brand added successfully"}, status=status_code) return Response({"message": "Product added successfully"}, status=status_code)
else: else:
status_code = status.HTTP_400_BAD_REQUEST status_code = status.HTTP_400_BAD_REQUEST
return Response({"message": "please fill the details"}, status=status_code) return Response({"message": "please fill the details"}, status=status_code)
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
brand_data = Brand.objects.filter(id=kwargs["pk"]) product_data = Product.objects.filter(id=kwargs["pk"])
if brand_data: if product_data:
brand_data.delete() product_data.delete()
status_code = status.HTTP_201_CREATED status_code = status.HTTP_201_CREATED
return Response({"message": "Brand deleted succesfully"}, status=status_code) return Response({"message": "Product deleted successfully"}, status=status_code)
else: else:
status_code = status.HTTP_400_BAD_REQUEST status_code = status.HTTP_400_BAD_REQUEST
return Response({"message": "Brand not found"}, status=status_code) return Response({"message": "Product not found"}, status=status_code)
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
brand_details = Brand.objects.get(id=kwargs["pk"]) product_details = Product.objects.get(id=kwargs["pk"])
brand_serializer_data = BrandSerializer(brand_details, data=request, partial=True) product_serializer_data = ProductSerializer(product_details, data=request, partial=True)
if brand_serializer_data.is_valid(): if product_serializer_data.is_valid():
brand_serializer_data.save() product_serializer_data.save()
status_code = status.HTTP_201_CREATED status_code = status.HTTP_201_CREATED
return Response({"message": "Brand updated successfully"}, status=status_code) return Response({"message": "Product updated successfully"}, status=status_code)
else: else:
status_code = status.HTTP_400_BAD_REQUEST status_code = status.HTTP_400_BAD_REQUEST
return Response({"message": "Brand not found"}, status=status) return Response({"message": "Product not found"}, status=status_code)