From b7bdbc354d82baa0f7ee92e65470479fa109b60c Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Sun, 20 Sep 2015 18:50:56 +0200 Subject: [PATCH] Start making things work, with unique_together instead of CompositeField --- database/platal/models.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/database/platal/models.py b/database/platal/models.py index 7ef05e4..3345d76 100644 --- a/database/platal/models.py +++ b/database/platal/models.py @@ -23,9 +23,12 @@ Latest version synced: Plat/al 1.1.15 https://github.com/Polytechnique-org/platal/tree/xorg/maint/upgrade +cf. https://docs.djangoproject.com/en/dev/howto/legacy-databases/ + This requires Django to work. """ from __future__ import unicode_literals + import collections from django.db import models from django.utils.encoding import python_2_unicode_compatible @@ -41,13 +44,14 @@ def is_ax_visible(field): @python_2_unicode_compatible class Skin(models.Model): - #id = models.IntegerField(primary_key=True) + id = models.IntegerField(primary_key=True) name = models.CharField(max_length=96) date = models.DateField() comment = models.CharField(max_length=765) auteur = models.CharField(max_length=90) skin_tpl = models.CharField(max_length=96) ext = models.CharField(max_length=9) + class Meta: db_table = 'skins' @@ -57,9 +61,10 @@ class Skin(models.Model): @python_2_unicode_compatible class EmailVirtualDomain(models.Model): - #id = models.IntegerField(primary_key=True) + id = models.IntegerField(primary_key=True) name = models.CharField(max_length=765) aliasing = models.ForeignKey('self', db_column='aliasing') + class Meta: db_table = 'email_virtual_domains' @@ -69,8 +74,9 @@ class EmailVirtualDomain(models.Model): @python_2_unicode_compatible class ProfileSectionEnum(models.Model): - #id = models.IntegerField(primary_key=True) + id = models.IntegerField(primary_key=True) text = models.CharField(max_length=150, unique=True) + class Meta: db_table = 'profile_section_enum' @@ -94,6 +100,7 @@ class GeolocCountry(models.Model): licenseplate = models.CharField(max_length=12, db_column='licensePlate', blank=True) # Field name made lowercase. belongsto = models.ForeignKey('self', null=True, db_column='belongsTo', blank=True) # Field name made lowercase. countryplain = models.CharField(max_length=765, db_column='countryPlain', blank=True) # Field name made lowercase. + class Meta: db_table = 'geoloc_countries' @@ -110,6 +117,7 @@ class AccountType(models.Model): type = models.CharField(max_length=48, primary_key=True) perms = models.CharField(max_length=321) description = models.TextField(blank=True) + class Meta: db_table = 'account_types' @@ -145,6 +153,7 @@ class Account(models.Model): best_domain = models.ForeignKey(EmailVirtualDomain, null=True, db_column='best_domain', blank=True) from_email = models.CharField(max_length=765) from_format = models.CharField(max_length=12) + class Meta: db_table = 'accounts' @@ -395,10 +404,11 @@ class Profile(models.Model): class AccountProfile(models.Model): account = models.ForeignKey(Account, db_column='uid', related_name='profiles') profile = models.ForeignKey(Profile, db_column='pid', related_name='accounts') - pkey = models.CompositeField(account, profile, primary_key=True) perms = models.CharField(max_length=15) + class Meta: db_table = 'account_profiles' + unique_together = (('uid', 'pid'),) def __str__(self): return '%s -> %s' % (self.account.hruid, self.profile.hrpid) @@ -413,6 +423,7 @@ class AccountAuthOpenid(models.Model): #id = models.IntegerField(primary_key=True) account = models.ForeignKey(Account, unique=True, null=True, db_column='uid', blank=True) url = models.CharField(max_length=255, unique=True) + class Meta: db_table = 'account_auth_openid' @@ -424,6 +435,7 @@ class AccountLostPassword(models.Model): certificat = models.CharField(max_length=96, primary_key=True) account = models.ForeignKey(Account, null=True, db_column='uid', blank=True) created = models.DateTimeField(null=True, blank=True) + class Meta: db_table = 'account_lost_passwords' @@ -436,6 +448,7 @@ class AccountXnetLostPassword(models.Model): account = models.ForeignKey(Account, primary_key=True, db_column='uid') date = models.DateTimeField(null=True, blank=True) hash = models.CharField(max_length=96) + class Meta: db_table = 'account_xnet_lost_passwords' @@ -460,7 +473,8 @@ class Announce(models.Model): flags = models.CharField(max_length=87) noinvite = models.IntegerField() post_id = models.IntegerField(null=True, blank=True, editable=False, - help_text=u"NNTP post identifier") + help_text="NNTP post identifier") + class Meta: db_table = 'announces' @@ -475,6 +489,7 @@ class AnnouncePhoto(models.Model): attach = models.TextField() x = models.IntegerField() y = models.IntegerField() + class Meta: db_table = 'announce_photos' @@ -486,9 +501,10 @@ class AnnouncePhoto(models.Model): class AnnounceRead(models.Model): evt = models.ForeignKey(Announce) account = models.ForeignKey(Account, db_column='uid') - pkey = models.CompositeField(evt, account, primary_key=True) + class Meta: db_table = 'announce_read' + unique_together = (('evt', 'uid'),) def __str__(self): return "%s: %s" % (self.account, self.evt) @@ -502,12 +518,13 @@ class AnnounceRead(models.Model): class EmailVirtual(models.Model): email = models.CharField(max_length=255) domain = models.ForeignKey(EmailVirtualDomain, db_column='domain') - pkey = models.CompositeField(email, domain, primary_key=True) redirect = models.CharField(max_length=765) type = models.CharField(max_length=21, blank=True) expire = models.DateField() + class Meta: db_table = 'email_virtual' + unique_together = (('email', 'domain'),) def __str__(self): return "%s@%s (%s)" % (self.email, self.domain, self.type) @@ -517,7 +534,6 @@ class EmailVirtual(models.Model): class EmailRedirectAccount(models.Model): account = models.ForeignKey(Account, db_column='uid') redirect = models.CharField(max_length=765) - pkey = models.CompositeField(account, redirect, primary_key=True) rewrite = models.CharField(max_length=765) type = models.CharField(max_length=30) action = models.CharField(max_length=54) @@ -527,8 +543,10 @@ class EmailRedirectAccount(models.Model): flags = models.CharField(max_length=24) hash = models.CharField(max_length=96, blank=True) allow_rewrite = models.BooleanField() + class Meta: db_table = 'email_redirect_account' + unique_together = (('uid', 'redirect'),) def __str__(self): return "%s for %s (%s)" % (self.redirect, self.account.hruid, self.type) -- 2.1.4