From 1c56ed5dbcef8f3bd7e6198d4195c5286bebedc7 Mon Sep 17 00:00:00 2001 From: Danny Browne Date: Fri, 4 Sep 2015 12:58:32 -0400 Subject: [PATCH 1/2] added database-level enforcement of unique user+primary pair in Avatar model --- avatar/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/avatar/models.py b/avatar/models.py index 1463df0..e7127ff 100644 --- a/avatar/models.py +++ b/avatar/models.py @@ -72,6 +72,7 @@ class Avatar(models.Model): class Meta: app_label = 'avatar' + unique_together = ('user', 'primary') def __unicode__(self): return _(six.u('Avatar for %s')) % self.user From 00cc973d477a96c73665815c6a19755301c0e0b2 Mon Sep 17 00:00:00 2001 From: Danny Browne Date: Fri, 4 Sep 2015 13:14:14 -0400 Subject: [PATCH 2/2] added django migration --- .../0002_add_user_primary_unique_together.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 avatar/migrations/0002_add_user_primary_unique_together.py diff --git a/avatar/migrations/0002_add_user_primary_unique_together.py b/avatar/migrations/0002_add_user_primary_unique_together.py new file mode 100755 index 0000000..c9bfb35 --- /dev/null +++ b/avatar/migrations/0002_add_user_primary_unique_together.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('avatar', '0001_initial'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='avatar', + unique_together=set([('user', 'primary')]), + ), + ]