#StackBounty: #python #django #mongodb #django-rest-framework #django-views Django Rest Framework not retrieving data from my database

Bounty: 50

I’m creating an API endpoint to retrieve data from a Mongo database, in order to use it on my frontend.

On my project, i’m using two DBs: a sqlite db and the Mongo DB.

In the Mongo database, there is a collection called tst with some data in it. I created the endpoint, but after opening the api on my browser, i see no json data retrieved from the collection, as if it’s not looking in the right place.

Can someone help me find what i’m doing wrong?

Here is my model:

class tst(models.Model):
    id = models.CharField(max_length=100)
    ticker = models.FloatField()

    def save(self, *args, using=None, **kwargs):
        super(tst, self).save(*args, using='dbtwo', **kwargs)

Here is my view:

class tstList(generics.ListCreateAPIView):
    queryset = tst.objects.using('dbtwo').all()
    serializer_class = tstSerializer

Here is the serializer:

class tstSerializer(serializers.ModelSerializer):

    class Meta:
        model = tst
        fields = ('id', 'ticker', )

And the url:

path('tst/', views.tstList.as_view()),


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.