1
1
import oauth
2
2
import logging
3
+ from datetime import datetime
3
4
4
5
from django .db import models
5
6
class Token (models .Model ):
@@ -28,8 +29,14 @@ def makeToken(self):
28
29
def __unicode__ (self ):
29
30
return "%s %s..." % (self .type , self .token [:10 ])
30
31
31
- created = models .DateTimeField (auto_now_add = True )
32
- modified = models .DateTimeField (auto_now = True )
32
+ created = models .DateTimeField ()
33
+ modified = models .DateTimeField ()
34
+ def save (self , * args , ** kwargs ):
35
+ ''' On save, update timestamps '''
36
+ if not self .id :
37
+ self .created = datetime .now ()
38
+ self .modified = datetime .now ()
39
+ return super (Token , self ).save (* args , ** kwargs )
33
40
34
41
35
42
class User (models .Model ):
@@ -80,15 +87,6 @@ def get_from_key(key):
80
87
return r
81
88
raise Exception ("Can't find object with key: %s" % key )
82
89
83
- def save (self ):
84
- """Save this to the DB"""
85
- if not self .primary_key :
86
- import string
87
- import random
88
- chars = string .letters + string .digits
89
- self .primary_key = '' .join (random .sample (chars , 20 ))
90
- logging .info ("new user (%s): %s" % (self .type , self .primary_key ))
91
- return super (User , self ).save ()
92
90
def delete (self ):
93
91
if self .request_token :
94
92
self .request_token .delete ()
@@ -99,5 +97,19 @@ def delete(self):
99
97
def __unicode__ (self ):
100
98
return "%s %s" % (self .type , self .primary_key )
101
99
102
- created = models .DateTimeField (auto_now_add = True )
103
- modified = models .DateTimeField (auto_now = True )
100
+ created = models .DateTimeField ()
101
+ modified = models .DateTimeField ()
102
+
103
+ def save (self , * args , ** kwargs ):
104
+ if not self .primary_key :
105
+ import string
106
+ import random
107
+ chars = string .letters + string .digits
108
+ self .primary_key = '' .join (random .sample (chars , 20 ))
109
+ logging .info ("new user (%s): %s" % (self .type , self .primary_key ))
110
+
111
+ if not self .id :
112
+ self .created = datetime .now ()
113
+ self .modified = datetime .now ()
114
+
115
+ return super (User , self ).save (* args , ** kwargs )
0 commit comments