Fakultas Ilmu Komputer UI

models.py 1.57 KB
Newer Older
Saul Andre's avatar
Saul Andre committed
1
import random
2
3
4
5
import uuid

from django.db import models

igor lestin sianipar's avatar
igor lestin sianipar committed
6
7
8
from authentication.models import User

VERIFICATION_STATUS = [
9
10
11
12
    ("PENDING", "Diproses"),
    ("APPROVE", "Diterima"),
    ("DISAPROVE", "Ditolak"),
    ("REVISION", "Perbaikan"),
igor lestin sianipar's avatar
igor lestin sianipar committed
13
]
Samuel Dimas's avatar
Samuel Dimas committed
14
15

# Create your models here.
Saul Andre's avatar
Saul Andre committed
16
17
def getRandomColor():
    color = "%06x" % random.randint(0, 0xFFFFFF)
Saul Andre's avatar
Saul Andre committed
18
    return color 
Saul Andre's avatar
Saul Andre committed
19
20
21
22
23

def getRandomUserId():
    userId = uuid.uuid4().hex
    return userId

24

Saul Andre's avatar
Saul Andre committed
25
26
27
28
29
30
31
32
33
class Category(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=20)

    def __str__(self):
        return self.name


class Comment(models.Model):
34
35
    user = models.CharField(max_length=100, default=getRandomUserId())
    profile = models.CharField(max_length=100, default=getRandomColor())
36
    comment = models.CharField(max_length=150, default="comments")
Saul Andre's avatar
Saul Andre committed
37
38
39
40

    def __str__(self):
        return self.user

41
class Materi(models.Model):
igor lestin sianipar's avatar
igor lestin sianipar committed
42
43
    cover = models.ImageField()
    content = models.FileField()
44
45
    title = models.CharField(max_length=50, default="title")
    author = models.CharField(max_length=30, default="author")
igor lestin sianipar's avatar
igor lestin sianipar committed
46
    uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
47
48
49
    publisher = models.CharField(max_length=30, default="publiser")
    descriptions = models.TextField(default="descriptions")
    status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0])
50
    comments = models.ForeignKey(Comment, on_delete=models.CASCADE, default=1)
Saul Andre's avatar
Saul Andre committed
51
    categories = models.ManyToManyField(Category)
52
    feedback = models.TextField(blank=True, default="")