I have the following error how can I solve it?
the model is:
class myModel(models.Model): name = models.CharField(max_length=50) libraries = models.ManyToManyField(library)and on the endpoint like this:
new_obj = myModel.objects.create(name=name) my_obj.libraries.add(Library.objects.filter(pk=l.pk) for l in input_libraries.get('libraries'))You are trying to save a generator in an add which is to add a single element.
A generator object in python is something like a lazy list. Elements are only evaluated as soon as you iterate over them.
so to solve it use set()
my_obj.libraries.set(Library.objects.filter(pk=l.pk) for l in input_libraries.get('libraries'))