use get_or_create(defaults...)

This commit is contained in:
j 2018-11-20 16:15:08 +01:00
parent e2ea4e3aab
commit 55b86bdac8
2 changed files with 2 additions and 8 deletions

View file

@ -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():

View file

@ -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)