Commit 80d0d8f5 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

Fix duplication issue

parent 42e87b5c
Pipeline #17339 passed with stage
in 37 seconds
......@@ -55,10 +55,19 @@ class UserPreferencesAbstractModel(models.Model):
def get_for_user(cls, user):
try:
pref = cls.objects.get(user=user)
except cls.MultipleObjectsReturned:
for p in cls.objects.filter(user=None)[1:]:
p.delete()
pref = cls.objects.get(user=user)
except TypeError:
return cls.get_for_user(None)
except cls.DoesNotExist:
pref, _ = cls.objects.get_or_create(user=None)
try:
pref, _ = cls.objects.get_or_create(user=None)
except cls.MultipleObjectsReturned:
for p in cls.objects.filter(user=None)[1:]:
p.delete()
pref, _ = cls.objects.get(user=None)
if user is not None:
pref.pk = None
pref.id = None
......
......@@ -7,7 +7,7 @@ readme = open('README.rst').read()
setup(
name='django-basetheme-bootstrap',
version='0.2.26',
version='0.2.27',
description='Django Basetheme Bootstrap',
long_description=readme,
author='Bryan Brancotte',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment