title: Django SerializerMethodField vs Complex SQL
body: <p>I'm wondering about what people think about the tradeoffs of efficiency and readability between using Django's <code>SerializerMethodField</code> and writing potentially convoluted SQL. I'm think SQL would generally be quicker, but the complexity of code may not be worth it. I lean towards using the <code>SerializerMethodField</code> for better readability/maintainability, but am curious what others think.</p>
  <p>This isn't a great example and just serves as an introduction to what I am talking about. These SQL queries could get much more convoluted. I know this code probably isn't actually written perfectly.</p>
  <pre class="lang-py prettyprint-override"><code># Comment
  # is_admin: Boolean
  # public_email: String
  # email: Optional String
  
  default_email = 'foo@bar.com'
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>queryset = Comment.objects
  
  class CommentSerializer(serializers.Serializer):
      is_admin = serializers.BooleanField()
      email = serializers.SerializerMethodField()
  
      @staticmethod
      def get_email(comment):
          if comment.is_admin:
              return comment.public_email
          return comment.email or default_email
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>queryset = Comment.objects.annotate(
      email=Case(
          When(is_admin=True, then='public_email'),
          default=Coalesce('email', Value(default_email)),
          output_field=CharField(),
      )
  )
  
  class CommentSerializer(serializers.Serializer):
      is_admin = serializers.BooleanField()
      email = serializers.CharField()
  </code></pre>