# django-restframework-test **Repository Path**: nian199919/django-restframework-test ## Basic Information - **Project Name**: django-restframework-test - **Description**: django restframework test - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 23 - **Created**: 2020-11-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Coding challenge - API We'd like to extend this Django REST Framework project (based on the one found [here](https://github.com/beheshtraya/django_rest_sample)). The API stores information about authors, categories and books. We'd like to let our API users view library statistics, namely: 1. Total number of books owned. 2. Total cost of all books. 3. Author with most books. 4. Category with most books. There are a few ways to approach this; feel free to choose one that seems appropriate, and please explain why you think it's best for us. 方案1 1、从数据库里把图书总书读取出来并且将返回值返回在number函数上 2、将预先从数据库的所有书籍计算总价并且将返回值返回在total函数上 3、将书籍作者按照书籍数量来排序并且将返回值返回在works函数上 4、按照书籍标签给书籍分类,并且将返回值返回在label函数上 5、在index上读取number函数、total函数、works函数、label函数,用户即可直接查看统计出来的结果 方案2 1、从数据库里把图书总书读取出来并且将返回值展示在number端口上 2、将预先从数据库的所有书籍计算总价并且将返回值返回在total端口上 3、将书籍作者按照书籍数量来排序并且将返回值返回在works端口上 4、按照书籍标签给书籍分类,并且将返回值返回在label端口上 5、将四个端口设置为一个按钮,并设置超链接 6、当用户点击其中一个按钮即可查看其中一个信息 我建议选择方案1,因为方案1比较适合用于管理系统的界面,管理者一般比较喜欢登录进来就可以观察到统计数据,而方案2则需要自己手动去点击按钮才显示数据,所有我认为方案1比较适合。 We've also heard of at least one bug in the codebase. Can you try to identify issues in the existing code, and document how you discovered and fixed the bugs? 问题1 在django-restframework-test\library_app\serializers.py语法错误,CategorySerializer方法应写在category引用的前面。 问题2 django-restframework-test\library_app\serializers.py底下user的model的name参数设置了可以为空,可以修改__str__的返回值 Also: - Please treat all code as production level code. - Please don’t spend more than 4 hours on this. If time runs short, an explanation of what you would do given more time is fine. ## Original `readme.txt` > pip install -r requirements.txt > python manage.py makemigrations > python manage.py migrate > python manage.py runserver -- server will be run on 127.0.0.1:8000 开发笔记: 将代码下载到本地桌面解压,使用pycharm打开 1、启动terminal 运行pip install -r requirements.txt 2、初始化db python manage.py makemigrations python manage.py migrate 3、启动 python manage.py runserver 127.0.0.1:8000 启动发现报错,于是修改报错的地方 4、首先打开django-restframework-test\django_rest_sample\settings.py 将ALLOWED_HOSTS 改成如下 ALLOWED_HOSTS = [‘*‘] 5、打开django-restframework-test\library_app\serializers.py CategorySerializer方法剪切到BookReadSerializer方法上面 6、可以正常访问http://127.0.0.1:8000/ 7、在 terminal下运行python manage.py createsuperuser创建超级用户 8、使用刚刚创建的用户登录http://127.0.0.1:8000/admin/即可查看数据