Skip to content

hhss16/Lab3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instructions to run this project

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 runserver

Extra djangorestframework-xml was installed using pipenv

Previews & Information

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.

Preview Lab 3

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}
        }

validation

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

JSON

XML

About

Lab3 (Row 127) - Restaurant Menu API using Serialization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages