Posts

Showing posts from October, 2021

Django Rest Framework Many To Many Relation with intermediate Table Serialization Example

Here, MLmodel and prediction models have not relationship class PredictionSerializer(serializers.ModelSerializer): prediction_result = PredictionResultSerializer(many=True, read_only=True) prediction_algorithms = serializers.SerializerMethodField() class Meta: model = Prediction fields = '__all__' def get_prediction_algorithms(self, mlmodel_instance): predmodel_query = PredModel.objects.filter(prediction=mlmodel_instance) pred_model_list = [ModelPredSerializer( model).data for model in predmodel_query] mlmodel = [] for ml in pred_model_list: alg = MlModel.objects.get(id=ml['model']) algo_dic = {"id": alg.id, "model_short_name": alg.model_short_name, "model_name": alg.model_name, "model_type": alg.model_type} mlmodel.append(algo_dic) return mlmodel Django Rest Framework Many To Many Inter...