How to create view from External http request json and Internal Database using Django Rest FrameworkDjango REST Framework can't show translatable fieldsmongoengine and django rest framework - fields aren't allowed to be optionalHow to save a nested relationship in django rest framework?django rest framework - request context key errorDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerDjango Rest Framework: Function Based API serializersDjango Rest Framework doesn't render generics.ListAPIView, model with GM2MFieldDjango Rest Framework get serializer of different model?Pass variable (non-model-field) to serializer in django rest frameworkHow to check if Django Signal works?

Is it possible to use .desktop files to open local pdf files on specific pages with a browser?

Gibbs free energy in standard state vs. equilibrium

Should I install hardwood flooring or cabinets first?

Proof of Lemma: Every nonzero integer can be written as a product of primes

Journal losing indexing services

Greco-Roman egalitarianism

Should I stop contributing to retirement accounts?

Do Legal Documents Require Signing In Standard Pen Colors?

If a character with the Alert feat rolls a crit fail on their Perception check, are they surprised?

What is this type of notehead called?

How will losing mobility of one hand affect my career as a programmer?

Is it better practice to read straight from sheet music rather than memorize it?

We have a love-hate relationship

Can somebody explain Brexit in a few child-proof sentences?

Greatest common substring

Bob has never been a M before

Is a model fitted to data or is data fitted to a model?

When quoting, must I also copy hyphens used to divide words that continue on the next line?

Difference between -| and |- in TikZ

Is XSS in canonical link possible?

Does having a TSA Pre-Check member in your flight reservation increase the chances that everyone gets Pre-Check?

Have I saved too much for retirement so far?

How do I extrude a face to a single vertex

Why did the EU agree to delay the Brexit deadline?



How to create view from External http request json and Internal Database using Django Rest Framework


Django REST Framework can't show translatable fieldsmongoengine and django rest framework - fields aren't allowed to be optionalHow to save a nested relationship in django rest framework?django rest framework - request context key errorDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerDjango Rest Framework: Function Based API serializersDjango Rest Framework doesn't render generics.ListAPIView, model with GM2MFieldDjango Rest Framework get serializer of different model?Pass variable (non-model-field) to serializer in django rest frameworkHow to check if Django Signal works?













1















I need to combine external json using request and Internal Database, But the condition is when someone call API we need to get empidlong from Model for call external API from specific URL, Then external API will return JSON and i need to merge this JSON with my json that create by Django REST API Framework



Here is my code



models.py :



from django.db import models
import requests
from django.core.files import File
from urllib import request
import os


# Create your models here.
class getData(models.Model):
company = models.CharField(max_length=150)
description = models.CharField(max_length=150)
period = models.CharField(max_length=150)
plate_no = models.CharField(max_length=150, primary_key=True)
project_code = models.CharField(max_length=150)
costcenter = models.CharField(max_length=150)
empidlong = models.CharField(max_length=150)

class Meta:
db_table = 'car_information'


serializers.py



from rest_framework import serializers
from .models import getData


class CarSerializer(serializers.ModelSerializer):
class Meta:
model = getData
fields = "__all__"


views.py



from django.shortcuts import render

from rest_framework import viewsets, filters
from .models import getData
from .serializers import CarSerializer

import requests


class CarViewSet(viewsets.ModelViewSet):
queryset = getData.objects.all()
serializer_class = CarSerializer
filter_backends = (filters.SearchFilter,)
#search_fields = ('plate_no')
__basic_fields = ('plate_no',)
search_fields = __basic_fields

serializer = CarSerializer(queryset, many=True)
data = serializer.data
for a in data:
empid= a['empidlong']
r = requests.get('http://192.168.10.32/Employees/'+empid)


def get_queryset(self):
queryset = getData.objects.all()
emp = self.request.query_params.get('emp', None)
if emp is not None:
queryset = queryset.filter(empidlong=emp)

return queryset


I have no idea how to do it. I stuck this for week.
Thank in advance.










