I’m new to django. I’m building simple shopping website for learning purpose only. I wrote following messy models. Is there any problem in my models? Please point out me. thanks you so much. 🙂
class Product(models.Model):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=155)
description = models.TextField()
photo = models.ImageField(upload_to='product_photo',blank=True)
author = models.CharField(max_length=300,)
price = models.DecimalField(max_digits=6,decimal_places=2)
class ProductDetail(models.Model):
product = models.ForeignKey('Product',related_name='product_details')
pages = models.CharFields(max_length=4)
language = models.CharFields(max_length=50)
binding = models.CharFields(max_length=50)
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
Product.authorshould be aForeignKeytoAuthor, you have a useless comma atProduct.author, and yourProduct.nameandProduct.slughave different lengths, when they contain (or should contain) almost the same data. Also, instead of theAuthormodel you could use the builtinUsermodel. Other than that, it seems ok.