﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
676	[patch] a _post_init hook for model classes to initialize fields from outside content	hugo	Adrian Holovaty	"It would be very interesting to have a _post_init hook. The reason for this is to pull stuff from outside into a model on field access. For example if you have tags to an object stored in a tagrelation table, but want to edit them in a textfield in the admin, you have the problem that the textfield might be out of sync with the real data. With a _post_init hook you could just pull in the tags from the tagrelations and populate that field with the correct string representation. And since you internally reference tags by the ID, this would even work if tag names or tag slugs are changed.

This could be implemented rather easily:

{{{
Index: core/meta/__init__.py
===================================================================
--- core/meta/__init__.py       (revision 987)
+++ core/meta/__init__.py       (working copy)
@@ -768,6 +768,8 @@
             raise TypeError, ""'%s' is an invalid keyword argument for this function"" % kwargs.keys()[0]
     for i, arg in enumerate(args):
         setattr(self, opts.fields[i].column, arg)
+    if hasattr(self, '_post_init'):
+        self._post_init()
 
 def method_eq(opts, self, other):
     return isinstance(other, self.__class__) and getattr(self, opts.pk.column) == getattr(other, opts.pk.column)
}}}
"	enhancement	closed	Metasystem		normal	invalid			Unreviewed	1	0	0	0	0	0
