I am writing a function that can return table items based on a dynamically inserted model. So I need to refrain from using the model name in the function. Now I sometimes will have a many-to-many relationship with another model and want to select on that.
Say I have a projects = ManyToMany(Projects) field in my Files model. Now I can use:
filter(projects__in=[1])
to select for files related to projects with id 1, but I need the projects part of this filter to be dynamic, so I can use something like:
a_field = 'projects'
filter(a_field+'__in'=[1])
which obviously doesn't work. How should I do this?