python - Django MVT design: Should I have all the code in models or views? -
i'm pretty novice i'll try explain in way can understand mean.
i'm coding simple application in django track cash operations, track amounts, etc.
so have account model (with amount field track how many money inside) , operation model(with amount field well).
i've created model helper called account.add_operation(amount). here question:
should include inside code create new operation inside account.add_operation(amount) or should in views?
and, should call save() method in models (for example @ end of account.add_operation() or must called in views?)
what's best approach, have code inside models or inside views?
thanks attention , patience.
experienced django users seem err on side of putting code in models. in part, that's because it's lot easier unit test models - they're pretty self-contained, whereas views touch both models , templates.
beyond that, ask if code pertains model or whether it's specific way it's being accessed , presented in given view. don't entirely understand example (i think you're going have post code if want more specific help), mention sounds me belongs in model. is, creating new operation
sounds it's inherent part of means called add_operation()
!
Comments
Post a Comment