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. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.






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






3. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


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






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


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


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






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






9. Returns a DateQuerySet -- a QuerySet that evaluates to a list of datetime.datetime objects representing all available dates of a particular kind within the contents of the QuerySet.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


10. Lookup type that returns results greater than or equal to a given value.






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






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






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






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






15. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used






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






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






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






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






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






21. To activate your models






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






23. The database that will be used if this query is executed now






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






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






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






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






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






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






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






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






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






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






34. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.






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






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






37. Keyword shortcut for looking up an object by primary key.






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






39. Returns the object matching the given lookup parameters






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






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






42. This model type is useful if you only want to modify the Python-level behavior of a model - without changing the models fields in any way. This creates a stand-in for the original model. You can create - delete and update instances of this new model






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






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






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






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






47. Defines a many-to-one relationship. ou use it just like any other Field type: by including it as a class attribute of your model.






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






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






50. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo