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. This gives your model metadata.






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






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






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






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






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






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






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






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






11. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.


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






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






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






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






16. By default - results returned by a QuerySet are ordered by the ordering tuple given by the ordering option in the model's Meta. You can override this on a per-QuerySet basis by using the this method.






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






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






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






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






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






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






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






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






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






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






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






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






30. Lookup type that finds a case-insensitive regular expression match.






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






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






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






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






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






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






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






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






39. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)






40. Fields are specified by these






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






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






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






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






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






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






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






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






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






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