What is the difference, please explain them in laymen's terms with examples. Thanks!
The filter() method is used to filter you search, and allows you to return only the rows that matches the search term.
GET is an HTTP method in Django that encapsulates the data in a string and utilizes it to construct a URL. The URL includes the data keys and values as well as the address to which the data must be transmitted.
The exact lookup is used to get records with a specified value. The exact lookup is case sensitive. For a case insensitive search, use the iexact lookup.
Django provides a filter() method which returns a subset of data. It accepts field names as keyword arguments and returns a QuerySet object. As database has only one record where name is 'tom' , the QuerySet object contains only a single record.
I don't know if you really need an example, it's quite easy:
To be more precise:
MyTable.objects.get(id=x).whatever
gives you the whatever
property of your object.get() raises MultipleObjectsReturned if more than one object was found. The MultipleObjectsReturned exception is an attribute of the model class.
get() raises a DoesNotExist exception if an object wasn’t found for the given parameters. This exception is also an attribute of the model class.
MyTable.objects.filter(somecolumn=x)
is not only usable as a list, but you can also query it again, something like MyTable.objects.filter(somecolumn=x).order_by('date')
. for obj in MyTable.objects.filter(somecolumn=x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With