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. This query deletes all Entry objects with a pub_date year of 2005.






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






3. These add custom "row-level" functionality to your objects. These act on a particular model instance.






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






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






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






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






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






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






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






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






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






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






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






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






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






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






18. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.






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


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






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






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






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






24. This query finds all entries with an id in the list [1 - 3 - 4]






25. To activate your models






26. This gives your model metadata.






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






28. Disjunction operator for Q objects.






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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