title: django rest framework serializers and django forms
body: <p><strong>Question</strong>: How to write DRY code for field validation in both form and serializer?</p>
  
  <p><strong>Example</strong>:
  I have simple django app with model form, which validates <code>passengers</code> field for <code>Order</code>:</p>
  
  <pre><code>def clean_passengers(self):
      passengers = self.cleaned_data['passengers']
      if passengers &gt; self.flight.available_seats:
          raise forms.ValidationError(
              _(u'''Passengers count can`t be greater then seats count'''))
      return passengers
  </code></pre>
  
  <p>And same code for validation in <code>Order</code> serializer:</p>
  
  <pre><code>def validate_passengers(self, attrs, source):
      passengers = attrs[source]
      if passengers &gt; self.flight.available_seats:
          raise serializers.ValidationError(
              _(u'''Passengers count can`t be greater then seats count'''))
      return attrs
  </code></pre>
  
  <p>This isn`t DRY and I have write same logic twice. How I can avoid this? Maybe I can inherit serializer from form or something like this.</p>