Я использую django_rest_api_framework.Мне нужно искать иностранный ключ.Мое поле поиска - "customer_id"
файл views.py
class DebtListAPIView(ListAPIView):
serializer_class = DebtCreateSerializer
permission_classes = [IsOwner]
filter_backends = [SearchFilter]
list_display = ('customer_id',)
search_fields = ["customer_id__id"]
def get_queryset(self):
queryset = Debt.objects.filter()
return queryset
файл serializers.py
class DebtCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Debt
fields = ['id', 'user', 'customer', 'debtKey', 'created_userKey', 'total_Debt', 'received_Amount',
'payment_Date', 'description', ]
models.py
class Debt(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, default=0,
blank=False)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE, blank=False,
related_name='customer')
debtKey = models.UUIDField(editable=False, default=uuid.uuid4,
blank=False)
created_userKey = models.UUIDField(editable=False,
default=uuid.uuid4)
total_Debt = models.CharField(max_length=50, blank=False)
received_Amount = models.CharField(max_length=50, blank=True)
payment_Date = models.DateField(blank=True)
description = models.CharField(max_length=500, blank=True)
created_Date = models.DateTimeField(auto_now=True)
modified_Date = models.DateTimeField(auto_now=True)