title: File upload type validation in Django
body: <p>I am trying to validate upload file type functionality in Django. The allowed extension would be xml only. The admin will upload a xml file and then the table would be populated with the data from xml file. The model has no <code>filefield</code> but the form has.</p>
  
  <p><code>accounts/models.py</code> --</p>
  
  <pre><code>class Coupling(models.Model):
      coupling_name = models.CharField(max_length=150, blank=False, null=True, default="")
      module_name = models.TextField(blank=False, null=True)
      def __str__(self):
          return self.coupling_name
  
      class Meta:
          verbose_name_plural = "Couplings"
  </code></pre>
  
  <p><code>accounts/forms.py</code> --</p>
  
  <pre><code>class CouplingUploadForm(forms.ModelForm):
  
      coupling_file = forms.FileField(label='XML File Upload:', required=True)
  
      class Meta:
          model = models.Coupling
          exclude = ['coupling_name', 'module_name']
  </code></pre>
  
  <p><code>settings.py</code></p>
  
  <pre><code>UPLOAD_PATH = os.path.join(BASE_DIR, "static", "uploads")
  
  CONTENT_TYPES = ['xml']
  MAX_UPLOAD_SIZE = "2621440"
  </code></pre>
  
  <p><code>accounts/admin.py</code></p>
  
  <pre><code>class couplingAdmin(admin.ModelAdmin):
      list_display = ('coupling_name','module_name')
      form = CouplingUploadForm
  admin.site.register(Coupling, couplingAdmin)
  </code></pre>
  
  <p>I have gone through some SOF references and most of them have <code>model.FileField</code> but in my case I do not want to save the file in model.</p>
  
  <p>I tried with using magic -- <a href="https://djangosnippets.org/snippets/3039/" rel="nofollow noreferrer">https://djangosnippets.org/snippets/3039/</a> but I got an python-magic installation error -- Unable to find libmagic. So I would like to do it without magic.</p>
  
  <p>Any help/suggestion/link is highly appreciated. Thanks in advance.</p>