Fakultas Ilmu Komputer UI

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

from django.db import models
4

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

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

# Create your models here.
15
16


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

Saul Andre's avatar
Saul Andre committed
21
22
23
24
25
26
27
28

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

    def __str__(self):
        return self.name

29

30
class Materi(models.Model):
31
    # TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
igor lestin sianipar's avatar
igor lestin sianipar committed
32
33
    cover = models.ImageField()
    content = models.FileField()
34
    title = models.CharField(max_length=50, default='title')
35
    author = models.CharField(max_length=30, default='author')
igor lestin sianipar's avatar
igor lestin sianipar committed
36
    uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
37
    publisher = models.CharField(max_length=30, default="publiser")
Samuel Dimas Partogi's avatar
Samuel Dimas Partogi committed
38
    pages = models.IntegerField(default=0)
39
    descriptions = models.TextField(default="descriptions")
40
41
    status = models.CharField(
        max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
Saul Andre's avatar
Saul Andre committed
42
    categories = models.ManyToManyField(Category)
43
44
    date_added = models.DateTimeField(auto_now_add=True)

45
46

class Comment(models.Model):
47
48
    username = models.CharField(max_length=100)
    profile = models.CharField(max_length=100, default=getRandomColor)
49
    comment = models.CharField(max_length=150, default="comments")
50
    materi = models.ForeignKey(Materi, models.SET_NULL, null=True)
51
52
    user = models.ForeignKey(
        User, on_delete=models.SET_NULL, blank=True, null=True)
53
54

    def __str__(self):
55
        return self.username