On Thu, Jul 16, 2009 at 9:27 AM, Joshua Russo<josh.r.ru...@gmail.com> wrote:
> What are some examples of mutating operations (and other operations
> for that matter) that you use in your models?

the most obvious are:

- 'calculated' fields.  the first example is the __unicode__() method,
but lots others, like multiplying widht/height fields to get an 'area'
field, (en/de)coding JSON data in one field to/from a python object,
fetching a filesize from the filesystem,  things like that.

- 'pre-made filters'. like alex's example

- overriding the save() method, to add some consistency checks, update
other tables (like maintaining denormalized fields), override one
field with another, etc.

- other kinds of objects that could present a nicer API than just a
bunch of DB records and tables, for example a tag soup, even if it's
an extra table, it's presented as extra fields and operations on the
'tagged' model.

- anything that Java developers could call the 'business layer', or
anything that a DB manager would like to put into an stored procedure
(unless you're able to actually do that!)

a worthwhile goal is to make view functions really really thin.  maybe
just a few lines before calling the template or a generic view.

if your model layer presents an API that is close to the concepts the
user manages, but at the same time isn't tied to the specific web
interface, you'll be able to easily rework the whole appearance of
your website, quite possibly even change the whole user experience
without rewriting the 'operational' code.

-- 
Javier

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to