refactor models/__init__.py so fields themselves add their own get_XXXX_count/list functions
|Reported by:||Owned by:||rjwittams|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
models/__init__.py there is a big for loop which goes over all the installed modules
and creates the foreign key relationships (oneTomany,manytomany and one to one) with a big if/else/elif statement.
I propose we move the if/elif logic to the actual field code itself. so a field 'knows' what functions it has to create, and field writers could override this functionality to add their own relationships if they choose
for related in klass._meta.get_all_related_objects(): if foo: .... elsif blah: ....
for related in klass._meta.get_all_related_objects(): related.create_relationships( klass, meta )
class OneToOne: def create_relationships( klass,meta ) func = curry(....) ... klass.setattr(...)
I think this change would be backwards compatible. and could allow me to define a 'TagField' which creates special functions.
Change History (10)
comment:6 Changed 11 years ago by
|Owner:||changed from Adrian Holovaty to rjwittams|