title: Getting the url of an uploaded file in django admin
body: <p>I have an application in which I am uploading a file using Django's admin site. I need to return the url of the file so that it can be used by another function. The process works just fine apart from the fact that I am able to get the name of the original file and not the file that is saved by the application. For instance if the file to be uploaded is named somefile.xxx and django saves it as somefile_1.xxx because that somefile.xxx already exists on the server I am not able to return somefile_1.xxx but I am geting the original file name. this is my code at the moment.</p>
  
  <p>admin.py</p>
  
  <pre><code>def add_view(self, request, form_url="", extra_context=None):
          ...
  
          ModelForm = self.get_form(request)
          if request.method == 'POST':
              form = ModelForm(request.POST, request.FILES)
              if form.is_valid():
                  url = MEDIA_URL+'files/'+request.FILES['filename'].name
                  url = iri_to_uri(url)
                  title = form.cleaned_data['title']
                  name = request.FILES['filename'].name
                  newname = os.path.splitext(request.FILES['filename'].name)[0]
                  data = utils.convert(url, title, newname)
                  print data
  
          return super(FileAdmin, self).add_view(request, form_url="", extra_context=extra_context)
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <pre><code>def save_model(self, request, obj, form, change):
  
          ...
  
          obj.save()
  
          url = obj.video.url
  
          title = obj.title
  
          newname = str(obj.id)
  
          data = utils.convert(url, title, newname)
          print data
  </code></pre>