allow only one mailbox for a mailaddress

- add migration to place a unique constraint on MailAddressMailbox.mailaddress
  and drop existing primary_key
- change managemails.models.MailAddressMailbox.mailaddress to OneToOneField
This commit is contained in:
Jan Dittberner 2014-05-24 20:57:17 +02:00
parent ee46a61e6d
commit d5e1128ff6
2 changed files with 59 additions and 1 deletions

View file

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
# pymode:lint_ignore=E501
from south.db import db
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'MailAddressMailbox.id'
db.delete_column(u'managemails_mailaddressmailbox', u'id')
# Changing field 'MailAddressMailbox.mailaddress'
db.alter_column(u'managemails_mailaddressmailbox', 'mailaddress_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['managemails.MailAddress'], unique=True, primary_key=True))
# Adding unique constraint on 'MailAddressMailbox', fields ['mailaddress']
db.create_unique(u'managemails_mailaddressmailbox', ['mailaddress_id'])
def backwards(self, orm):
# User chose to not deal with backwards NULL issues for 'MailAddressMailbox.id'
raise RuntimeError("Cannot reverse this migration. 'MailAddressMailbox.id' and its values cannot be restored.")
models = {
u'managemails.mailaddress': {
'Meta': {'unique_together': "(('localpart', 'domain'),)", 'object_name': 'MailAddress'},
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailDomain']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'localpart': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
u'managemails.mailaddressforward': {
'Meta': {'unique_together': "(('mailaddress', 'target'),)", 'object_name': 'MailAddressForward'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'mailaddress': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailAddress']"}),
'target': ('django.db.models.fields.EmailField', [], {'max_length': '254'})
},
u'managemails.mailaddressmailbox': {
'Meta': {'unique_together': "(('mailaddress', 'mailbox'),)", 'object_name': 'MailAddressMailbox'},
'mailaddress': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['managemails.MailAddress']", 'unique': 'True', 'primary_key': 'True'}),
'mailbox': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.Mailbox']"})
},
u'managemails.mailbox': {
'Meta': {'object_name': 'Mailbox'},
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
'home': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'})
},
u'managemails.maildomain': {
'Meta': {'object_name': 'MailDomain'},
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['managemails']

View file

@ -61,7 +61,7 @@ class MailAddress(ActivateAbleMixin, models.Model):
class MailAddressMailbox(models.Model):
mailaddress = models.ForeignKey(MailAddress)
mailaddress = models.OneToOneField(MailAddress, primary_key=True)
mailbox = models.ForeignKey(Mailbox)
class Meta: