I have two routes in my api looking like that :
http://mywebsite/websites/website_1/annonces/http://mywebsite/websites/website_2/annonces/
I need to make an ListAPIView merging these 2 routes but each route call its own database.
The two databases are made with the same django Model. I made two databases because it suits my architecture better.
The problem is that I have no column in my databases which indicates the website the records are from. The records are only differentiated by the names of their database.
I want to get all record in a single route but also being able to tell from which database they are from in the json response.
class Annonce(models.Model):
annonce_type = models.CharField(max_length=200, blank=True, null=True)
annonce_id = models.CharField(unique=True, max_length=200, blank=True, null=True)
url = models.TextField(blank=True, null=True)
region = models.TextField(blank=True, null=True)
class AnnoncesList(generics.ListAPIView):
authentication_classes = ()
permission_classes = ()
serializer_class = AnnonceListSerializer
pagination_class = LargeResultsSetPagination
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('advert_type', 'asset_type', 'sales_type', 'price', 'area', 'department', 'department_id', 'city', 'postal_code')
def get_queryset(self):
queryset = Annonce.objects.using(self.kwargs["website_name"]).all()
return queryset