5 ms·
Models vs. Modules
- raganwald 18y agoReminds me of... Favour object composition over class inheritance, only we are talking about mixin inheritance instead of class inheritance.
- deleted 18y ago[deleted]
- zepolen 18y agoSummary: Object oriented beats monkey patching.
- jamis 18y agoActually, 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).
- namcos 18y agoSimple question, why not have a db backed Avatar model instead?
- jamis 18y agoIt is db-backed. It's just that the fields exist on the people table, instead of in their own table.
- namcos 18y agoThanks, I never noticed model aggregation before. Looks really useful.
- ambition 18y agoAlso 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.
- diN0bot 18y agoin 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)?