Created
October 29, 2022 14:55
-
-
Save KabakiAntony/a7a0429415b1ded39e7c8f5d21a5e041 to your computer and use it in GitHub Desktop.
this will be product app models 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
from django.db import models | |
class Category(models.Model): | |
name = models.CharField(max_length=100, unique=True) | |
description = models.TextField(max_length=255, blank=True) | |
def __str__(self): | |
return self.name | |
class Product(models.Model): | |
name = models.CharField(max_length=150, unique=True) | |
slug = models.SlugField() | |
description = models.TextField(max_length=255, blank=True) | |
price = models.DecimalField(max_digits=7, decimal_places=0) | |
category = models.ForeignKey(Category, on_delete=models.CASCADE) | |
main_image = models.ImageField(default='default.jpeg', blank=True) | |
date = models.DateTimeField(auto_now_add=True) | |
stock = models.PositiveIntegerField(default=1) | |
available = models.BooleanField(default=True) | |
def __str__(self): | |
return self.name | |
class ProductImage(models.Model): | |
product = models.ForeignKey(Product, on_delete=models.CASCADE) | |
thumb = models.ImageField(default='default.jpeg', blank=True) | |
def __str__(self): | |
return self.product.name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment