django-confirmation / confirmation /

import random

from django.db import models
from django.contrib.contenttypes.models import ContentType

from confirmation import settings

class ConfirmationManager(models.Manager):
    Auto generate key with length and allowed symobls from settings

    def create(self, obj=None, token=1, data=None):
        key = "".join(random.choice(settings.KEY_SYMBOLS) for i in range(0, settings.KEY_LENGTH))
        confirmation = self.model(key=key, token=token, data=data)
        if obj:
            confirmation.content_type = ContentType.objects.get_for_model(obj)
            confirmation.object_id =
        return confirmation