from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver class Member(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) avatar = models.URLField() firstname = models.CharField(max_length=255, blank=True, null=True) lastname = models.CharField(max_length=255, blank=True, null=True) email = models.CharField(max_length=255, blank=True, null=True) number = models.CharField(max_length=255, blank=True, null=True) cell = models.ForeignKey("Cell", on_delete=models.DO_NOTHING, blank=True, null=True) skills = models.ManyToManyField("Skill", blank=True) projects = models.ManyToManyField("Project", blank=True) def __str__(self): return self.firstname +' '+ self.lastname @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Member.objects.create(user=instance) else: instance.member.save() class Skill(models.Model): name = models.CharField(max_length=255, default='') def __str__(self): return self.name class Project(models.Model): name = models.CharField(max_length=255, default='') number = models.PositiveIntegerField(default='0') client = models.OneToOneField("Client", on_delete=models.DO_NOTHING) team = models.ManyToManyField("Member", blank=True) def __str__(self): return self.name class Client(models.Model): name = models.CharField(max_length=255, default='') address = models.CharField(max_length=255, default='') logo = models.URLField() def __str__(self): return self.name class Cell(models.Model): name = models.CharField(max_length=255, default='') city = models.CharField(max_length=255, default='') country = models.CharField(max_length=255, default='') def __str__(self): return self.name class Channel(models.Model): name = models.CharField(max_length=255, default='') description = models.CharField(max_length=255, default='') members = models.ManyToManyField("Member", blank=True) owner = models.ForeignKey("Member", related_name="owned_chatrooms", on_delete=models.DO_NOTHING) def __str__(self): return self.name