Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2014-12-15 Thread Collin Anderson
Hi Fred, I don't see how it could possibly be thread-safe without using a thread-local. But, if you don't deploy using threads then you should be fine. I agree with Russ that explicit is better than implicit. I think there is some benefit to simply being able to ask for the the current

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2014-12-14 Thread Russell Keith-Magee
On Mon, Dec 15, 2014 at 9:14 AM, Fred Stluka wrote: > Collin and Russell (and anyone else), > > Do you have any opinion on this? > - https://bitbucket.org/aptivate/django-current-user > > It was offered in an earlier post: > -

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2014-12-14 Thread Fred Stluka
Collin and Russell (and anyone else), Do you have any opinion on this? - https://bitbucket.org/aptivate/django-current-user It was offered in an earlier post: - https://groups.google.com/d/msg/django-users/y7aIbN2_CsA/GtmrSjG1nq8J as a solution to exactly this problem. Makes the current user

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2014-12-14 Thread Collin Anderson
Hi, The "admin save handlers" refers to save_model() and there's actually a nice example of accessing the user. https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model If you're using the admin, that's a good place to record this sort of thing. Using

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2014-12-12 Thread malte . dik
Thanks Mike and Russell, this is very helpful for starters. Do you have some more verbose code examples I can use as crutches while I hobble along the path of understanding Django? Especially an expansion on something like "All the admin save handlers" would be much appreciated. For me every

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-15 Thread Mike Dewhirst
On 15/03/2013 4:56pm, Russell Keith-Magee wrote: On Fri, Mar 15, 2013 at 11:58 AM, Mike Dewhirst > wrote: What is the right way to design a system whereby on every save for every model the updated_by column is changed to the user.id

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Russell Keith-Magee
On Fri, Mar 15, 2013 at 11:58 AM, Mike Dewhirst wrote: > On 15/03/2013 10:31am, Russell Keith-Magee wrote: > >> >> >> On Fri, Mar 15, 2013 at 5:24 AM, Shawn Milochik > > wrote: >> >> I've repeatedly asked about this over

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Mike Dewhirst
On 15/03/2013 10:31am, Russell Keith-Magee wrote: On Fri, Mar 15, 2013 at 5:24 AM, Shawn Milochik > wrote: I've repeatedly asked about this over the past couple of years and there seems to be no "right" answer." This, to me, is the

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Russell Keith-Magee
On Fri, Mar 15, 2013 at 5:24 AM, Shawn Milochik wrote: > I've repeatedly asked about this over the past couple of years and > there seems to be no "right" answer." This, to me, is the biggest flaw > in Django. > There's definitely a right answer. > The official (and

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Shawn Milochik
I've repeatedly asked about this over the past couple of years and there seems to be no "right" answer." This, to me, is the biggest flaw in Django. The official (and useless) answer is that you must pass "user" in everywhere you save anything. This is stupid, obviously, because you can not

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Hendrik Speidel
Hi, Accessing the request within models may be problematic ... E.g. when using a management command, there is no request. However, it's doable: -implement a middleware that takes the request or request.user and stores it in a thread local -register this middleware in your settings -in your

Re: Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Jonathan D. Baker
Perhaps a combination of signals and receivers would fit the bill? Models.py shouldn't be concerned with request objects. Sent from my iPhone On Mar 14, 2013, at 12:59 PM, Simon Chan wrote: > Essentially, I'm just trying to make a simple email alert system. If

Can anyone give me a suggestion or a recommendation as to how I can access the current user's username in the models.py?

2013-03-14 Thread Simon Chan
Essentially, I'm just trying to make a simple email alert system. If anyone creates, modifies or deletes an entry in the admin back end, I'll receive an email as to which user did what to which model. I already figured out how to detect the 3 user actions mentioned above in the models.py as