views:

189

answers:

1

hi i am using django app engine patch i have set up a simple model as follows

class Intake(db.Model):
    intake=db.StringProperty(multiline=False, required=True)
    #@permerlink 
    def get_absolute_url(self):
       return "/timekeeper/%s/" % self.intake
    class Meta:
       db_table = "Intake"
       verbose_name_plural = "Intakes"
       ordering = ['intake']

i am using the following views to check if some thing exist in data base and add to database

from ragendja.template import render_to_response
from django.http import HttpResponse, Http404
from google.appengine.ext import db
from timekeeper.forms import *
from timekeeper.models import *

def checkintake(request, key):
    intake = Intake.all().filter('intake=',key).count()
    if intake<1:
       return HttpResponse('ok')
    else:
       return HttpResponse('Exist in database')

def addintake(request,key):
    if Intake.all().filter('intake=',key).count()>1:
        return HttpResponse('Item already Exist in Database')
    else:
        data = Intake(intake=cleaned_data[key])
        data.put()
        return HttpResponse('Ok')

i can add to database with no problem (when i do a Intake.all().count() it increases) but when i check if the key exist in the database by filtering i am getting a count of zero any one have any idea why i am not able to filter by keys ?

+2  A: 

You need to insert a space between the field name and the operator in your filter arguments - eg, use .filter('intake =') instead of .filter('intake='). With an equality filter, you can also leave it out entirely, as in .filter('intake'). Without the space, the equals sign is taken to be part of the field name.

Nick Johnson
thanks for the help Nick
nashr rafeeg