I keep field imdb_id for models Movie in my db:
class Movie(models.Model):
imdb_id = models.IntegerField('imdb ID', blank=True, null=True, unique=True)
def _get_imdb_url(self):
return self.imdb_id and 'http://www.imdb.com/title/tt%s/' % str(self.imdb_id).zfill(7) or ''
def _set_imdb_url(self, imdb_url):
self.imdb_id = int( re.compile(r'[^\d]').sub('', imdb_url))
imdb_url = property(_get_imdb_url, _set_imdb_url)
And I want to make special widget for displaying external link to imdb.com in the admin form near text input for field 'imdb_id'. I think it may be global widget for any form field with external link, generated by using special mask (in my case, this mask is 'http://www.imdb.com/title/tt%s/'). I know how to write widget, but I don't know how push my mask, defined in my Movie model, to this widget. I don't want to violate DRY principe and define this mask in two different places. And also it will be a good tool for the same purpose with other external links in future.
What do you think about this widget? How it is posssible to realize it? May be someone wrote it before me?
Thanks!