Please make sure you have pip and pipenv installed first.
git clone https://github.com/hhss16/Lab3
cd Lab3
pipenv shell
pipenv install
python manage.py makemigrations
python manage.py migrate
python manage.py runserverExtra djangorestframework-xml was installed using pipenv
Then access http://127.0.0.1:8000/api/menu-items or http://127.0.0.1:8000/api/menu-items/1 - full support for GET and POST for menu items and full support for GET, PUT, PATCH and DELETE for single menu item.
It has full validation support done in the serializers.py - check that extra_kwargs section. Price cannot be less than 2 and inventory cannot be negative.
class MenuItemSerializer(serializers.ModelSerializer):
class Meta:
model = MenuItem
fields = ['id','title','price','inventory']
extra_kwargs = {
'price': {'min_value': 2},
'inventory':{'min_value':0}
}JSON XMLRenderer is added in the settings.py file
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
'rest_framework_xml.renderers.XMLRenderer',
]
}And you can access http://127.0.0.1:8000/api/menu-items?format=xml and http://127.0.0.1:8000/api/menu-items?format=json



