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






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






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






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






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






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






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






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






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






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






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






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


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






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






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






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






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






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






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






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






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






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






23. Conjuntion operator for Q objects.






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






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






26. To activate your models






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






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






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






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






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






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






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






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






35. Fields are specified by these






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






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






38. Disjunction operator for Q objects.






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






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






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






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






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






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






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






46. If this option is True - Django will store empty values as NULL in the database. Default is False.






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






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






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






50. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on