Fakultas Ilmu Komputer UI

models.py 1.59 KB
Newer Older
Saul Andre's avatar
Saul Andre committed
1
import random
2
3

from django.db import models
igor lestin sianipar's avatar
igor lestin sianipar committed
4
5
6
from authentication.models import User

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

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

class Category(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=20)

    def __str__(self):
        return self.name

25
class Materi(models.Model):
26
    # TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
igor lestin sianipar's avatar
igor lestin sianipar committed
27
28
    cover = models.ImageField()
    content = models.FileField()
29
    title = models.CharField(max_length=50, default='title')
30
    author = models.CharField(max_length=30, default='author')
igor lestin sianipar's avatar
igor lestin sianipar committed
31
32
    # ubah jadi one to one ke kontributor
    uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
33
34
    publisher = models.CharField(max_length=30, default="publiser")
    descriptions = models.TextField(default="descriptions")
35
36
    status = models.CharField(
        max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
Saul Andre's avatar
Saul Andre committed
37
    categories = models.ManyToManyField(Category)
38
    feedback = models.TextField(blank=True, default="")
39
40

class Comment(models.Model):
41
    user = models.CharField(max_length=100)
42
43
    profile = models.CharField(max_length=100, default=getRandomColor())
    comment = models.CharField(max_length=150, default="comments")
44
    materi = models.ForeignKey(Materi, models.SET_NULL, null=True)
45
46
47

    def __str__(self):
        return self.user