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. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.






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






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






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






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






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






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






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






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






10. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()






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






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






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






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






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






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






17. Performs an SQL update query for the specified fields - and returns the number of rows affected. This method is applied instantly and the only restriction on the QuerySet that is updated is that it can only update columns in the model's main table. F






18. Disjunction operator for Q objects.






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






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






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


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






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






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






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






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






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


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






29. Fields are specified by these






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






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






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






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






34. Returns the object matching the given lookup parameters






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






36. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.






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






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






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






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






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






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






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






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






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






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






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






48. To activate your models






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






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