Skip to content
Snippets Groups Projects
models.py 1.55 KiB
Newer Older
  • Learn to ignore specific revisions
  • from django.db import models
    
    from account.models import Profile
    
    from common.middleware import CurrentUserMiddleware
    
    Chif Gergo's avatar
    Chif Gergo committed
    
    
    
    class Event(models.Model):
        name = models.CharField(max_length=255)
    
        date = models.DateTimeField(null=False)
    
    Bodor Máté's avatar
    Bodor Máté committed
        description = models.TextField(blank=True, default='')
    
        visitors = models.ManyToManyField(
            Profile,
    
    Bodor Máté's avatar
    Bodor Máté committed
            related_name='events_visitor',
            blank=True
        )
        absent = models.ManyToManyField(
            Profile,
            related_name='events_absent',
    
    Bodor Máté's avatar
    Bodor Máté committed
            blank=True
    
        )
        created_by = models.ForeignKey(
            Profile,
            related_name='created_event',
            on_delete=models.DO_NOTHING,
    
    Bodor Máté's avatar
    Bodor Máté committed
            default=CurrentUserMiddleware.get_current_user_profile
    
        created_at = models.DateTimeField(auto_now_add=True, editable=False)
        updated_at = models.DateTimeField(auto_now=True, editable=False)
    
        def __str__(self):
            return self.name
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
    
    
    class Note(models.Model):
    
    Bodor Máté's avatar
    Bodor Máté committed
        event = models.ForeignKey(Event, related_name='notes', on_delete=models.CASCADE, blank=True, null=True)
        profile = models.ForeignKey(Profile, related_name='notes', on_delete=models.CASCADE, blank=True, null=True)
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
        note = models.TextField()
    
        created_by = models.ForeignKey(
            Profile,
            related_name='created_notes',
            on_delete=models.DO_NOTHING,
    
    Bodor Máté's avatar
    Bodor Máté committed
            default=CurrentUserMiddleware.get_current_user_profile
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
        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