-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
34 lines (26 loc) · 1.04 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import uuid
from django.db import models
from django.utils.text import slugify
def catalog_image_file_path(instance, filename):
_, extension = os.path.splitext(filename)
filename = f"{slugify(instance.name)}-{uuid.uuid4()}{extension}"
return os.path.join("uploads/catalog/", filename)
class Catalog(models.Model):
name = models.CharField(max_length=100, unique=True)
grape_variety = models.CharField(max_length=100)
region = models.CharField(max_length=100)
country = models.CharField(max_length=100)
description = models.TextField(blank=True)
alcohol_content = models.DecimalField(
max_digits=4, decimal_places=2, null=True, blank=True
)
price = models.PositiveIntegerField()
amount = models.PositiveIntegerField()
sold = models.PositiveIntegerField(default=0)
image = models.ImageField(null=True, upload_to=catalog_image_file_path)
date_created = models.DateField(auto_now_add=True)
def __str__(self):
return self.name
class Meta:
ordering = ["-price"]