Hi. I'm trying to override the defaults of an text field in an subclass. I thought i could accomplish that by the following code, but models.TextField(default = default('flags')... wouldn't find default (). I cant reference it by self.__class__.default() as the is no self at the field initialization. Im kind of stuck ...
Thank you for your help! class Compiler(Model): class Meta(Checker.Meta): abstract = True # default values for the model fields defaults = { 'flags' : "-Wall -static", 'output_flags' : "-o %s", 'libs' : "", 'file_pattern' : r"^[a-zA-Z0-9_]*$" # Regular expression describing all source files to be passed to the compiler. } def default(key): """ By making the model field defaults a callable instead of an value it will be called every time a new object is created wich will allow for altered defaults in subclasses. """ return defaults[key] _flags = models.TextField(default = default('flags'), help_text = _ ('Compiler flags')) _output_flags = models.TextField(default = default('output_flags'), help_text = _('Output flags')) _libs = models.TextField(default = default('libs'), help_text = _ ('Compiler libraries')) class CXXBuilder(compiler): """ A C++ compiler for construction. """ # override configuration _compiler = "c++" _language = "C++" # override default values for the model fields defaults['flags'] = "-Wall", defaults['output_flags'] = "" defaults['file_pattern'] = r"^[a-zA-Z0-9_]*\.(c|C|cc|CC|cxx|CXX|c\+\+| C\+\+|cpp|CPP)$" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---