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






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






3. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.






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






5. This query finds all entries with an id in the list [1 - 3 - 4]






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






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






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






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






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






11. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)






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






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






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






15. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.






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






17. If True - this field is the primary key for the model.






18. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.






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






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






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






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






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






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






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






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






27. Specifies the model that will be used to govern the many-to-many relationship. You can then put extra fields on the intermediate model. The intermediate model is associated with the ManyToManyField using this to point to the model that will act as an






28. A Python "magic method" that returns a unicode "representation" of any object.






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






30. Fields are specified by these






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






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






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






34. Returns a DateQuerySet -- a QuerySet that evaluates to a list of datetime.datetime objects representing all available dates of a particular kind within the contents of the QuerySet.

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


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






36. This query finds all entries between a start date of start_date and an end date of end_date.






37. This method immediately deletes the object and has no return value.






38. An iterable (e.g. - a list or tuple) of 2-tuples to use as options for this field. If this is given - Django's admin will use a select box instead of the standard text field and will limit options to those given.






39. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.

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


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






41. This tells Django how to calculate the URL for an object. Django uses this in its admin interface - and any time it needs to figure out a URL for an object.






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






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






44. Manager method used to retrieve every object in a model.






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






46. Returns a dictionary of aggregate values (averages - sums - etc) calculated over the QuerySet. Each argument to this method specifies a value that will be included in the dictionary that is returned.






47. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o






48. a QuerySet can be sliced - using Python's array-slicing syntax.






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






50. Returns the object matching the given lookup parameters