summaryrefslogtreecommitdiffstats
path: root/users/models/invite.py
blob: 5d69b18d8e9b9777f062ea87fc4246568d0d7371 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import random

from django.db import models


class Invite(models.Model):
    """
    An invite token, good for one signup.
    """

    # Should always be lowercase
    token = models.CharField(max_length=500, unique=True)

    # Is it limited to a specific email?
    email = models.EmailField(null=True, blank=True)

    # Admin note about this code
    note = models.TextField(null=True, blank=True)

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    @classmethod
    def create_random(cls, email=None):
        return cls.objects.create(
            token="".join(
                random.choice("abcdefghkmnpqrstuvwxyz23456789") for i in range(20)
            ),
            email=email,
        )