Following up: if it affects a single instance of an object, then it belongs 
as a model method.

If it affects any number of them, then it should perhaps go on the manager 
(or even the queryset: I use django-model-utils PassThroughManager for this 
a lot).

Matt.

On Sunday, November 11, 2012 3:53:26 AM UTC+10:30, Javier Guerra wrote:
>
> On Sat, Nov 10, 2012 at 6:15 AM, Tomas Ehrlich 
> <tomas....@gmail.com<javascript:>> 
> wrote: 
> > I usualy put methods like this one into Model, although Manager is also 
> > possible. Definitely not View or sth else. 
>
> definitely in the model. 
>
> you'd use it like this: 
>
> accnt = get_object_or_404 (Account, pk=account_id) 
> payee = get_object_or_404 (...........) 
> accnt.make_payment (payee, amount) 
>
> it would be as easy as adding a method to your Account class, for example: 
>
> class Account (models.Model): 
>     ...... 
>     ...... 
>
>     def make_payment(self, payee, amount, save=True): 
>         if amount > self.balance: 
>             throw NotEnoughFunds 
>         self.balance -= amount 
>         payee.balance += amount 
>         if save: 
>             self.save() 
>             payee.save() 
>
> (of course, a serious accounting app don't modify balances but 
> registers debit/credit entries) 
>
> -- 
> Javier 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/pU7gNc-iJe8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to