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. A convenience method for constructing an object and saving it all in one step.






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


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






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






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






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






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






8. This gives your model metadata.






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






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






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






12. Disjunction operator for Q objects.






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






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






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






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






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






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






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






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






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






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






23. Fields are specified by these






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






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






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






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






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






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






30. Returns the object matching the given lookup parameters






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






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






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






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






35. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o






36. To activate your models






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






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






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






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






41. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.






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






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






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






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






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






47. Exception raised by get(**kwargs) if more than one item matches the query.






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






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






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