Recall & Review
beginner
What is the purpose of the
search_fields attribute in Django's admin?The
search_fields attribute allows you to specify which model fields should be searchable in the Django admin interface. It enables a search box that filters the list view based on the entered query.Click to reveal answer
beginner
How do you enable ordering of model records in Django admin?
You can enable ordering by setting the <code>ordering</code> attribute in the model's <code>Meta</code> class or by using the <code>ordering</code> attribute in the admin class. This controls the default order of records shown.Click to reveal answer
intermediate
What does the
ordering attribute accept in Django models or admin?It accepts a list or tuple of field names as strings. Prefixing a field name with a minus sign (
-) orders it in descending order; otherwise, ascending order is used.Click to reveal answer
intermediate
How can you add search functionality to a Django REST Framework API view?
You add the <code>SearchFilter</code> class to the view's <code>filter_backends</code> and specify <code>search_fields</code>. This enables searching by query parameters on specified fields.Click to reveal answer
intermediate
What is the difference between
search_fields and ordering_fields in Django REST Framework?search_fields defines which fields can be searched using a query string, while ordering_fields defines which fields can be used to order the results. Both are used with filter backends.Click to reveal answer
In Django admin, which attribute enables a search box to filter records?
✗ Incorrect
The
search_fields attribute adds a search box in Django admin to filter records by specified fields.How do you specify descending order for a field in Django model ordering?
✗ Incorrect
Prefixing a field name with a minus sign (
-) orders the results in descending order.Which Django REST Framework filter backend enables search functionality?
✗ Incorrect
SearchFilter enables search functionality in Django REST Framework views.What does the
ordering_fields attribute do in Django REST Framework?✗ Incorrect
ordering_fields specifies which fields clients can use to order API results.Where do you set the default ordering of records in a Django model?
✗ Incorrect
The default ordering is set in the model's
Meta class with the ordering attribute.Explain how to add search and ordering features to a Django admin interface.
Think about attributes in admin classes and model Meta.
You got /4 concepts.
Describe how to implement search and ordering in a Django REST Framework API view.
Focus on filter backends and query parameters.
You got /4 concepts.