Test your basic knowledge |

Django Queryset

Subject : it-skills
Instructions:
  • Answer 50 questions in 15 minutes.
  • If you are not ready to take this test, you can study here.
  • Match each statement with the correct term.
  • Don't refresh. All questions and answers are randomly picked and ordered every time you load a test.

This is a study tool. The 3 wrong answers for each question are randomly chosen from answers to other questions. So, you might find at times the answers obvious, but you will see it re-enforces your understanding as you take the test each time.
1. (1) These cannot be Python reserved words - because that would result in a Python syntax error. (2) These cannot contain more than one underscore in a row - due to the way Django's query lookup syntax works.






2. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.






3. This query finds all entries with an id greater than 4.






4. Adds to each object in the QuerySet with the provided list of aggregate values (averages - sums - etc) that have been computed over the objects that are related to the objects in the QuerySet. Each argument to this is content that will be added to ea






5. A QuerySet is iterable - and it executes its database query the first time you iterate over it.






6. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u






7. These methods are intended to do "table-wide" things.






8. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.






9. Lookup type that returns results that fall into an inclusive date range.






10. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used






11. This query deletes all Entry objects with a pub_date year of 2005.






12. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r






13. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.






14. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.






15. This represents a collection of objects from your database. It can have zero - one or many filters.






16. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.






17. Conjuntion operator for Q objects.






18. This method is for controlling which database the QuerySet will be evaluated against if you are using more than one database. The only argument this method takes is the alias of a database - as defined in DATABASES.






19. Lookup type that returns results less than or equal to a given value.






20. Returns an EmptyQuerySet -- a QuerySet that always evaluates to an empty list. This can be used in cases where you know that you should return an empty result set and your caller is expecting a QuerySet object (instead of returning an empty list - fo






21. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode






22. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.






23. Defines a one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.






24. The database that will be used if this query is executed now






25. Lookup type that yields a case-insensitive match.






26. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.






27. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12






28. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


29. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo






30. By default - results returned by a QuerySet are ordered by the ordering tuple given by the ordering option in the model's Meta. You can override this on a per-QuerySet basis by using the this method.






31. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .






32. A convenience method for constructing an object and saving it all in one step.






33. Defines a many-to-one relationship. ou use it just like any other Field type: by including it as a class attribute of your model.






34. Lookup type that returns results greater than a given value.






35. This query uses an F object to increment the pingback count for every entry in the blog.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


36. Disjunction operator for Q objects.






37. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.






38. This field is added automatically - but this behavior can be overridden






39. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire






40. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.






41. Returns a new QuerySet containing objects that match the given lookup parameters.






42. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.






43. The default for this is the name of the child class followed by '_set'.






44. If this option is True - Django will store empty values as NULL in the database. Default is False.






45. This model method is used for updating a ManyToManyField.






46. This model type is useful if you only want to modify the Python-level behavior of a model - without changing the models fields in any way. This creates a stand-in for the original model. You can create - delete and update instances of this new model






47. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


48. Lookup type that yields an "exact" match. If you don't provide a lookup type -- that is - if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be of this sort.






49. Lookup type that finds a case-sensitive regular expression match.






50. Lookup type that returns results greater than or equal to a given value.