Skip to content

Commit

Permalink
docs(add-model): adjust annotations
Browse files Browse the repository at this point in the history
Repositioned and combined a couple of them.
  • Loading branch information
fyliu committed Jul 18, 2024
1 parent 0eb1d5b commit 042ff9b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/how-to/add-model-and-api-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,11 @@ In `app/core/api/views.py`
class UserViewSet(viewsets.ModelViewSet):
...

# (1)!
def get_queryset(self): # (2)!
def get_queryset(self): # (1)!
"""
Optionally filter users by an 'email' and/or 'username' query paramerter in the URL
"""
queryset = get_user_model().objects.all() # (3)!
queryset = get_user_model().objects.all() # (2)!
email = self.request.query_params.get("email")
if email is not None:
queryset = queryset.filter(email=email)
Expand All @@ -412,7 +411,9 @@ In `app/core/api/views.py`
```

1. Notice the `queryset` property is now the `get_queryset(()` function which returns the queryset.
1. The `get_queryset()` function overrides the default and lets us filter the objects returned to the client if they pass in a query param.
The `get_queryset()` function overrides the default and lets us filter the objects returned to the client if they pass in a query param.
1. Start with all the model objects and filter them based on any available query params.
### Register API endpoints
Expand All @@ -428,8 +429,8 @@ In `app/core/api/urls.py`
1. [Register](https://www.django-rest-framework.org/api-guide/routers/#usage) the viewset to the [router](https://www.django-rest-framework.org/api-guide/routers/)
```python
# (1)!
router.register(r"recurring-events", RecurringEventViewSet, basename="recurring-event")
# (1)!
```
1. Params
Expand Down

0 comments on commit 042ff9b

Please sign in to comment.