Given the example below, is there a more elegant solution than passing a string to allow a function to test against and in turn, run the required code?
myfunction(self, "location1")
def myfunction(self, source):
    if source == "location1":
        qs = MyModel.objects.filter(id = self.object.id)
        return qs
    elif source == "location2":
        qs = AnotherModel.objects.filter(id = self.object.id)
        return qs
    else:
        qs = YetAnotherModel.objects.filter(id = self.object.id)
        return qs
This example contains dummy Django queries, but I've had to use this solution on various Python functions throughout my projects.
 
     
     
     
    