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. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.






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






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






4. Keyword shortcut for looking up an object by primary key.






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






6. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.






7. Lookup type for date/datetime fields that finds a 'day of the week' match.






8. 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.






9. 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






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






11. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.






12. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.






13. 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






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






15. Conjuntion operator for Q objects.






16. 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






17. This is a criterion that narrow down a QuerySet based on given parameters.






18. 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






19. A convenience method for looking up an object with the given kwargs - creating one if necessary.






20. Lookup type that returns results with a case-insensitive end sequence.






21. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on






22. 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.






23. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.






24. 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.






25. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.






26. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary






27. Can be used to remove all many-to-many relationships for an instance






28. This method returns tuples of values when iterated over. Each tuple contains the value from the respective field passed into the call to this method -- so the first item is the first field - etc.






29. 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






30. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.






31. Lookup type that tests for inclusion in a case-sensitive fashion.






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






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






34. Lookup type for date/datetime fields that finds an exact day match.






35. If True - the table does not permit duplicate values for this field.






36. Returns the most recent object in the table - by date - using the field_name provided as the date field.






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






38. Lookup type that returns results with a case-insensitive start sequence.






39. Lookup type that finds a case-insensitive regular expression match.






40. 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


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






42. Fields are specified by these






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






44. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.






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






46. This model method saves a model instance to the database. This method has no return value.






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






48. 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


49. Disjunction operator for Q objects.






50. (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.