def getPurchaseDocSupplierViewSet(purchasedoc, supplier): queryset = purchasedoc.objects.filter(module=5).filter(doctype=2) supplierids = [] for pd in queryset: try: supplierids.append(pd.supplierid) except ObjectDoesNotExist: pass queryset = supplier.objects.filter(pk__in=supplierids) # this fails, if supplierid is not found, ToDo: failsafe return type(supplier.__name__ + 'PurchaseDocSupplierViewSet', (PurchaseDocSupplierViewSet,), dict( queryset=queryset, serializer_class=getSupplierSerializer(supplier) ))
def getSupplierViewSet(model): return type(model.__name__ + 'ViewSet', (SupplierViewSet,), dict( queryset=model.objects.all(), serializer_class=getSupplierSerializer(model) ))