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. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






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






18. Negation operator for Q objects.






19. When to run syncdb






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






21. Fields are specified by these






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






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. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.


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






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






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






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






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






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






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






32. Returns the object matching the given lookup parameters






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






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






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






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






37. Disjunction operator for Q objects.






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






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






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






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






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






43. This tells Django how to calculate the URL for an object. Django uses this in its admin interface - and any time it needs to figure out a URL for an object.






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






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






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






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






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






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






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