Source

django-confirmation / confirmation / models.py

Full commit
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.core.urlresolvers import reverse

from confirmation.managers import ConfirmationManager



class Confirmation(models.Model):
    """
    Can be used for user activation, but also for
    other purposes where confirmation is required.
    """
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')
    date = models.DateTimeField(auto_now=True)
    key = models.CharField(max_length=32)
    confirmation_type = models.IntegerField(default=1)
    content = models.TextField(blank=True, null=True)
    

    objects = ConfirmationManager()
    
    
    def get_url(self, request):
        url = request.build_absolute_uri(reverse('confirmation'))
        url += '?key=%s&type=%s' % (self.key, self.confirmation_type)
        return url
    
    class Meta:
        db_table = "confirmation"

    def __unicode__(self):
        return self.key