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. A Python "magic method" that returns a unicode "representation" of any object.






3. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.

Warning: Invalid argument supplied for foreach() in /var/www/html/basicversity.com/show_quiz.php on line 183


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






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






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






7. Negation operator for Q objects.






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






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






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






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






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






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






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






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






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






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






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






19. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)






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


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






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






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






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






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






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






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. Fields are specified by these






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






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






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






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






33. Conjuntion operator for Q objects.






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






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






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






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






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






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


40. This gives your model metadata.






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






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






43. When to run syncdb






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






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






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






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






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






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






50. Lookup type that returns results greater than or equal to a given value.