Commits

Anonymous committed fb23e01

use get_or_create in add_to

  • Participants
  • Parent commits d07eadd

Comments (0)

Files changed (1)

File djangotoolbox/auth/utils.py

 from djangotoolbox.auth.models import UserPermissionList, GroupPermissionList, GroupList
 
 def add_to(obj, list_cls, filter):
-    try:
-        obj_list = list_cls.objects.get(**filter)
-    except list_cls.DoesNotExist:
-        obj_list = list_cls.objects.create(**filter)
+    obj_list, created = list_cls.objects.get_or_create(**filter)
 
     obj_list._fk_list.append(obj.id)
     obj_list.save()