Fakultas Ilmu Komputer UI

models.py 1.37 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
Samuel Dimas's avatar
Samuel Dimas committed
4
5

# Create your models here.
Saul Andre's avatar
Saul Andre committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def getRandomColor():
    color = "%06x" % random.randint(0, 0xFFFFFF)
    return color 

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):
    user = models.CharField(max_length = 100, default= getRandomUserId())
    profile = models.CharField(max_length = 100, default= getRandomColor())
    comment = models.CharField(max_length = 150, default= 'comments')

    def __str__(self):
        return self.user

30
class Materi(models.Model):
Saul Andre's avatar
Saul Andre committed
31
    #TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
32
    cover = models.URLField(max_length=1000)
Saul Andre's avatar
Saul Andre committed
33
34
35
36
37
38
39
40
41
42
43
    title = models.CharField(max_length=50, default='title') 
    author = models.CharField(max_length=30, default='author')
    uploader = models.CharField(max_length=30, default='uploader') #ubah jadi one to one ke kontributor 
    publisher = models.CharField(max_length=30, default='publiser')
    descriptions = models.TextField(default='descriptions')
    verified = models.BooleanField(default=False, null=True)
    categories = models.ManyToManyField(Category)
    comments = models.ManyToManyField(Comment)