Skip to content

Commit 2f28da1

Browse files
committed
Add created and updated fields to all models
Closes #321
1 parent 643c3d0 commit 2f28da1

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

oauth2_provider/migrations/0005_auto_20170514_1141.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,48 @@ class Migration(migrations.Migration):
5555
name='user',
5656
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='oauth2_provider_refreshtoken', to=settings.AUTH_USER_MODEL),
5757
),
58+
migrations.AddField(
59+
model_name='accesstoken',
60+
name='created',
61+
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
62+
preserve_default=False,
63+
),
64+
migrations.AddField(
65+
model_name='accesstoken',
66+
name='updated',
67+
field=models.DateTimeField(auto_now=True),
68+
),
69+
migrations.AddField(
70+
model_name='application',
71+
name='created',
72+
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
73+
preserve_default=False,
74+
),
75+
migrations.AddField(
76+
model_name='application',
77+
name='updated',
78+
field=models.DateTimeField(auto_now=True),
79+
),
80+
migrations.AddField(
81+
model_name='grant',
82+
name='created',
83+
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
84+
preserve_default=False,
85+
),
86+
migrations.AddField(
87+
model_name='grant',
88+
name='updated',
89+
field=models.DateTimeField(auto_now=True),
90+
),
91+
migrations.AddField(
92+
model_name='refreshtoken',
93+
name='created',
94+
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
95+
preserve_default=False,
96+
),
97+
migrations.AddField(
98+
model_name='refreshtoken',
99+
name='updated',
100+
field=models.DateTimeField(auto_now=True),
101+
),
58102
]

oauth2_provider/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class AbstractApplication(models.Model):
8181
name = models.CharField(max_length=255, blank=True)
8282
skip_authorization = models.BooleanField(default=False)
8383

84+
created = models.DateTimeField(auto_now_add=True)
85+
updated = models.DateTimeField(auto_now=True)
86+
8487
class Meta:
8588
abstract = True
8689

@@ -182,6 +185,9 @@ class AbstractGrant(models.Model):
182185
redirect_uri = models.CharField(max_length=255)
183186
scope = models.TextField(blank=True)
184187

188+
created = models.DateTimeField(auto_now_add=True)
189+
updated = models.DateTimeField(auto_now=True)
190+
185191
def is_expired(self):
186192
"""
187193
Check token expiration with timezone awareness
@@ -232,6 +238,9 @@ class AbstractAccessToken(models.Model):
232238
expires = models.DateTimeField()
233239
scope = models.TextField(blank=True)
234240

241+
created = models.DateTimeField(auto_now_add=True)
242+
updated = models.DateTimeField(auto_now=True)
243+
235244
def is_valid(self, scopes=None):
236245
"""
237246
Checks if the access token is valid.
@@ -318,6 +327,9 @@ class AbstractRefreshToken(models.Model):
318327
related_name="refresh_token"
319328
)
320329

330+
created = models.DateTimeField(auto_now_add=True)
331+
updated = models.DateTimeField(auto_now=True)
332+
321333
def revoke(self):
322334
"""
323335
Delete this refresh token along with related access token

0 commit comments

Comments
 (0)