Tuesday, July 16, 2013

mutable verbose_name and help_text

Is there a way to adjust inherited verbose_name and help_text in child
tables depending on which child table is inheriting?

Sergiy Khohlov very kindly offered a generic OOP solution[1] to a recent
question I asked "how can an abstract class know which class inherits it"

I tried Sergiy's solution but couldn't get it working. However, I'm sure
this has been solved before. Maybe Sergiy's solution would have worked
if I coded it properly. Here is the problem ...

class Flavours(models.Model):
flavour = models.CharField(max_length=99, verbose_name="to be set
by inheritor", help_text="to be set by inheritor")
sauce = models.CharField(max_length=99, verbose_name="to be set by
inheritor", help_text="to be set by inheritor")
class Meta:
abstract = True

class Pizza(Flavours):
base = models.CharField(max_length=99)

class Pasta(Flavours):
pasta_shape = models.CharField(max_length=99)

Thanks

Mike




[1] Thanks Sergiy ...
>
> class ParentClass(object):
> def __init__(self, name):
> print "Constructor parent"
> print "Called from ", name
> class ChildClass(ParentClass):
> def __init__(self):
> super(ChildClass,self).__init__("Child")
> print "Child Constructor"
>


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate