Fakultas Ilmu Komputer UI

models.py 1.68 KB
Newer Older
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.
16
17


18
19
def getRandomColor():
    color = "%06x" % random.randint(0, 0xFFFFFF)
20
21
    return color

22
23
24
25
26

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

27

28
29
30
31
32
33
34
class Category(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=20)

    def __str__(self):
        return self.name

35
36

class Comment(models.Model):
37
38
    user = models.CharField(max_length=100, default=getRandomUserId())
    profile = models.CharField(max_length=100, default=getRandomColor())
39
    comment = models.CharField(max_length=150, default="comments")
40
41
42
43

    def __str__(self):
        return self.user

44

45
class Materi(models.Model):
46
    # TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
igor lestin sianipar's avatar
igor lestin sianipar committed
47
48
    cover = models.ImageField()
    content = models.FileField()
49
    title = models.CharField(max_length=50, default='title')
50
    author = models.CharField(max_length=30, default='author')
igor lestin sianipar's avatar
igor lestin sianipar committed
51
52
    # ubah jadi one to one ke kontributor
    uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
53
54
    publisher = models.CharField(max_length=30, default="publiser")
    descriptions = models.TextField(default="descriptions")
55
    status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
56
57
    categories = models.ManyToManyField(Category)
    comments = models.ManyToManyField(Comment)
58
    feedback = models.TextField(blank=True, default="")
59