I guess the thing I like the least about the helper module scheme is that it is easy to forget that it is there, and reinvent the wheel.  I thought about experimenting with mixins, so that my model class would derive from my controller class.  It feels a little upside-down, but I think it would work, no?

--Ned.

Jacob Kaplan-Moss wrote:
On May 11, 2006, at 7:37 AM, Ned Batchelder wrote:
  
Django provides a great way to separate models and views, and even
pre-populates the project tree with directories named models and  
views.
But what about separating models and controllers, that is, separating
the specific database representation of an object from all of the
"business logic" needed to manipulate the object?

I've seen two patterns in use, and neither is completely satisfactory.
I'm wondering if there are possibilities I've overlooked.

The first technique is to put all of the logic in the model class.   
This
leads to large model classes, and combines all of the field lists with
the logic to manipulate them.

The second technique is to leave the model classes as bare as possible
(basically just Field declarations), and create a separate module full
of helper methods that has all the logic.  This means the objects  
don't
manipulate themselves, and you have to go back to non-OO techniques of
passing passive data structures into un-classes functions.

Is there some way to put the model and the logic in two separate  
places
but somehow end up with an object class with real methods?  Am I  
making
any sense?
    

Good question, Ned!

I usually end up with what's usually thought of as "business logic"  
in my view code -- but that's a byproduct of the fact that I'm  
working 99% of the time on web views, so most logic I need to write  
is concerned with aggregating/filtering data for display.

The times when it's not, though, I do struggle with the two different  
patterns you talk about, and like you I'm not totally happy with  
either of them.  I'd say I more often do the "helper module" thing,  
but I often later forget about that module and am surprised not to  
find it somewhere more obvious.

Any ideas?

Jacob





  

-- 
Ned Batchelder, http://nedbatchelder.com

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to