Skip to content

Commit

Permalink
replace save method by get_or_create for dictionary items
Browse files Browse the repository at this point in the history
don't create it if it already exist
  • Loading branch information
clavay authored and trombastic committed Oct 16, 2023
1 parent 67187cf commit 20961c6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyscada/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,9 @@ def convert_string_value(self, value):
max_value = 0
for di in self.dictionary.dictionaryitem_set.all():
max_value = max(float(max_value), float(di.value))
DictionaryItem(
DictionaryItem.objects.get_or_create(
label=str(value), value=int(max_value) + 1, dictionary=self.dictionary
).save()
)
# logger.debug('new value : %s' % (int(max_value) + 1))
return int(max_value) + 1
elif len(self.dictionary.dictionaryitem_set.filter(label=str(value))) == 1:
Expand Down Expand Up @@ -1760,11 +1760,11 @@ def convert_string_value(self, value):
max_value = 0
for di in self.dictionary.dictionaryitem_set.all():
max_value = max(float(max_value), float(di.value))
DictionaryItem(
DictionaryItem.objects.get_or_create(
label=str(value),
value=int(max_value) + 1,
dictionary=self.dictionary,
).save()
)
# logger.debug('new value : %s' % (int(max_value) + 1))
return int(max_value) + 1
elif len(self.dictionary.dictionaryitem_set.filter(label=str(value))) == 1:
Expand Down

0 comments on commit 20961c6

Please sign in to comment.