Good day list! After much dealing with this problem I decided to share it with fresh minds to get a new perspective.
situation: In the project we have a model that is Promo, which in turn has different types of promos (FK to Promo models) and these types of promo are different and defined which things should be displayed. Now when users access / promo / 1 /, what we do is nested if askinf for the type of promo and then setting the template_name and o_promo (model specific type promotion) Obviously this design is not very scalable because if one day there are 10 types of promos, have 10 if is not the most Pythonic. The solution I found is to define the model of a method that is Promo get_promo_handler () and return a class according to the type of promo is promo and that has methods like render () or other methods for logic necesaarios project (generate coupons, decide if the promotion is finished, etc.) The example code is here [0] Being new to python I open a lot of doubts. 1 is the best solution for this? What other ways are there? 2 I am implementing the best way? 3 I am using appropriately ABCMeta [1]? maybe you should use something like __new__ [2]? 4. not quite understand is the ducktyping [3] and how it affects all this. Thank you very much in advance, regards, Julo [0] http://linkode.org/p39S0VryugbTFPXXhkVb94 [1] https://docs.python.org/2/library/abc.html [2] https://docs.python.org/2/reference/datamodel.html#object.__new__ [3] https://docs.python.org/2/glossary.html#term-duck-typing put all the links because they are using to try to understand the components. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKSEZ1EG01XkE_fkuvyJihH751r06WPwYLtPNYqLsxJwfhc_oA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.