what is the difference between get() and filter() function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    #1

    what is the difference between get() and filter() function?

    hi

    i am quite confused between get() function and filter() function, what is the difference between. it seems they all retrieve the specific row from database.
    i have written this code in one function of my application and it works:
    [code=python]

    Rt=outlet.objec ts.get(id__exac t=return_locati on)
    r=Rt.outlet_nam e
    [/code]


    in my other functions, i write this and it also works:
    [code=python]
    allObj =Booking1.objec ts.filter(id = booking)
    [/code]

    in the other scenario, which i use filter it will work but when i change it into get,it complain about errors. which the code is like the following:
    [code=python]
    my = Booking1.object s.filter(id__ex act= myId)
    my.delete()
    [/code]

    thus i am very confused about how it works and what is the difference between get() and filter()

    (PS, i am using Django framework which is build on python programming language)

    this problem is a bit urgent at the moment,as it causes a lot of problem for me and my project is running out of time. thanks in advance for any kind help :)
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by kang jia
    hi

    i am quite confused between get() function and filter() function, what is the difference between. it seems they all retrieve the specific row from database.
    i have written this code in one function of my application and it works:
    [code=python]

    Rt=outlet.objec ts.get(id__exac t=return_locati on)
    r=Rt.outlet_nam e
    [/code]


    in my other functions, i write this and it also works:
    [code=python]
    allObj =Booking1.objec ts.filter(id = booking)
    [/code]

    in the other scenario, which i use filter it will work but when i change it into get,it complain about errors. which the code is like the following:
    [code=python]
    my = Booking1.object s.filter(id__ex act= myId)
    my.delete()
    [/code]

    thus i am very confused about how it works and what is the difference between get() and filter()

    (PS, i am using Django framework which is build on python programming language)

    this problem is a bit urgent at the moment,as it causes a lot of problem for me and my project is running out of time. thanks in advance for any kind help :)
    I am not familiar with Django. A get() method should return the value of a given attribute name, and a filter() method should return a list whose elements evaluate to true given a comparison function. I am just guessing though.

    Comment

    Working...