use get_or_create(defaults...)
This commit is contained in:
parent
e2ea4e3aab
commit
55b86bdac8
2 changed files with 2 additions and 8 deletions
|
@ -270,10 +270,7 @@ class Annotation(models.Model):
|
||||||
from translation.models import Translation
|
from translation.models import Translation
|
||||||
layer = self.get_layer()
|
layer = self.get_layer()
|
||||||
if layer.get('translate'):
|
if layer.get('translate'):
|
||||||
t, created = Translation.objects.get_or_create(lang=lang, key=self.value)
|
Translation.objects.get_or_create(lang=lang, key=self.value, defaults={'type': Translation.CONTENT})
|
||||||
if created:
|
|
||||||
t.type = Translation.CONTENT
|
|
||||||
t.save()
|
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
|
|
|
@ -118,10 +118,7 @@ def getPage(request, data):
|
||||||
name = data
|
name = data
|
||||||
else:
|
else:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
page, created = models.Page.objects.get_or_create(name=name)
|
page, created = models.Page.objects.get_or_create(name=name, defaults={'text': ''})
|
||||||
if created:
|
|
||||||
page.text = ''
|
|
||||||
page.save()
|
|
||||||
response = json_response({'name': page.name, 'text': page.text})
|
response = json_response({'name': page.name, 'text': page.text})
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(getPage)
|
actions.register(getPage)
|
||||||
|
|
Loading…
Reference in a new issue