Also, you can do a try/catch, but I don't really like this method,
personally:

    try:
        User.objects.get(username=username)
    except User.DoesNotExist:
        # user didn't exist in database.

On Fri, Jan 16, 2015 at 9:16 AM, Mark Furbee <markfur...@gmail.com> wrote:

> Yes, that link will cover the basics...
>
> Here's a couple ways to find out if a query returns any records:
>
>     User.objects.filter(username=username).exists()  # .exists() returns
> boolean if records are found.
>     User.objects.filter(username=username).count() != 0  # .count()
> returns number of records in query.
>     User.objects.filter(username=username).first() is not None # .first()
> returns the first record if there are matches, and None if there aren't
>
>
> On Fri, Jan 16, 2015 at 9:11 AM, James Bennett <ubernost...@gmail.com>
> wrote:
>
>> This may be a good time to review Django's documentation on how to
>> perform database queries:
>>
>>
>> https://docs.djangoproject.com/en/1.7/topics/db/queries/#retrieving-a-single-object-with-get
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACMDPqG8-V--9HB_c2YM%3DYchq7bhOmPTA482jLTFwRLpuFLZTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to