title: DjangoRestFramework - Omit null fields when serializing objects
body: <p>This is my Model:</p>
  
  <pre><code>class Post(models.Model):
      user = models.ForeignKey(User)
      post = models.CharField(max_length=400)
      country = models.ForeignKey(Country, blank=True, null=True)
  </code></pre>
  
  <p>and this is my serializer:</p>
  
  <pre><code>class PostSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Post
          fields = ('user', 'post', 'country',)
  
      def create(self, validated_data):
          post = Post(
                  user =  User.objects.get(username='MyUser'),
                  post = validated_data['post'],
          )
  
          if validated_data.get('country', None):
              post.country = validated_data['country']
  
          return post
  </code></pre>
  
  <p>Is there any way for me to tell DRF that if the value of the field is null (because the 'country' field is optional and sometimes not provided) then to skip it and just serialize the other data? Or at least serialize it with a value of None?</p>
  
  <p>I don't think I can use SerializerMethodField (<a href="http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield" rel="noreferrer">http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield</a>) because the 'country' field is not a read-only field (I write too it too, if it is provided).</p>
  
  <p>I basically want to omit the field (or at least make the value None) when serializing an object If the field is null.</p>