summaryrefslogtreecommitdiff
path: root/web/models.py
blob: f30355226f8d244b2316ca22c4e2818b18d286d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.contrib import admin
from django.db import models
from django.contrib.auth.models import User



class BaseModel(models.Model):
    created_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
    updated_at = models.DateTimeField(blank=True, null=True, auto_now=True)
    active = models.BooleanField(default=True)

    class Meta:
        abstract = True


class Event(BaseModel):
    id = models.AutoField(primary_key=True)
    name = models.TextField(blank=False, null=False)
    start_date = models.DateTimeField(blank=False, null=False)
    end_date = models.DateTimeField(blank=False, null=False)
    participants = models.IntegerField(blank=False)

    class Meta:
        db_table = 'events'


class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'start_date', 'end_date', 'active')


class Availability(BaseModel):
    id = models.AutoField(primary_key=True)
    event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    time_table = models.JSONField()

    class Meta:
        db_table = 'availabilities'