evenicoulddoit / django-rest-framework-serializer-extensions

Extensions to help DRY up Django Rest Framework serializers
Other
247 stars 23 forks source link

Not able to run this on remote server #39

Closed SadbhavanaBhardwaj closed 4 years ago

SadbhavanaBhardwaj commented 4 years ago

I'm using EC2 instance and ngrok for hosting my site(just for checking). but it is not working for me. Whenever I write ?expand=order_lines, it is not giving me the desired output. But when I implement it in my system, it is working very well. Can someone please check.

serializers.py

**from rest_framework_serializer_extensions.serializers import SerializerExtensionsMixin

class OrderLineSerializer(serializers.ModelSerializer): ad_length = serializers.IntegerField(required=False, allow_null=True) targeting = serializers.JSONField(allow_null=True, required=False)

class Meta:
    model = OrderLine
    fields = ('orderLine_id', 'orders_id', 'sales_id', 'name', 'priority', 'ad_length', 'status', 'activation_time',
              'deactivation_time', 'targeting', 'order')

class OrderSerializer(serializers.ModelSerializer):

class Meta:
    model = Order
    fields = ["order_id", "sales_id", "owner", "status", "type", "start_time", "end_time", "name", "advertiser_id", "advertiser_name", ]
    expandable_fields = dict(
        order_lines=dict(
            serializer=OrderLineSerializer,
            many=True
        )
    )**

view.py

**from rest_framework_serializer_extensions.views import SerializerExtensionsAPIViewMixin

class OrderAPIView(SerializerExtensionsAPIViewMixin, ListCreateAPIView):

pagination_class = OrderPagination
serializer_class = OrderSerializer
#authentication_classes = (OrderAuthentication, )
def get_queryset(self):
    type = self.request.GET.get('type', None)
    advertiser_id = self.request.GET.get('advertiser_id', None)
    status = self.request.GET.get('status', None)
    qs = Order.objects.all()
    if type is not None:
        qs = qs.filter(type__icontains=type)
    if advertiser_id is not None:
        qs = qs.filter(advertiser_id__icontains=advertiser_id)
    if status is not None:
        qs = qs.filter(status__icontains=status)
    return qs**

Note: It's working on my local machine but not when I host it using ngrok for my EC2 instance. I've installed the package and added the app in Installed_Apps

SadbhavanaBhardwaj commented 4 years ago

Apologies from my side as I did a silly mistake.. It is now resolved and thanks to the contributors of this pkg. It is surely a useful pkg for selective fields