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






2. Fields are specified by these






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






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






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






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






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






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






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






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


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


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






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






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


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






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






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






18. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.






19. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.






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






21. Conjuntion operator for Q objects.






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






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






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






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






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






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






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






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






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






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






32. This gives your model metadata.






33. To activate your models






34. These add custom "row-level" functionality to your objects. These act on a particular model instance.






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






36. Negation operator for Q objects.






37. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.






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






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






40. If this option is True - the field is allowed to be blank. Default is False.






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






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






43. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.






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


46. If you pickle a QuerySet - this will force all the results to be loaded into memory prior to pickling. When you unpickle a QuerySet - it contains the results at the moment it was pickled - rather than the results that are currently in the database.






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






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






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






50. Defined by django.db.models.ForeignKey. You use it just like any other Field type: by including it as a class attribute of your model.