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. Lookup type that returns results that fall into an inclusive date range.






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






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






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






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






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






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






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






9. Used to get a QuerySet for a model. This is called 'objects' by default.






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






11. The first element in this iterable is the value that will be stored in the database - the second element will be displayed by the admin interface - or in a ModelChoiceField.






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






13. Disjunction operator for Q objects.






14. Lookup type that returns results in a given list.






15. Lookup type that returns results with a case-sensitive start sequence.






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






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






18. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th






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






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






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






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






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






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






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






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






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






28. To activate your models






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






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






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






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






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






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






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






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






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






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


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






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






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






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






43. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.






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






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






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






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






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






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






50. When to run syncdb