Add attribute to custom fields in Django -


i'll brief possible.

i want able this

{{ video.youtube_url.video_id }} 

by implementing following custom field:

class youtubeurlfield(urlfield):     description = _("youtubeurl")      def _video_id(self):       return re.search('(?<=\?v\=)[\w-]+', self.value)     video_id = property(_video_id)      def __init__(self, verbose_name=none, name=none, verify_exists=true, **kwargs):       super(youtubeurlfield, self).__init__(**kwargs)       kwargs['max_length'] = kwargs.get('max_length', 200)       charfield.__init__(self, verbose_name, name, **kwargs)       self.validators.append(youtubeurlvalidator(verify_exists=verify_exists)) 

this:

    def _video_id(self):       return re.search('(?<=\?v\=)[\w-]+', self.value)     video_id = property(_video_id) 

does not sucessfully add "video_id" attribute custom youtubeurlfield.

everything else works flawlessly.

i understand there maybe better design considerations in terms of youtube custom field, i'd rather understand, first, why doesn't work.

django fields descriptors, means accessing them not return field, rather field value. need override django field methods in order return object has attributes care about, sanely-defined __unicode__() method.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -