Skip to content
Snippets Groups Projects
models.py 1018 B
Newer Older
  • Learn to ignore specific revisions
  • from django.db import models
    
    from account.models import Profile
    
    from django.utils import timezone
    from django.core.exceptions import ValidationError
    
    Chif Gergo's avatar
    Chif Gergo committed
    
    
    
    class Event(models.Model):
        name = models.CharField(max_length=255)
    
        date = models.DateTimeField(null=False)
    
        visitors = models.ManyToManyField(Profile, related_name='visitor')
    
        def clean(self):
            if self.date > timezone.now():
                raise ValidationError('Invalid date')
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
    
    
    class Note(models.Model):
        event = models.ForeignKey(Event, related_name='notes', on_delete=models.CASCADE)
        user = models.ForeignKey(Profile, related_name='notes', on_delete=models.CASCADE)
        note = models.TextField()
    
        created_by = models.ForeignKey(Profile, related_name='created_notes', on_delete=models.CASCADE)
        created_at = models.DateTimeField(auto_now_add=True, editable=False)
        updated_at = models.DateTimeField(auto_now=True, editable=False)
    
        def __str__(self):
            return self.note