Where does this code go? I want to create a user profile for every
user created.
On Dec 18 2008, 2:37 am, "James Bennett"
wrote:
> On Wed, Dec 17, 2008 at 5:21 PM, Malcolm Tredinnick
>
> wrote:
> > This would be the "standard" solution. I
On Wed, Dec 17, 2008 at 5:21 PM, Malcolm Tredinnick
wrote:
> This would be the "standard" solution. I thought James Bennett's
> django-profiles app did this, but apparently I'm mistaken (it would be
> slightly duplicated work if it did, in any case).
django-profiles
> ##
> try:
> m = SomeModel.objects.get(pk=request.user)
> except:
> m = SomeModel()
> ##
>
>
Attention, catch-all ("except" without an exception class) is evil.
There are a lot of exception
that could happen.
You could use:
try:
except SomeModel.DoesNotExist:
On Wed, 2008-12-17 at 08:25 -0600, Milan Andric wrote:
> On Wed, Dec 17, 2008 at 4:00 AM, Thomas Guettler wrote:
> >
> > Hi,
> >
> > The method user.get_profile() fails, if the user has no profile. During
> > my custom login I
> > check if the user has a profile and create it
actually don't user super(self.__class__, self)
http://loveandtheft.org/2008/09/03/how-super-should-be-used-when-calling-a-parents-method/
use super(MyManager, self)
On 17 Dec, 18:15, 7timesTom wrote:
> On 17 Dec, 16:08, Darthmahon wrote:
>
>
On 17 Dec, 16:08, Darthmahon wrote:
> Why not create your own function then and just put the try or except
> code in that? That way it'll only be one line.
Yup. Using model.Manager i.e.:
class MyManager(models.Manager):
def get_or_blank(self, pk_val):
try:
Why not create your own function then and just put the try or except
code in that? That way it'll only be one line.
On Dec 17, 3:19 pm, nbv4 wrote:
> On Dec 17, 5:00 am, Thomas Guettler wrote:
>
>
>
> > Hi,
>
> > The method user.get_profile() fails, if the
On Dec 17, 5:00 am, Thomas Guettler wrote:
> Hi,
>
> The method user.get_profile() fails, if the user has no profile. During
> my custom login I
> check if the user has a profile and create it if needed.
>
> But sometimes this fails: A new user gets created, but before his
On Wed, Dec 17, 2008 at 4:00 AM, Thomas Guettler wrote:
>
> Hi,
>
> The method user.get_profile() fails, if the user has no profile. During
> my custom login I
> check if the user has a profile and create it if needed.
>
> But sometimes this fails: A new user gets created, but
Can you not do this:
if request.user.is_authenticated():
# Get profile
user.get_profile()
else:
# Create profile
On Dec 17, 10:00 am, Thomas Guettler wrote:
> Hi,
>
> The method user.get_profile() fails, if the user has no profile. During
> my custom login I
>
Hi,
The method user.get_profile() fails, if the user has no profile. During
my custom login I
check if the user has a profile and create it if needed.
But sometimes this fails: A new user gets created, but before his first
login someone else
tries to access the not yet created profile.
Since
11 matches
Mail list logo