Saturday, November 10, 2012

Re: Queries to multiple tables

Hi Kristofer,
I usualy put methods like this one into Model, although Manager is also
possible. Definitely not View or sth else.

Why I like Model more than Manager is this difference (suppose your
method is called make_payment):

Account.make_payment # via Model
Account.objects.make_payment # via Manager

and because this method is "creating" object instead of "retrieving"
objects, it seems to me more apropriate. I know, there are methods like
create or get_or_create in Manager, so propably someone would have a
better arguments on this. Or maybe it's just matter of taste. In fact,
in one application of mine I have method Node.create which do some
fancy stuff (creating other related objects, consistency checks, etc.)
and then call Node.objects.create.


Cheers,
Tom

Dne Sat, 10 Nov 2012 01:23:44 -0600 (CST)
Kristofer <kristofer@cybernetik.net> napsal(a):

> Hello,
>
> I'm new to Django and trying to learn it by making a simple budget/checkbook application.
>
> I apologize for my ignorance, but I couldn't seem to find an answer to this on Google or the Django docs from my searches.
>
> I want to create a function that will take a bank account as an id number (assumed to already exist), and the payee/amount. From there, the function will do a typical bank transaction: 1) add the entry to the "Ledger" table, and subtract the amount from the "balance" field of the "Account" table for the account referenced in the id number passed to the function.
>
> Where is the appropriate/intended place to put that type of function? Model, Manager, View, or somewhere completely different?
>
> My best guess is that it belongs in a Manager, but all of the examples I can find seem to indicate that Managers are intended for queries.
>
> Thanks in advance,
>
> Kris
>
>
>
<

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate