public
Description: Sample paste bin Django application for the Pinax platform
Homepage: http://fernandoacorreia.wordpress.com/tag/pinax/
Clone URL: git://github.com/fernandoacorreia/oxybeles.git
oxybeles / models.py
100644 31 lines (24 sloc) 1.019 kb
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
31
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _
from uuid import uuid4
 
class PastedItem(models.Model):
    """
An item that was pasted.
"""
 
    uuid = models.CharField(_('identifier'), max_length=36, unique=True)
    text = models.TextField(_('text'))
    in_response_to = models.ForeignKey('self', related_name='responses',
        blank=True, null=True, verbose_name=_('in response to'))
    user = models.ForeignKey(User, related_name="pasted_items",
        verbose_name=_('user'))
    pasted_at = models.DateTimeField(_('pasted at'), auto_now_add=True)
 
    def __unicode__(self):
        return self.uuid
 
    def save(self):
        if not self.uuid:
            self.uuid = str(uuid4()) # random so it can't be easily guessed
        super(PastedItem, self).save()
 
    def get_absolute_url(self):
        return ('oxybeles_detail', (), { 'uuid': self.uuid })
    get_absolute_url = models.permalink(get_absolute_url)