Fixed IntegrityError on postgres
parent
4b055f7ffa
commit
4e0c4a00e2
|
|
@ -28,16 +28,17 @@ class Theme(models.Model):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_active_theme():
|
def get_active_theme():
|
||||||
objs_active_qs = Theme.objects.filter(active=True)
|
objs_manager = Theme.objects
|
||||||
|
objs_active_qs = objs_manager.filter(active=True)
|
||||||
objs_active_ls = list(objs_active_qs)
|
objs_active_ls = list(objs_active_qs)
|
||||||
objs_active_count = len(objs_active_ls)
|
objs_active_count = len(objs_active_ls)
|
||||||
|
|
||||||
if objs_active_count == 0:
|
if objs_active_count == 0:
|
||||||
default_obj, default_obj_created = Theme.objects.get_or_create(
|
obj = objs_manager.all().first()
|
||||||
pk='1', defaults={'active': True})
|
if obj:
|
||||||
if not default_obj_created:
|
obj.set_active()
|
||||||
default_obj.set_active()
|
else:
|
||||||
obj = default_obj
|
obj = objs_manager.create()
|
||||||
|
|
||||||
elif objs_active_count == 1:
|
elif objs_active_count == 1:
|
||||||
obj = objs_active_ls[0]
|
obj = objs_active_ls[0]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue