title: django - using regex to strip and replace a urlfield
body: <p>I want to save url field of videos from youtube, so that I can load it in my site. So far I came up with this in the html:</p>
  
  <pre><code>&lt;h3&gt;{{video.title}}&lt;/h3&gt;
  &lt;object width="425" height="344"&gt;&lt;param name="movie" value="{{video.video_url}}"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="{{video.video_url}}" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;
  </code></pre>
  
  <p>But the problem is that it works only in one way. Eg:</p>
  
  <p>url: <code>http://www.youtube.com/watch?v=e4lHTj9xFqE</code></p>
  
  <p>This will only work if the <code>watch?</code> is striped and <code>=</code> becomes <code>/</code></p>
  
  <p>So that final url will be somewhat like this</p>
  
  <pre><code>http://www.youtube.com/v/e4lHTj9xFqE
  </code></pre>
  
  <p>I was thinking of using regex before it gets saved and replace and strip the url. How do I do to strip the <code>watch?</code> and then replace <code>=</code> with a <code>/</code>? Also is there any better way to load the video in the html? Suggestion from you guys will be most appreciated. Thank you!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>models.py:</p>
  
  <pre><code>class Video(models.Model):
      title = models.CharField(max_length=100)
      video_url = models.URLField(max_length=100)
  
      def save(self, *args, **kwargs):
          new_url = (self.video_url.replace("watch?v=","v/"))
          super(Video, self).save(*args, **kwargs)
          if new_url:
              self.video_url = new_url
  </code></pre>