title: What is the proper process for validating and saving data with with Django/Django Rest Framework regardless the data source?
body: <p>I have a particular model that I'd like to perform custom validations on. I'd like to guarantee that at least one identifier field is always present when creating a new instance such that its impossible to create an instance without one of these fields, though no field in particular is individually required.</p>
  
  <pre><code>from django.db import models
  
  class Security(models.Model):
      symbol = models.CharField(unique=True, blank=True)
      sedol = models.CharField(unique=True, blank=True)
      tradingitemid = models.Charfield(unique=True, blank=True)
  </code></pre>
  
  <p>I'd like a clean, reliable way to do this no matter where the original data is coming from (e.g., an API post or internal functions that get this data from other sources like a .csv file).</p>
  
  <p>I understand that I could overwrite the models .save() method and perform validation, but best practice stated <a href="https://stackoverflow.com/questions/8771029/raise-a-validation-error-in-a-models-save-method-in-django">here</a> suggests that raising validation errors in the .save() method is a bad idea because views will simply return a 500 response instead of returning a validation error to a post request. </p>
  
  <p>I know that I can define a custom serializer with a <a href="http://www.django-rest-framework.org/api-guide/validators/" rel="nofollow noreferrer">validator</a> using Django Rest Framework for this model that validates the data (this would be a great solution for a ModelViewSet where the objects are created and I can guarantee this serializer is used each time). But this data integrity guarantee is only good on that API endpoint and then as good as the developer is at remembering to use that serializer each and every time an object is created elsewhere in the codebase (objects can be created throughout the codebase from sources besides the web API).</p>
  
  <p>I am also familiar with Django's <a href="https://docs.djangoproject.com/en/2.0/ref/models/instances/#validating-objects" rel="nofollow noreferrer">.clean() and .full_clean() methods</a>. These seem like the perfect solutions, except that it again relies upon the developer always remembering to call these methods--a guarantee that's only as good as the developer's memory. I know the methods are called automatically when using a ModelForm, but again, for my use case models can be created from .csv downloads as well--I need a general purpose guarantee that's best practice. I could put .clean() in the model's .save() method, but this <a href="https://stackoverflow.com/questions/4441539/why-doesnt-djangos-model-save-call-full-clean">answer</a> (and related comments and links in the post) seem to make this approach controversial and perhaps an anti-pattern.</p>
  
  <p>Is there a clean, straightforward way to make a guarantee that this model can never be saved without one of the three fields that 1. doesn't raise 500 errors through a view, 2. that doesn't rely upon the developer explicitly using the correct serializer throughout the codebase when creating objects, and 3. Doesn't rely upon hacking a call to .clean() into the .save() method of the model (a seeming anti-pattern)? I feel like there must be a clean solution here that isn't a hodge podge of putting some validation in a serializer, some in a .clean() method, hacking the .save() method to call .clean() (it would get called twice with saves from ModelForms), etc... </p>