Skip to content

Commit

Permalink
Merge pull request #771 from cortex-lab/fix-autoname
Browse files Browse the repository at this point in the history
Fix failing autoname when new nickname already exists
  • Loading branch information
rossant authored Jan 25, 2023
2 parents b118cc0 + dacd33c commit 125a7a5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion alyx/subjects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,11 @@ def new_litter_autoname(self):
def new_subject_autoname(self):
self.subject_autoname_index = self.subject_autoname_index + 1
self.save()
return '%s_%04d' % (self.nickname, self.subject_autoname_index)
new_name = '%s_%04d' % (self.nickname, self.subject_autoname_index)
if Subject.objects.filter(nickname=new_name).count() > 0:
return self.new_subject_autoname()
assert Subject.objects.filter(nickname=new_name).count() == 0
return new_name

def set_autoname(self, obj):
if isinstance(obj, BreedingPair):
Expand Down

0 comments on commit 125a7a5

Please sign in to comment.