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 model method saves a model instance to the database. This method has no return value.






2. Fields are specified by these






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






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






6. This gives your model metadata.






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






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






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






10. Disjunction operator for Q objects.






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






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






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






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






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






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






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






18. Returns the object matching the given lookup parameters






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






20. When to run syncdb






21. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.






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






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






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






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






26. Lookup type that yields a case-insensitive match.






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






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






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






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






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






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. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.






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






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






36. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.






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






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






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






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






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






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






43. Conjuntion operator for Q objects.






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






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






46. Negation operator for Q objects.






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






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






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






50. Used to get a QuerySet for a model. This is called 'objects' by default.






Can you answer 50 questions in 15 minutes?



Let me suggest you:



Major Subjects



Tests & Exams


AP
CLEP
DSST
GRE
SAT
GMAT

Most popular tests