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. A QuerySet is iterable - and it executes its database query the first time you iterate over it.






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






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






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






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






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






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






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






9. Lookup type that returns results less than a given value.






10. Fields are specified by these






11. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.


12. Defines a one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.






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






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






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






16. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.






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






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






19. Negation operator for Q objects.






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






44. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.






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






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






47. This gives your model metadata.






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






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






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