models.py

member access
mail@pastecode.io avatar
unknown
python
a year ago
1.9 kB
3
Indexable
Never
# membernya
class Member(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
    member_first_name = models.CharField(max_length=100, help_text="Your first name")
    member_last_name = models.CharField(max_length=100, help_text="Your first name")

    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, auto_created=True)

    def save(self, *args, **kwargs):
        self.alumni_url = slugify(self.member_first_name + '-' + self.member_last_name)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.member_first_name + ' ' + self.member_last_name

    class Meta:
        verbose_name_plural = 'Members'



# space/group yang bisa disetting private / public
class Space(models.Model):
    space_name = models.CharField(max_length=100)
    space_url = models.CharField(editable=False, default=uuid.uuid4, max_length=150)
    space_category = models.ForeignKey(SpaceCategory, on_delete=models.CASCADE, blank=True, null=True)

    is_private = models.BooleanField(default=False)

    def save(self, *args, **kwargs):
        self.space_url = slugify(self.space_name)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.space_name

    class Meta:
        verbose_name_plural = 'Space / Alumni Group'



# buat nyimpen aksesnya
class AccessQueue(models.Model):
    access_name = models.CharField(max_length=50)
    user = models.ForeignKey(Member, on_delete=models.CASCADE)
    access_status = models.CharField(choices=status, max_length=20, default=None)
    access_space = models.ForeignKey(Space, on_delete=models.CASCADE, default=0)
    is_member = models.BooleanField(default=False)
    is_confirmed = models.BooleanField(default=False)

    def __str__(self):
        return self.access_name