Re: Where to put function to instantiate and save a model object?

2007-02-03 Thread Rob Hudson

Russell Keith-Magee wrote:
> Look in django.contrib.auth.models for UserManager for implementation details.

Nice.  Thanks.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Where to put function to instantiate and save a model object?

2007-02-02 Thread Russell Keith-Magee

On 2/3/07, Rob Hudson <[EMAIL PROTECTED]> wrote:
>
> Log(user=request.user, session=request.session.session_key,
> varname='somename').save()

> But I'm finding that I'm writing the above line in a number of
> places.  I'd like to create a method to do this for me.  But where?

Why not take the example of User (from django.contrib.auth), and put
it in a custom manager? If you want to create a User, you write:

newuser = User.object.create_user(username='foo',...)

which creates a new user with the provided arguments, saves it, and
returns the instance.

Look in django.contrib.auth.models for UserManager for implementation details.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Where to put function to instantiate and save a model object?

2007-02-02 Thread Rob Hudson

I have a model called "Log" which logs access to certain pages or sets
variables that we're tracking.

The way I'm inserting new records into the log table is like this:

Log(user=request.user, session=request.session.session_key,
varname='somename').save()

But I'm finding that I'm writing the above line in a number of
places.  I'd like to create a method to do this for me.  But where?

I thought about putting it in the model but can it be a method of Log
itself?  Can I call something like Log.set_log(request, varname)?
Would this need to call __init__ or something?

If not, would it make sense in the view file of the code that's using
it?  It's really not a "view" itself.

Thanks for any advice.

-Rob


--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---