Posts

Setting Up PostgreSQL Database for a Django Project

Setting Up PostgreSQL Database for Django Project on Ubuntu  Follow these steps to configure a PostgreSQL database for your Django project on an Ubuntu server. This guide ensures that the database setup aligns with Blocksport.com’s project standards. 1. Access PostgreSQL Open a terminal on your Ubuntu server and enter the PostgreSQL shell: sudo -u postgres psql You may be prompted to provide the system's admin password. 2. List Existing Databases To verify existing databases, use: \l Press q to exit the list and return to the PostgreSQL shell. 3. Create a New Database Create a dedicated database for the Django project: CREATE DATABASE blocksport_tenant; 4. Create a Database User Define a new user for database access and assign a secure password: CREATE USER blocksport_tenant WITH PASSWORD 'blocksport_password'; Replace 'blocksport_password' with a strong password for security. 5. Connect to the Database Switch to the newly created database: \c blocksport_tenant Th...

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...