On 6/15/07, Vincent Nijs <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have the following model
>
>     class App(models.Model):
>         user = models.ForeignKey(User, unique=True, editable=False)
>
> In a view I now want to check if a user is indeed in the database table. I
> tried the following
>
>     user_exists = Application.objects.get(user='john')
>
> But this give the following error:
>
>     invalid input syntax for integer: "john"

If you are using the User model from django.contrib.auth.models then
you can check directly:

user_exists = False
try:
    u = User.objects.get(username='john')
    user_exists = True
except User.DoesNotExist:
    pass # or do something here

or following your code above:

user_exists = False
try:
    u = App.objects.get(user_username='john')
except User.DoesNotExist:
    pass # or do something here

HTH.
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to