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 with a case-sensitive start sequence.






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






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






4. Negation operator for Q objects.






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






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






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


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






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






10. Lookup type that returns results that fall into an inclusive date range.






11. The default for this is the name of the child class followed by '_set'.






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






13. Returns an EmptyQuerySet -- a QuerySet that always evaluates to an empty list. This can be used in cases where you know that you should return an empty result set and your caller is expecting a QuerySet object (instead of returning an empty list - fo






14. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r






15. Fields are specified by these






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






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






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






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






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






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






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






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






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






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






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






27. In some complex data-modeling situations - your models might contain a lot of fields - some of which could contain a lot of data (for example - text fields) - or require expensive processing to convert them to Python objects. If you are using the res






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






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






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






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






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






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






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






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






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






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






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






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






40. Lookup type that returns results with a case-sensitive end sequence.






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






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






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






44. To activate your models






45. Conjuntion operator for Q objects.






46. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.






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






48. Exception raised by get(**kwargs) if no items match the query.






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






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