From ce3e58f70c1b9129ce16afa667ebca8e4ec5b010 Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Thu, 28 May 2015 10:42:10 -0400 Subject: [PATCH] fix(models):make user and token unique --- push_notifications/__init__.py | 2 +- .../migrations/0002_auto_20150528_1115.py | 18 ++++++++++++++++++ push_notifications/models.py | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 push_notifications/migrations/0002_auto_20150528_1115.py diff --git a/push_notifications/__init__.py b/push_notifications/__init__.py index 8ce9b36..7525d19 100644 --- a/push_notifications/__init__.py +++ b/push_notifications/__init__.py @@ -1 +1 @@ -__version__ = '0.1.3' +__version__ = '0.1.4' diff --git a/push_notifications/migrations/0002_auto_20150528_1115.py b/push_notifications/migrations/0002_auto_20150528_1115.py new file mode 100644 index 0000000..05059ff --- /dev/null +++ b/push_notifications/migrations/0002_auto_20150528_1115.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('push_notifications', '0001_initial'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='pushdevice', + unique_together=set([('user', 'token')]), + ), + ] diff --git a/push_notifications/models.py b/push_notifications/models.py index bc6b43b..d6248af 100644 --- a/push_notifications/models.py +++ b/push_notifications/models.py @@ -55,6 +55,9 @@ class PushDevice(models.Model): objects = PushDeviceManager() + class Meta: + unique_together = ('user', 'token') + def add_permissions(self, notice_types): """ Adds a permission to the push device """ PushDevice.change_permissions(notice_types, self, send=True)