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






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






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






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






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






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






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






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






9. Returns a new QuerySet containing objects that match the given lookup parameters.






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






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






12. To activate your models






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






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






15. When to run syncdb






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






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






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






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






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






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






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






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






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






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






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






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






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






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






30. Conjuntion operator for Q objects.






31. Lookup type that returns results with a case-sensitive end sequence.






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






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






34. This is a criterion that narrow down a QuerySet based on given parameters.






35. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th






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






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






38. Fields are specified by these






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






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






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






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






43. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.






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






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






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






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






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






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






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