News for hackers. Stuff that matters.
Re:Models vs. Modules by raganwald on Wednesday February 04, 2009 @01:36PM (#466218)
Reminds me of... Favour object composition over class inheritance, only we are talking about mixin inheritance instead of class inheritance.
Re:Models vs. Modules by zepolen on Wednesday February 04, 2009 @12:10PM (#466033)
Summary: Object oriented beats monkey patching.
Re:Models vs. Modules by jamis on Wednesday February 04, 2009 @01:11PM (#466167)
Actually, the two are orthogonal. You can monkey-patch an aggregation into a model as easily as you can monkey-patch anything else in.

Also, modules aren't monkey-patching. :)

  http://en.wikipedia.org/wiki/Monkey_patch
Lastly, the modules referred to in the article were added statically, not dynamically. We don't use a lot of dynamic module inclusion (though we do it some).
Re:Models vs. Modules by diN0bot on Wednesday February 04, 2009 @09:23PM (#466981)
in django i separate model components into different files and then mixin in the relevant fields and methods. for example, suppose i define models Blog and Post in blog.py, and Rating and RatingMixin (extends object not base model). I'd give Rating a method, say Initialize, that gets called when importing the whole models folder. Rating.Initialize() would then mixin all the fields and methods in RatingMixin to the specified models. In this case, it might be useful to give Blog and Post the method "average_method".

Is this good practice?

Also, what's the advantage of keep lots of data in a single row versus multiple tables? Does it effect performance that much (esp with caching)?

Re:Models vs. Modules by namcos on Wednesday February 04, 2009 @12:50PM (#466114)
Simple question, why not have a db backed Avatar model instead?
Re:Models vs. Modules by jamis on Wednesday February 04, 2009 @12:56PM (#466129)
It is db-backed. It's just that the fields exist on the people table, instead of in their own table.
Re:Models vs. Modules by namcos on Wednesday February 04, 2009 @01:03PM (#466152)
Thanks, I never noticed model aggregation before. Looks really useful.
Re:Models vs. Modules by ambition on Wednesday February 04, 2009 @11:17PM (#467086)
Also if you did it db backed in a separate table, you'd have to do database joins to retrieve avatars, which might have a performance impact.