I have a model class (for example A) inside the Django model framework. For this model I have created his Manager class with some functions.
class T_Manager(BaseModelManager):
def add_function(value):
....
class T(BaseModel):
objects = T_Manager()
....
class A(BaseModel):
t = GenericRelation('T', related_name='t')
....
Now I have a list of A class objects and I would like to call add_function on all of them efficiently.
I would like to use something like
list_a.update(F('add_function', value))
or something like this.
Is there a way to call this function inside the update function or what is recommended way to do this?
It is not possible to call the
add_function()method ofT_Managerclass insideupdate()method ofAmodel.To call
add_function()on allTinstances related to theAobjects you can use loop to iterate throughTobjects:or use custom manager to iterate all related
Tobjects:you can then call custom manager: