backend/app/events/models.py

37 lines
1.1 KiB
Python
Raw Normal View History

from django.db import models
2022-10-08 19:31:01 +03:00
from users.models import User
class Event(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(max_length=8)
about = models.TextField(blank=True)
creator = models.ForeignKey(
User, related_name="events_created", on_delete=models.CASCADE
)
starts = models.DateTimeField(blank=False)
image = models.ImageField(upload_to="uploads/", blank=True)
image_cropped = models.ImageField(upload_to="cropped/", blank=True)
planning = models.IntegerField(default=0)
attended = models.IntegerField(default=0)
def __str__(self):
return self.name
class Meta:
ordering = ["-starts"]
class EventAttendance(models.Model):
event = models.ForeignKey(Event, related_name="people", on_delete=models.CASCADE)
worker = models.ForeignKey(User, related_name="events", on_delete=models.CASCADE)
token = models.CharField(blank=False, unique=True, max_length=128)
attended = models.BooleanField(default=False)
def __str__(self):
return f"{self.worker.name} attendance on {self.event.name}"