Re: Overriding verbose_name in contrib or 3rd-party apps?
Thanks for the suggestions, everyone. It seems to be popping up for all sorts of things -- from changing verbose_name in order to globally relabel form fields in ModelForms to changing __unicode__ methods to change template output. I know there are workarounds, but they seem less DRY. On Sep 27, 5:02 pm, Michael Williamsonwrote: > On Sep 25, 9:59 pm, ringemup wrote: > > > Is there an easy way to override strings like help_text or > > verbose_name or __unicode__ methods for models in contrib or third- > > party apps? I can't seem to find anything on Google. > > > Thanks! > > A reasonably hacktastic way of doing this is monkey-patching. For > instance, say you want to override the __unicode__ method of the class > Blog. Firstly, write the new method e.g. > > def new_unicode(self): > return self._name > > Then, set the __unicode__ method of Blog to your new function: > > Blog.__unicode__ = new_unicode > > Is this a horrible piece of code? Absolutely. But it is quick, and it > works. A clean solution depends more on why you actually want to do > this. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Overriding verbose_name in contrib or 3rd-party apps?
On Sep 25, 9:59 pm, ringemupwrote: > Is there an easy way to override strings like help_text or > verbose_name or __unicode__ methods for models in contrib or third- > party apps? I can't seem to find anything on Google. > > Thanks! A reasonably hacktastic way of doing this is monkey-patching. For instance, say you want to override the __unicode__ method of the class Blog. Firstly, write the new method e.g. def new_unicode(self): return self._name Then, set the __unicode__ method of Blog to your new function: Blog.__unicode__ = new_unicode Is this a horrible piece of code? Absolutely. But it is quick, and it works. A clean solution depends more on why you actually want to do this. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Overriding verbose_name in contrib or 3rd-party apps?
Can you please post some more information for what purpose you like to do this? My first guess would be you are using the admin interface. Dirty workarounds are: copying code and adapting it, importing from your adaptation in stead of the original. Maybe modifying the admin view to do something differently. Or adapt a translation? Probably there are a hundred better ways, but you can try these for a start. Wim On Sep 25, 10:59 pm, ringemupwrote: > Is there an easy way to override strings like help_text or > verbose_name or __unicode__ methods for models in contrib or third- > party apps? I can't seem to find anything on Google. > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Overriding verbose_name in contrib or 3rd-party apps?
Is there an easy way to override strings like help_text or verbose_name or __unicode__ methods for models in contrib or third- party apps? I can't seem to find anything on Google. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---