How to check if something exists in a postgresql database using django?

You can use

Entry.objects.filter(name="name", title="title").exists()

This will return to you true/false values. When you use count the orm generates query which will be executed much longer than in exists method. The get method will raise an exception when object does not exists.

request.POST is a dictionary so to check db with it you use, i.e.:

Entry.objects.filter(name=request.POST['name'], title=request.POST['title']).exists()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)