Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Unique together user and alias in Userprofile

Michal Ociepka0f1675fc90ee
diff --git a/userprofile/migrations/0003_auto__add_unique_address_alias_user.py b/userprofile/migrations/0003_auto__add_unique_address_alias_user.py
new file mode 100644
index 0000000000..e047334920
--- /dev/null
+++ b/userprofile/migrations/0003_auto__add_unique_address_alias_user.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding unique constraint on 'Address', fields ['alias', 'user']
+ db.create_unique(u'userprofile_address', ['alias', 'user_id'])
+
+
+ def backwards(self, orm):
+ # Removing unique constraint on 'Address', fields ['alias', 'user']
+ db.delete_unique(u'userprofile_address', ['alias', 'user_id'])
+
+
+ models = {
+ u'userprofile.address': {
+ 'Meta': {'unique_together': "(('user', 'alias'),)", 'object_name': 'Address'},
+ 'alias': ('django.db.models.fields.CharField', [], {'default': "u'Home'", 'max_length': '30'}),
+ 'city': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'company_name': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+ 'country_area': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'street_address_1': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'street_address_2': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'addressbook'", 'to': u"orm['userprofile.User']"})
+ },
+ u'userprofile.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'default_billing_address': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': u"orm['userprofile.Address']"}),
+ 'default_shipping_address': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': u"orm['userprofile.Address']"}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+ }
+ }
+
+ complete_apps = ['userprofile']
\ No newline at end of file
diff --git a/userprofile/models.py b/userprofile/models.py
index 8cef468de5..eaae50bbce 100644
--- a/userprofile/models.py
+++ b/userprofile/models.py
@@ -29,6 +29,10 @@ class Address(models.Model):
max_length=128)
phone = models.CharField(_('phone number'), max_length=30, blank=True)
+
+ class Meta:
+ unique_together = ('user', 'alias')
+
def __unicode__(self):
return self.alias