Fakultas Ilmu Komputer UI

models.py 1.68 KB
Newer Older
Samuel Dimas's avatar
Samuel Dimas committed
1
from django.db import models
Saul Andre's avatar
Saul Andre committed
2
3
import uuid
import random
igor lestin sianipar's avatar
igor lestin sianipar committed
4
5
6
7
8
9
10
11
from authentication.models import User

VERIFICATION_STATUS = [
    ('PENDING', 'Diproses'),
    ('APPROVE', 'Diterima'),
    ('DISAPROVE', 'Ditolak'),
    ('REVISION', 'Perbaikan'),
]
Samuel Dimas's avatar
Samuel Dimas committed
12
13

# Create your models here.
14
15


Saul Andre's avatar
Saul Andre committed
16
17
def getRandomColor():
    color = "%06x" % random.randint(0, 0xFFFFFF)
18
19
    return color

Saul Andre's avatar
Saul Andre committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33

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

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
36
    user = models.CharField(max_length=100, default=getRandomUserId())
    profile = models.CharField(max_length=100, default=getRandomColor())
    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

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