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 <cp368...@ohio.edu> wrote:
> On Dec 17, 5:00 am, Thomas Guettler <h...@tbz-pariv.de> 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 first
> > login someone else
> > tries to access the not yet created profile.
>
> > Since all fields of my profile model have default values, it could be
> > created it on the fly.
>
> > Since I don't want to run a modified django, I will use my own
> > get_profile method.
>
> > Does some know this problem? How do you solve this?
>
> I'm having the same problem. I have about 4 models that are 1to1
> linked to a user, much like how the get_profile() thing works. Every
> time I want to access that model, I have to do this:
>
> ######
> try:
>     m = SomeModel.objects.get(pk=request.user)
> except:
>     m = SomeModel()
> ######
>
> Which gets annoying to have to do every single time. I wish there was
> some way to do something like:
>
> ######
> m = SomeModel.objects.get_or_blank(pk=request.user)
> ######
>
> Yeah, sure you can have it create a row in the database every time a
> new user registers, but why hit the database when all you ever need is
> the default values?
--~--~---------~--~----~------------~-------~--~----~
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