From e50e4c87aa7c56648c911be8f538dd913217ddd8 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 15 Jun 2010 20:09:30 +0100 Subject: [PATCH] Init the API key if it doesnt exist --- api/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/models.py b/api/models.py index 20c82f8..65e63b9 100644 --- a/api/models.py +++ b/api/models.py @@ -1,7 +1,4 @@ -import re -import unicodedata -import logging -import types +import uuid from django.db import models @@ -12,6 +9,12 @@ class AuthAPIKey(models.Model): active = models.BooleanField(default=True) key = models.CharField("API Key", max_length=200) + def save(self, *args, **kwargs): + if not key or key = '': + self.key = uuid.uuid4() + + models.Model.save(self, *args, **kwargs) + class AuthAPILog(models.Model): access_datetime = models.DateTimeField()