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






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






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






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






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






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






7. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.






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






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






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






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






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






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






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






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. A convenience method for looking up an object with the given kwargs - creating one if necessary.






17. This query finds all entries between a start date of start_date and an end date of end_date.






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






19. If True - this field is the primary key for the model.






20. This gives your model metadata.






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






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






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






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






25. Lookup type that returns results with a case-sensitive start sequence.






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






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






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






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






30. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.






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






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






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






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






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






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






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






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






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






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






41. To activate your models






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






43. This method immediately deletes the object and has no return value.






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






45. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.






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






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






48. Conjuntion operator for Q objects.






49. Returns the object matching the given lookup parameters






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