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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
from django.db import models
from django.contrib.auth.models import User as DjangoUser
from django.contrib.auth.models import UserManager
from datetime import datetime
import random, string, re
''' Helper methods '''
def randomstring(length=16):
return ''.join(random.choice(string.letters) for i in xrange(length))
''' Core models '''
class Hacker(DjangoUser):
twitter = models.SlugField(max_length=100, blank=True, null=True)
#stackoverflow
#blog
#homepage
# Use UserManager to get the create_user method, etc.
objects = UserManager()
class OneLiner(models.Model):
hacker = models.ForeignKey(Hacker)
line = models.TextField()
summary = models.TextField()
explanation = models.TextField()
caveats = models.TextField(blank=True)
is_published = models.BooleanField(default=False)
created_dt = models.DateTimeField(default=datetime.now)
def lines(self):
return [x for x in self.line.split('\n') if x.strip() != '']
def __unicode__(self):
return self.line
# eof
|