I have an application using Django Rest Framework and a ListModelView for a model which I basically need to filter for in a MongoDB. The call for MongoDB is made in a model method of the model and referenced as a SerializerMethodField in the serializer. So when requesting the list endpoint there are n calls to the MongoDB. However I would love to make this more efficient by only using one call. Is this somehow possible?

class Model(models.Model):
    def get_topics(self):
        return self.gateway.get_mongo_collection().distinct('topic', {"topic": {"$regex": '^' + self.gen_topic()}})


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.