Skip to content

Commit

Permalink
Starting Module 6: Customizing Model Behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
codesensei-courses committed Apr 26, 2024
1 parent 92897af commit 7adedd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions carved_rock/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ class Product(models.Model):
description = models.TextField(default="", blank=True)
sku = models.CharField(verbose_name="Stock Keeping Unit", max_length=20, unique=True)

class Meta:
ordering = ['price']

def __str__(self):
return self.name


class ProductImage(models.Model):
image = models.ImageField()
product = models.ForeignKey('Product', on_delete=models.CASCADE)
product = models.ForeignKey('Product', on_delete=models.CASCADE, related_name="images")

def __str__(self):
return str(self.image)


class Category(models.Model):
name = models.CharField(max_length=100)
products = models.ManyToManyField('Product')
products = models.ManyToManyField('Product', related_name="categories")

def __str__(self):
return self.name
2 changes: 1 addition & 1 deletion carved_rock/store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def category_view(request, name):
products = Product.objects.filter(category__name=name)
products = Product.objects.filter(categories__name=name)

return render(request, "store/category.html",
{'products': products,
Expand Down

0 comments on commit 7adedd6

Please sign in to comment.