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. If True - this field is the primary key for the model.






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






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






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






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


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






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






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






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






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






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






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






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


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






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






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






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






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






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


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






21. A convenience method for constructing an object and saving it all in one step.






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






23. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.






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






25. Negation operator for Q objects.






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






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






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






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






30. When to run syncdb






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






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






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






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






35. If this option is True - the field is allowed to be blank. Default is False.






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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