share|improve this question




























    1















    I need to combine external json using request and Internal Database, But the condition is when someone call API we need to get empidlong from Model for call external API from specific URL, Then external API will return JSON and i need to merge this JSON with my json that create by Django REST API Framework



    Here is my code



    models.py :



    from django.db import models
    import requests
    from django.core.files import File
    from urllib import request
    import os


    # Create your models here.
    class getData(models.Model):
    company = models.CharField(max_length=150)
    description = models.CharField(max_length=150)
    period = models.CharField(max_length=150)
    plate_no = models.CharField(max_length=150, primary_key=True)
    project_code = models.CharField(max_length=150)
    costcenter = models.CharField(max_length=150)
    empidlong = models.CharField(max_length=150)

    class Meta:
    db_table = 'car_information'


    serializers.py



    from rest_framework import serializers
    from .models import getData


    class CarSerializer(serializers.ModelSerializer):
    class Meta:
    model = getData
    fields = "__all__"


    views.py



    from django.shortcuts import render

    from rest_framework import viewsets, filters
    from .models import getData
    from .serializers import CarSerializer

    import requests


    class CarViewSet(viewsets.ModelViewSet):
    queryset = getData.objects.all()
    serializer_class = CarSerializer
    filter_backends = (filters.SearchFilter,)
    #search_fields = ('plate_no')
    __basic_fields = ('plate_no',)
    search_fields = __basic_fields

    serializer = CarSerializer(queryset, many=True)
    data = serializer.data
    for a in data:
    empid= a['empidlong']
    r = requests.get('http://192.168.10.32/Employees/'+empid)


    def get_queryset(self):
    queryset = getData.objects.all()
    emp = self.request.query_params.get('emp', None)
    if emp is not None:
    queryset = queryset.filter(empidlong=emp)

    return queryset


    I have no idea how to do it. I stuck this for week.
    Thank in advance.










    share|improve this question


























      1












      1








      1








      I need to combine external json using request and Internal Database, But the condition is when someone call API we need to get empidlong from Model for call external API from specific URL, Then external API will return JSON and i need to merge this JSON with my json that create by Django REST API Framework



      Here is my code



      models.py :



      from django.db import models
      import requests
      from django.core.files import File
      from urllib import request
      import os


      # Create your models here.
      class getData(models.Model):
      company = models.CharField(max_length=150)
      description = models.CharField(max_length=150)
      period = models.CharField(max_length=150)
      plate_no = models.CharField(max_length=150, primary_key=True)
      project_code = models.CharField(max_length=150)
      costcenter = models.CharField(max_length=150)
      empidlong = models.CharField(max_length=150)

      class Meta:
      db_table = 'car_information'


      serializers.py



      from rest_framework import serializers
      from .models import getData


      class CarSerializer(serializers.ModelSerializer):
      class Meta:
      model = getData
      fields = "__all__"


      views.py



      from django.shortcuts import render

      from rest_framework import viewsets, filters
      from .models import getData
      from .serializers import CarSerializer

      import requests


      class CarViewSet(viewsets.ModelViewSet):
      queryset = getData.objects.all()
      serializer_class = CarSerializer
      filter_backends = (filters.SearchFilter,)
      #search_fields = ('plate_no')
      __basic_fields = ('plate_no',)
      search_fields = __basic_fields

      serializer = CarSerializer(queryset, many=True)
      data = serializer.data
      for a in data:
      empid= a['empidlong']
      r = requests.get('http://192.168.10.32/Employees/'+empid)


      def get_queryset(self):
      queryset = getData.objects.all()
      emp = self.request.query_params.get('emp', None)
      if emp is not None:
      queryset = queryset.filter(empidlong=emp)

      return queryset


      I have no idea how to do it. I stuck this for week.
      Thank in advance.










      share|improve this question
















      I need to combine external json using request and Internal Database, But the condition is when someone call API we need to get empidlong from Model for call external API from specific URL, Then external API will return JSON and i need to merge this JSON with my json that create by Django REST API Framework



      Here is my code



      models.py :



      from django.db import models
      import requests
      from django.core.files import File
      from urllib import request
      import os


      # Create your models here.
      class getData(models.Model):
      company = models.CharField(max_length=150)
      description = models.CharField(max_length=150)
      period = models.CharField(max_length=150)
      plate_no = models.CharField(max_length=150, primary_key=True)
      project_code = models.CharField(max_length=150)
      costcenter = models.CharField(max_length=150)
      empidlong = models.CharField(max_length=150)

      class Meta:
      db_table = 'car_information'


      serializers.py



      from rest_framework import serializers
      from .models import getData


      class CarSerializer(serializers.ModelSerializer):
      class Meta:
      model = getData
      fields = "__all__"


      views.py



      from django.shortcuts import render

      from rest_framework import viewsets, filters
      from .models import getData
      from .serializers import CarSerializer

      import requests


      class CarViewSet(viewsets.ModelViewSet):
      queryset = getData.objects.all()
      serializer_class = CarSerializer
      filter_backends = (filters.SearchFilter,)
      #search_fields = ('plate_no')
      __basic_fields = ('plate_no',)
      search_fields = __basic_fields

      serializer = CarSerializer(queryset, many=True)
      data = serializer.data
      for a in data:
      empid= a['empidlong']
      r = requests.get('http://192.168.10.32/Employees/'+empid)


      def get_queryset(self):
      queryset = getData.objects.all()
      emp = self.request.query_params.get('emp', None)
      if emp is not None:
      queryset = queryset.filter(empidlong=emp)

      return queryset


      I have no idea how to do it. I stuck this for week.
      Thank in advance.







      django-rest-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 10:00







      Malody Gamor

















      asked Mar 8 at 6:43









      Malody GamorMalody Gamor

      62




      62






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Where are you expecting the json from? if from a user, you can access the json from the request. Then you can use it in your orm query. You CarViewSet seem to be doing way more than it should be. What is your goal exactly?






          share|improve this answer























          • I need to display merged API from getData Model and JSON from 192.168.10.32

            – Malody Gamor
            Mar 8 at 7:16











          • 192.168.10.32 ip has nothing.

            – Wisani Salani
            Mar 11 at 6:56










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058024%2fhow-to-create-view-from-external-http-request-json-and-internal-database-using-d%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Where are you expecting the json from? if from a user, you can access the json from the request. Then you can use it in your orm query. You CarViewSet seem to be doing way more than it should be. What is your goal exactly?






          share|improve this answer























          • I need to display merged API from getData Model and JSON from 192.168.10.32

            – Malody Gamor
            Mar 8 at 7:16











          • 192.168.10.32 ip has nothing.

            – Wisani Salani
            Mar 11 at 6:56















          0














          Where are you expecting the json from? if from a user, you can access the json from the request. Then you can use it in your orm query. You CarViewSet seem to be doing way more than it should be. What is your goal exactly?






          share|improve this answer























          • I need to display merged API from getData Model and JSON from 192.168.10.32

            – Malody Gamor
            Mar 8 at 7:16











          • 192.168.10.32 ip has nothing.

            – Wisani Salani
            Mar 11 at 6:56













          0












          0








          0







          Where are you expecting the json from? if from a user, you can access the json from the request. Then you can use it in your orm query. You CarViewSet seem to be doing way more than it should be. What is your goal exactly?






          share|improve this answer













          Where are you expecting the json from? if from a user, you can access the json from the request. Then you can use it in your orm query. You CarViewSet seem to be doing way more than it should be. What is your goal exactly?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 6:50









          Wisani SalaniWisani Salani

          244




          244












          • I need to display merged API from getData Model and JSON from 192.168.10.32

            – Malody Gamor
            Mar 8 at 7:16











          • 192.168.10.32 ip has nothing.

            – Wisani Salani
            Mar 11 at 6:56

















          • I need to display merged API from getData Model and JSON from 192.168.10.32

            – Malody Gamor
            Mar 8 at 7:16











          • 192.168.10.32 ip has nothing.

            – Wisani Salani
            Mar 11 at 6:56
















          I need to display merged API from getData Model and JSON from 192.168.10.32

          – Malody Gamor
          Mar 8 at 7:16





          I need to display merged API from getData Model and JSON from 192.168.10.32

          – Malody Gamor
          Mar 8 at 7:16













          192.168.10.32 ip has nothing.

          – Wisani Salani
          Mar 11 at 6:56





          192.168.10.32 ip has nothing.

          – Wisani Salani
          Mar 11 at 6:56



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058024%2fhow-to-create-view-from-external-http-request-json-and-internal-database-using-d%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived