-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
53 lines (39 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from django.db import models
# Create your models here.
from django.utils.text import slugify
def defoult_rate():
return (
(1, "⭐"),
(2, "⭐⭐"),
(3, "⭐⭐⭐"),
(4, "⭐⭐⭐⭐"),
(5, "⭐⭐⭐⭐⭐"),
)
class Category(models.Model):
content = models.CharField(max_length=128)
slug = models.SlugField(max_length=128, blank=True, null=True)
def __str__(self):
return self.content
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.content)
super(Category, self).save(*args, **kwargs)
class Recipe(models.Model):
name = models.CharField(max_length=256)
steps = models.TextField()
date = models.DateTimeField(auto_now_add=True)
prep = models.IntegerField()
cook = models.IntegerField()
yields = models.IntegerField()
rate = models.IntegerField(choices=defoult_rate())
img = models.ImageField()
ctg = models.ForeignKey(Category, on_delete=models.CASCADE)
def __str__(self):
return self.name
class Suggestion(models.Model):
name = models.CharField(max_length=256)
email = models.EmailField()
subject = models.CharField(max_length=512)
message = models.TextField()
def __str__(self):
return self.name