-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (backend) : Added Product Models (#87)
* Merge branch develop into Priyansh61/product-model * Done requested changes
- Loading branch information
1 parent
9f051c8
commit 18dbbd7
Showing
9 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from django.contrib import admin | ||
from django.urls import path | ||
from django.conf.urls import include | ||
from django.conf.urls.static import static | ||
from django.conf import settings | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('api/token/', include('auth.urls')), | ||
path('api/accounts/', include('accounts.urls')), | ||
] | ||
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.contrib import admin | ||
from .models import Product,ProductVariation,ProductColor,ProductSize,ProductImage | ||
|
||
# Register your models here. | ||
|
||
class ProductAdmin(admin.ModelAdmin) : | ||
list_display = ("name","description","category",'primary_variant',"created_at","updated_at") | ||
fields = ("name","description","category","primary_variant",) | ||
|
||
class ProductVariationAdmin(admin.ModelAdmin) : | ||
list_display = ("Product","ProductSize","ProductColor","price","quantity") | ||
|
||
class ProductColorAdmin(admin.ModelAdmin) : | ||
list_display = ("color",) | ||
|
||
class ProductSizeAdmin(admin.ModelAdmin) : | ||
list_display = ("size",) | ||
|
||
class ProductImageAdmin(admin.ModelAdmin) : | ||
list_display = ("product_variation_id","image") | ||
|
||
|
||
admin.site.register(Product,ProductAdmin) | ||
admin.site.register(ProductVariation,ProductVariationAdmin) | ||
admin.site.register(ProductColor,ProductColorAdmin) | ||
admin.site.register(ProductSize,ProductSizeAdmin) | ||
admin.site.register(ProductImage,ProductImageAdmin) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ProductsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'products' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
category_choices = [ | ||
('clothing','Clothing'), | ||
('rsvp','RSVP'), | ||
] | ||
|
||
class Product(models.Model): | ||
name = models.CharField(max_length=200) | ||
description = models.TextField(max_length=600, | ||
blank=True) | ||
category = models.CharField(max_length=100, | ||
choices=category_choices) | ||
primary_variant = models.OneToOneField( | ||
'ProductVariation', | ||
on_delete=models.CASCADE, | ||
default=None, | ||
null=True, | ||
blank=True,) | ||
|
||
# Need to add Primary Variant and seller Id | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class ProductVariation(models.Model): | ||
Product = models.ForeignKey(Product, | ||
on_delete=models.CASCADE, | ||
related_name='product_variations') | ||
ProductColor = models.ForeignKey('ProductColor', | ||
on_delete=models.CASCADE) | ||
ProductSize = models.ForeignKey('ProductSize', | ||
on_delete=models.CASCADE) | ||
price = models.IntegerField() | ||
quantity = models.IntegerField() | ||
cover_image = models.ForeignKey('ProductImage', | ||
on_delete=models.CASCADE, | ||
default=None, null=True, | ||
blank=True,) | ||
is_active = models.BooleanField(default=True) | ||
|
||
def __str__(self): | ||
return f'{self.Product.name} {self.ProductColor.color} {self.ProductSize.size}' | ||
|
||
|
||
class ProductColor(models.Model): | ||
color = models.CharField(max_length=100, unique=True) | ||
|
||
def __str__(self): | ||
return self.color | ||
|
||
class ProductSize(models.Model): | ||
size = models.CharField(max_length=100, unique=True) | ||
|
||
def __str__(self): | ||
return self.size | ||
|
||
|
||
class ProductImage(models.Model): | ||
product_variation_id = models.ForeignKey(ProductVariation, | ||
on_delete=models.CASCADE, | ||
related_name='product_images') | ||
image = models.ImageField(upload_to='product_images') | ||
|
||
required = ['image'] | ||
|
||
def __str__(self): | ||
return f'{self.product_variation_id.Product.name} {self.product_variation_id.ProductColor.color} {self.product_variation_id.ProductSize.size}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters