diff options
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/chimere/models.py b/chimere/models.py index 6b0d4b3..445221b 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -1255,14 +1255,11 @@ def area_post_save(sender, **kwargs): perm = Permission.objects.filter(codename=mnemo) lbl = "Can change " + area.name if not perm.count(): - try: - content_type = ContentType.objects.get(app_label="chimere", - model="area") - perm = Permission(name=lbl, content_type_id=content_type.id, - codename=mnemo) - perm.save() - except ObjectDoesNotExist: - pass + content_type, created = ContentType.objects.get_or_create( + app_label="chimere", model="area") + perm = Permission(name=lbl, content_type_id=content_type.id, + codename=mnemo) + perm.save() else: perm = perm.all()[0] if old_name != area.name: @@ -1286,10 +1283,8 @@ def area_post_save(sender, **kwargs): ('chimere', 'multimediafile'), ('chimere', 'picturefile'), ('chimere', 'routefile')): - ct = ContentType.objects.filter(app_label=app_label, model=model) - if not ct.count(): - continue - ct = ct.all()[0] + ct, created = ContentType.objects.get_or_create(app_label=app_label, + model=model) for p in Permission.objects.filter(content_type=ct).all(): group.permissions.add(p) |