Commit 5a2374b0 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

fxing autofill with M2M not working due to save

parent 2765d1ea
Pipeline #10365 passed with stages
in 12 minutes and 54 seconds
......@@ -34,15 +34,26 @@ class AutoFillableModel(models.Model):
abstract = True
def save(self, *args, **kwargs):
if kwargs.get('autofill') is True or not self.is_autofill_done():
auto_fill_needed = not self.is_autofill_done()
if kwargs.get('autofill') is True or auto_fill_needed:
auto_fill_needed = True
self.autofill()
if 'autofill' in kwargs:
del kwargs['autofill']
super(AutoFillableModel, self).save(*args, **kwargs)
if auto_fill_needed:
self.autofill_post_save()
def autofill(self):
raise NotImplementedError()
def autofill_post_save(self):
"""
method called after the save is done, usefull for settings m2m relations
:return:
"""
pass
def is_autofill_done(self):
return True
......@@ -243,8 +254,10 @@ class Protein(AutoFillableModel):
taxonomy.taxonomy_id = info['organism']
taxonomy.save(autofill=True)
self.organism = taxonomy
super(Protein, self).save()
self.__info = info
def autofill_post_save(self):
info = self.__info
for go_id in info['molecular_functions']:
mol_function, created = MolecularFunction.objects.get_or_create(go_id=go_id)
self.molecular_functions.add(mol_function)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment