takahe/users/models/invite.py

37 lines
921 B
Python
Raw Normal View History

2022-11-17 23:09:04 -08:00
import random
2022-12-20 00:51:53 -08:00
import urlman
2022-11-17 23:09:04 -08:00
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)
2022-12-20 00:51:53 -08:00
class urls(urlman.Urls):
admin = "/admin/invites/"
admin_create = "{admin}create/"
admin_view = "{admin}{self.pk}/"
2022-11-17 23:09:04 -08:00
@classmethod
def create_random(cls, email=None):
return cls.objects.create(
token="".join(
random.choice("abcdefghkmnpqrstuvwxyz23456789") for i in range(20)
),
email=email,
)