title: AssertionError: The field '' was declared on serializer '' but has not been included in the 'fields' option. optional
body: <p>Im, using Django Rest Framework to make an APIRest but I got this error when trying to make a simple crud for the discount resource</p>
  
  <p>This is my model </p>
  
  <pre><code>class Discount(BaseModel):
      """ Discount Model. """
      code = models.CharField(max_length=50)
      rate = models.DecimalField( max_digits=3, decimal_places=2)
      class DiscountStatus(models.TextChoices):
          ENABLED = 'ENABLED'
          DISABLED = 'DISABLED'
          REDEEMED = 'REDEEMED'
      status = models.CharField("status", choices=DiscountStatus.choices, default=DiscountStatus.ENABLED,  max_length=10)
      insurance_company = models.ForeignKey("sanitas.InsuranceCompany", on_delete=models.CASCADE)
      appointment = models.ForeignKey("sanitas.Appointment", verbose_name="appointment", on_delete=models.CASCADE, blank=True, null=True)
      class Meta():
          """ Meta class. """
          db_table = 'discounts'
  </code></pre>
  
  <p>This is my serializer</p>
  
  <pre><code>class DiscountModelSerializer(serializers.ModelSerializer):
      """ Insurance company model serializer. """
  
      insurance_company = InsuranceCompanyModelSerializer(many=False, read_only=True, allow_null=True, required=False)
      insurance_company_id = serializers.IntegerField(allow_null=True, required=False,)
  
      appointment = AppointmentModelSerializer(many=False, read_only=True, allow_null=True, required=False)
      appointment_id = serializers.IntegerField(allow_null=True, required=False)
  
      class Meta():
          """ Meta class. """
          model = Discount
          fields = (
              'id',
              'code',
              'rate',
              'status',
              'appointment'
              'insurance_company'
              'insurance_company_id'
              'appointment_id'
          )
  </code></pre>
  
  <p>And this is my Viewset</p>
  
  <pre><code>class DiscountViewset(viewsets.ModelViewSet):
      """ Schedule items will be the time unit to manage appointments. """
  
      queryset = Discount.objects.all()
      serializer_class = DiscountModelSerializer
  
      @action(methods=['post'], detail=False)
      def generate(self, request):
          """ Create dicounts in bulk. """
          rate = 1 - request.data['rate'] / 100
          insurance_company = get_object_or_404(InsuranceCompany, pk=request.data['insurance_company_id'])
          count = 0
          amount = request.data['amount']
          response = []
          while count &lt; amount:
              code = insurance_company.code + randomString(8)
              discount = Discount()
              discount.rate = rate
              discount.code = code
              discount.insurance_company = insurance_company      
              discount.save()
              serializer = DiscountModelSerializer(discount)
              response.append(serializer.data)
              count = count + 1
          return Response(response, status=status.HTTP_200_OK)
  
  </code></pre>
  
  <p>My guess is that the error appears because I have an optional field (is not really optional, but when I create the discount codes there is no appointment yet so it will be added later) and the error appears because I didn't add the field "appointment" and when trying to retrieve the resources I make It shows this error</p>
  
  <pre><code>AssertionError at /discounts/generate/ The field 'appointment_id' was declared on serializer DiscountModelSerializer, but has not been included in the 'fields' option.
  </code></pre>