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






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






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






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






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






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






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






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






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






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






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






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






13. To activate your models






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






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






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






17. Lookup type that returns results less than a given value.






18. Lookup type that returns results greater than a given value.






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






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


21. This gives your model metadata.






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






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






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






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






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






27. Returns the object matching the given lookup parameters






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






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






30. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire






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






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






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






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






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






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






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






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






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






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






41. If this option is True - Django will store empty values as NULL in the database. Default is False.






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






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. Lookup type that finds a case-sensitive regular expression match.






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. Exception raised by get(**kwargs) if more than one item matches the query.






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


48. Disjunction operator for Q objects.






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






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