add apis to retrieve full model data by name and id

This commit is contained in:
Kardia 2024-01-04 11:49:17 -05:00 committed by Alex Yatskov
parent 2de0798fc1
commit 50d062e6ca

View File

@ -1111,6 +1111,28 @@ class AnkiConnect:
return models
@util.api()
def findModelsById(self, modelIds):
models = []
for id in modelIds:
model = self.collection().models.get(id)
if model is None:
raise Exception("model was not found: {}".format(id))
else:
models.append(model)
return models
@util.api()
def findModelsByName(self, modelNames):
models = []
for name in modelNames:
model = self.collection().models.byName(name)
if model is None:
raise Exception("model was not found: {}".format(name))
else:
models.append(model)
return models
@util.api()
def modelNameFromId(self, modelId):
model = self.collection().models.get(modelId)