Fakultas Ilmu Komputer UI

models.py 1.23 KB
Newer Older
Samuel Dimas's avatar
Samuel Dimas committed
1
from django.db import models
2
3
import uuid
import random
Samuel Dimas's avatar
Samuel Dimas committed
4
5

# Create your models here.
6
7
8
9
10
11
12
13
def getRandomColor():
    color = "%06x" % random.randint(0, 0xFFFFFF)
    return color 

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

14
15
16
17
18
19
20
class Category(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=20)

    def __str__(self):
        return self.name

21
22
23
24
25
26
27
28
29

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
31
class Materi(models.Model):
    cover = models.URLField(max_length=1000)
32
33
34
35
36
37
38
39
    title = models.CharField(max_length=50, default='title') 
    author = models.CharField(max_length=30, default='author')
    uploader = models.CharField(max_length=30, default='uploader')
    publisher = models.CharField(max_length=30, default='publiser')
    descriptions = models.TextField(default='descriptions')
    verified = models.BooleanField(default=False)
    categories = models.ManyToManyField(Category)
    comments = models.ManyToManyField(Comment)