khashashin
khashashin

Reputation: 1127

Adding additional data in the DRF api endpoint

My endpoints.py have:

from wagtail.api.v2.endpoints import BaseAPIEndpoint

from .models import Week, Ingredient, Menu

class WeekAPIEndpoint(BaseAPIEndpoint):
    model = Week
def register_endpoints(api_router):
    api_router.register_endpoint('week', WeekAPIEndpoint)

And if I follow the link 127.0.0.1:8000/api/v2/week i get this:

enter image description here

Is it possible to raise data by one step in DRF endpoints? from here 127.0.0.1:8000/api/v2/week/1:

enter image description here

I opened issue in my github. Didn't want to create too big a question here.

Upvotes: 0

Views: 235

Answers (1)

khashashin
khashashin

Reputation: 1127

As suggested by @Oleg here, the problem is solved by adding 1 line of code in the endpoints like there:

class WeekAPIEndpoint(BaseAPIEndpoint):
    model = Week
    listing_default_fields = BaseAPIEndpoint.listing_default_fields + ['year', 'week']

so its takes my "year" and "week" fields and picks them up, so my api endpoint looks good Thanks @oleg.

enter image description here

Upvotes: 1

Related Questions