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






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






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






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






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. Returns the object matching the given lookup parameters






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






8. Conjuntion operator for Q objects.






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






10. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary






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






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






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






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






15. Returns a dictionary of aggregate values (averages - sums - etc) calculated over the QuerySet. Each argument to this method specifies a value that will be included in the dictionary that is returned.






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






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






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






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






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






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






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






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






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






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






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






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






28. a QuerySet can be sliced - using Python's array-slicing syntax.






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






30. To activate your models






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






33. This method is for controlling which database the QuerySet will be evaluated against if you are using more than one database. The only argument this method takes is the alias of a database - as defined in DATABASES.






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






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






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






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






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






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






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






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






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






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






44. Lookup type that returns results with a case-insensitive end sequence.






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






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






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






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






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






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