diff --git a/pgweb/account/models.py b/pgweb/account/models.py index 31832fd6..f4f3e9bf 100644 --- a/pgweb/account/models.py +++ b/pgweb/account/models.py @@ -15,7 +15,7 @@ class CommunityAuthSite(models.Model): return self.name class EmailChangeToken(models.Model): - user = models.ForeignKey(User, null=False, blank=False, unique=True) + user = models.OneToOneField(User, null=False, blank=False) email = models.EmailField(max_length=75, null=False, blank=False) token = models.CharField(max_length=100, null=False, blank=False) sentat = models.DateTimeField(null=False, blank=False, auto_now=True) diff --git a/pgweb/core/models.py b/pgweb/core/models.py index 07209eec..a92565f8 100644 --- a/pgweb/core/models.py +++ b/pgweb/core/models.py @@ -2,8 +2,6 @@ from django.db import models from django.contrib.auth.models import User from pgweb.util.misc import varnish_purge -from datetime import datetime - TESTING_CHOICES = ( (0, 'Release'), (1, 'Release candidate'), @@ -121,7 +119,7 @@ class Organisation(models.Model): phone = models.CharField(max_length=100, null=False, blank=True) orgtype = models.ForeignKey(OrganisationType, null=False, blank=False, verbose_name="Organisation type") managers = models.ManyToManyField(User, null=False, blank=False) - lastconfirmed = models.DateTimeField(null=False, blank=False, default=datetime.now()) + lastconfirmed = models.DateTimeField(null=False, blank=False, auto_now_add=True) send_notification = True @@ -161,7 +159,7 @@ class ImportedRSSItem(models.Model): # Extra attributes for users (if they have them) class UserProfile(models.Model): - user = models.ForeignKey(User, null=False, blank=False, unique=True, primary_key=True) + user = models.OneToOneField(User, null=False, blank=False, primary_key=True) sshkey = models.TextField(null=False, blank=True, verbose_name="SSH key", help_text= "Paste one or more public keys in OpenSSH format, one per line.") lastmodified = models.DateTimeField(null=False, blank=False, auto_now=True) diff --git a/pgweb/docs/models.py b/pgweb/docs/models.py index 8c8132be..dc044177 100644 --- a/pgweb/docs/models.py +++ b/pgweb/docs/models.py @@ -2,8 +2,6 @@ from django.db import models from django.contrib.auth.models import User from pgweb.core.models import Version -from datetime import datetime - class DocPage(models.Model): id = models.AutoField(null=False, primary_key=True) file = models.CharField(max_length=64, null=False, blank=False) @@ -27,7 +25,7 @@ class DocComment(models.Model): version = models.DecimalField(max_digits=3, decimal_places=1, null=False) file = models.CharField(max_length=64, null=False, blank=False) comment = models.TextField(null=False, blank=False) - posted_at = models.DateTimeField(null=False, blank=False, default=datetime.now()) + posted_at = models.DateTimeField(null=False, blank=False, auto_now_add=True) submitter = models.ForeignKey(User, null=False) approved = models.BooleanField(blank=False, default=False) diff --git a/pgweb/downloads/models.py b/pgweb/downloads/models.py index 961e142e..b4f69335 100644 --- a/pgweb/downloads/models.py +++ b/pgweb/downloads/models.py @@ -7,10 +7,10 @@ from datetime import datetime class Mirror(models.Model): country_name = models.CharField(max_length=50, null=False, blank=False) country_code = models.CharField(max_length=2, null=False, blank=False) - mirror_created = models.DateTimeField(null=False, blank=False, default=datetime.now()) + mirror_created = models.DateTimeField(null=False, blank=False, auto_now_add=True) mirror_last_rsync = models.DateTimeField(null=False, blank=False, default=datetime(1970,1,1)) mirror_index = models.IntegerField(null=False) - host_addr = models.IPAddressField(null=True, default='0.0.0.0') + host_addr = models.GenericIPAddressField(null=True, default='0.0.0.0') host_path = models.CharField(max_length=100, null=True) host_sponsor = models.CharField(max_length=100, null=True) host_contact = models.CharField(max_length=100, null=True) @@ -82,7 +82,7 @@ class Product(models.Model): licencetype = models.ForeignKey(LicenceType, null=False, verbose_name="Licence type") description = models.TextField(null=False, blank=False) price = models.CharField(max_length=200, null=False, blank=True) - lastconfirmed = models.DateTimeField(null=False, blank=False, default=datetime.now()) + lastconfirmed = models.DateTimeField(null=False, blank=False, auto_now_add=True) send_notification = True markdown_fields = ('description', ) diff --git a/pgweb/profserv/models.py b/pgweb/profserv/models.py index 64b036af..fef5e49d 100644 --- a/pgweb/profserv/models.py +++ b/pgweb/profserv/models.py @@ -5,7 +5,7 @@ from pgweb.core.models import Organisation class ProfessionalService(models.Model): approved = models.BooleanField(null=False, blank=False, default=False) - org = models.ForeignKey(Organisation, null=False, blank=False, unique=True, + org = models.OneToOneField(Organisation, null=False, blank=False, db_column="organisation_id", verbose_name="organisation", help_text="If no organisations are listed, please check the organisation list and contact the organisation manager or webmaster@postgresql.org if none are listed.") diff --git a/pgweb/survey/models.py b/pgweb/survey/models.py index ac531da1..569c5b71 100644 --- a/pgweb/survey/models.py +++ b/pgweb/survey/models.py @@ -1,7 +1,5 @@ from django.db import models -from datetime import datetime - # internal text/value object class SurveyQuestion(object): def __init__(self, value, text): @@ -23,7 +21,7 @@ class Survey(models.Model): opt6 = models.CharField(max_length=500, null=False, blank=True) opt7 = models.CharField(max_length=500, null=False, blank=True) opt8 = models.CharField(max_length=500, null=False, blank=True) - posted = models.DateTimeField(null=False, default=datetime.now) + posted = models.DateTimeField(null=False, auto_now_add=True) current = models.BooleanField(null=False, default=False) purge_urls = ('/community/survey', ) @@ -80,7 +78,7 @@ class Survey(models.Model): super(Survey, self).save() class SurveyAnswer(models.Model): - survey = models.ForeignKey(Survey, null=False, blank=False, primary_key=True) + survey = models.OneToOneField(Survey, null=False, blank=False, primary_key=True) tot1 = models.IntegerField(null=False, default=0) tot2 = models.IntegerField(null=False, default=0) tot3 = models.IntegerField(null=False, default=0) @@ -93,6 +91,6 @@ class SurveyAnswer(models.Model): purge_urls = ('/community/survey', ) class SurveyLock(models.Model): - ipaddr = models.IPAddressField(null=False, blank=False) - time = models.DateTimeField(null=False, default=datetime.now) + ipaddr = models.GenericIPAddressField(null=False, blank=False) + time = models.DateTimeField(null=False, auto_now_add=True)