From 55b86bdac8a9871848eb54cf50b285979eaaae8c Mon Sep 17 00:00:00 2001 From: j Date: Tue, 20 Nov 2018 16:15:08 +0100 Subject: [PATCH] use get_or_create(defaults...) --- pandora/annotation/models.py | 5 +---- pandora/app/views.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 333aaf0f9..470af3580 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -270,10 +270,7 @@ class Annotation(models.Model): from translation.models import Translation layer = self.get_layer() if layer.get('translate'): - t, created = Translation.objects.get_or_create(lang=lang, key=self.value) - if created: - t.type = Translation.CONTENT - t.save() + Translation.objects.get_or_create(lang=lang, key=self.value, defaults={'type': Translation.CONTENT}) def delete(self, *args, **kwargs): with transaction.atomic(): diff --git a/pandora/app/views.py b/pandora/app/views.py index c0da9ede3..8bd0fbfa2 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -118,10 +118,7 @@ def getPage(request, data): name = data else: name = data['name'] - page, created = models.Page.objects.get_or_create(name=name) - if created: - page.text = '' - page.save() + page, created = models.Page.objects.get_or_create(name=name, defaults={'text': ''}) response = json_response({'name': page.name, 'text': page.text}) return render_to_json_response(response) actions.register(getPage)