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_queryset
in yourtstList
, print the queryset and see if it includes any data:print(self.queryset)
– yofee Jul 14 '19 at 20:19tst
objects in yourdbtwo
database? – Stevy Jul 14 '19 at 22:20