title: Django. Check `unique_together` only if both Model fields were provided for create and update calls
body: <p>I need to check <code>unique_together</code> only in case both fields were supplied to admin creation <code>Form</code> or via <code>API</code> request for both <code>create</code> and <code>update</code> calls. In case this happens and fields are not <code>unique_together</code> I need to propagate <code>Exception</code> to <code>django-admin</code> creation <code>Form</code> and <code>RestFramework</code>'s <code>Serializer/ViewSet</code>.</p>
  
  <p>Here's a simplified example of my model:</p>
  
  <pre><code>class MyModel(models.Model):
      time = models.TimeField(null=True, blank=True)
      date = models.DateField(null=True, blank=True)
      some_other_field = models.BooleanField(default=False)
      ...
  </code></pre>
  
  <p>As you can see at the level of model both <code>time</code> and <code>date</code> are not required and are nullable.</p>
  
  <p>Application logic on the other hand requires at least one of those fields to be provided and if both are supplied – this pair should be unique for entire table to avoid duplication of <code>datetime</code> composition.</p>
  
  <p>This model is accessed through these nodes: <code>django-admin</code> and <code>DjangoRestFramework</code>'s endpoint using <code>ViewSet</code>.</p>
  
  <p>Creation of new record does not seem to be a problem from <code>API</code> perspective, I can override <code>validate</code> method of <code>Serializer</code>:</p>
  
  <pre><code>    def validate(self, data):
      if not data.get('time') and not data.get('date'):
          raise serializers.ValidationError(
              "At least one of this fields is required: time, date"
          )
  
      if OpenTable.objects.filter(
              time=data.get('time'),
              date=data.get('date')).exists():
          raise serializers.ValidationError('Duplicates for date or datetime not allowed')
      return data
  </code></pre>
  
  <p>But this becomes a problem when I receive <code>PUT</code> or <code>PATCH</code> request, because then despite this record being the only one in table I raise <code>ValidationError</code> precisely because there is a record with this <code>date</code>-<code>time</code> pair.</p>
  
  <p>Overriding <code>validate</code> method also does not solve problem of preventing creation of such a pair from <code>Django-Admin</code>.</p>
  
  <p>At the moment the closest I got to validating this is using <code>save</code> method of <code>MyModel</code>, but I can't understand how exactly to handle this case there to comply with <code>create</code>/<code>update</code> flow. </p>