├── .gitignore ├── consume.py ├── db.sqlite3 ├── drink_api ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── admin.cpython-310.pyc │ ├── apps.cpython-310.pyc │ ├── models.cpython-310.pyc │ ├── serializers.cpython-310.pyc │ ├── urls.cpython-310.pyc │ └── views.cpython-310.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-310.pyc │ │ └── __init__.cpython-310.pyc ├── models.py ├── serializers.py ├── tests.py ├── urls.py └── views.py ├── drinks ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── admin.cpython-310.pyc │ ├── models.cpython-310.pyc │ ├── settings.cpython-310.pyc │ ├── urls.cpython-310.pyc │ └── wsgi.cpython-310.pyc ├── admin.py ├── asgi.py ├── models.py ├── settings.py ├── urls.py └── wsgi.py └── manage.py /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # GhostDoc plugin setting file 270 | *.GhostDoc.xml 271 | 272 | # Node.js Tools for Visual Studio 273 | .ntvs_analysis.dat 274 | node_modules/ 275 | 276 | # Visual Studio 6 build log 277 | *.plg 278 | 279 | # Visual Studio 6 workspace options file 280 | *.opt 281 | 282 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 283 | *.vbw 284 | 285 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 286 | *.vbp 287 | 288 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 289 | *.dsw 290 | *.dsp 291 | 292 | # Visual Studio 6 technical files 293 | *.ncb 294 | *.aps 295 | 296 | # Visual Studio LightSwitch build output 297 | **/*.HTMLClient/GeneratedArtifacts 298 | **/*.DesktopClient/GeneratedArtifacts 299 | **/*.DesktopClient/ModelManifest.xml 300 | **/*.Server/GeneratedArtifacts 301 | **/*.Server/ModelManifest.xml 302 | _Pvt_Extensions 303 | 304 | # Paket dependency manager 305 | .paket/paket.exe 306 | paket-files/ 307 | 308 | # FAKE - F# Make 309 | .fake/ 310 | 311 | # CodeRush personal settings 312 | .cr/personal 313 | 314 | # Python Tools for Visual Studio (PTVS) 315 | __pycache__/ 316 | *.pyc 317 | 318 | # Cake - Uncomment if you are using it 319 | # tools/** 320 | # !tools/packages.config 321 | 322 | # Tabs Studio 323 | *.tss 324 | 325 | # Telerik's JustMock configuration file 326 | *.jmconfig 327 | 328 | # BizTalk build output 329 | *.btp.cs 330 | *.btm.cs 331 | *.odx.cs 332 | *.xsd.cs 333 | 334 | # OpenCover UI analysis results 335 | OpenCover/ 336 | 337 | # Azure Stream Analytics local run output 338 | ASALocalRun/ 339 | 340 | # MSBuild Binary and Structured Log 341 | *.binlog 342 | 343 | # NVidia Nsight GPU debugger configuration file 344 | *.nvuser 345 | 346 | # MFractors (Xamarin productivity tool) working folder 347 | .mfractor/ 348 | 349 | # Local History for Visual Studio 350 | .localhistory/ 351 | 352 | # Visual Studio History (VSHistory) files 353 | .vshistory/ 354 | 355 | # BeatPulse healthcheck temp database 356 | healthchecksdb 357 | 358 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 359 | MigrationBackup/ 360 | 361 | # Ionide (cross platform F# VS Code tools) working folder 362 | .ionide/ 363 | 364 | # Fody - auto-generated XML schema 365 | FodyWeavers.xsd 366 | 367 | # VS Code files for those working on multiple tools 368 | .vscode/* 369 | !.vscode/settings.json 370 | !.vscode/tasks.json 371 | !.vscode/launch.json 372 | !.vscode/extensions.json 373 | *.code-workspace 374 | 375 | # Local History for Visual Studio Code 376 | .history/ 377 | 378 | # Windows Installer files from build outputs 379 | *.cab 380 | *.msi 381 | *.msix 382 | *.msm 383 | *.msp 384 | 385 | # JetBrains Rider 386 | *.sln.iml 387 | 388 | ########################################################################### 389 | # Byte-compiled / optimized / DLL files 390 | __pycache__/ 391 | *.py[cod] 392 | *$py.class 393 | 394 | # C extensions 395 | *.so 396 | 397 | # Distribution / packaging 398 | .Python 399 | build/ 400 | develop-eggs/ 401 | dist/ 402 | downloads/ 403 | eggs/ 404 | .eggs/ 405 | lib/ 406 | lib64/ 407 | parts/ 408 | sdist/ 409 | var/ 410 | wheels/ 411 | share/python-wheels/ 412 | *.egg-info/ 413 | .installed.cfg 414 | *.egg 415 | MANIFEST 416 | 417 | # PyInstaller 418 | # Usually these files are written by a python script from a template 419 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 420 | *.manifest 421 | *.spec 422 | 423 | # Installer logs 424 | pip-log.txt 425 | pip-delete-this-directory.txt 426 | 427 | # Unit test / coverage reports 428 | htmlcov/ 429 | .tox/ 430 | .nox/ 431 | .coverage 432 | .coverage.* 433 | .cache 434 | nosetests.xml 435 | coverage.xml 436 | *.cover 437 | *.py,cover 438 | .hypothesis/ 439 | .pytest_cache/ 440 | cover/ 441 | 442 | # Translations 443 | *.mo 444 | *.pot 445 | 446 | # Django stuff: 447 | *.log 448 | local_settings.py 449 | db.sqlite3 450 | db.sqlite3-journal 451 | 452 | # Scrapy stuff: 453 | .scrapy 454 | 455 | # Sphinx documentation 456 | docs/_build/ 457 | 458 | # PyBuilder 459 | .pybuilder/ 460 | target/ 461 | 462 | # Jupyter Notebook 463 | .ipynb_checkpoints 464 | 465 | # IPython 466 | profile_default/ 467 | ipython_config.py 468 | 469 | # pyenv 470 | # For a library or package, you might want to ignore these files since the code is 471 | # intended to run in multiple environments; otherwise, check them in: 472 | # .python-version 473 | 474 | # pipenv 475 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 476 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 477 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 478 | # install all needed dependencies. 479 | #Pipfile.lock 480 | 481 | # poetry 482 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 483 | # This is especially recommended for binary packages to ensure reproducibility, and is more 484 | # commonly ignored for libraries. 485 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 486 | #poetry.lock 487 | 488 | # pdm 489 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 490 | #pdm.lock 491 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 492 | # in version control. 493 | # https://pdm.fming.dev/#use-with-ide 494 | .pdm.toml 495 | 496 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 497 | __pypackages__/ 498 | 499 | # Celery stuff 500 | celerybeat-schedule 501 | celerybeat.pid 502 | 503 | # SageMath parsed files 504 | *.sage.py 505 | 506 | # Environments 507 | .env 508 | .venv 509 | env/ 510 | venv/ 511 | ENV/ 512 | env.bak/ 513 | venv.bak/ 514 | 515 | # Spyder project settings 516 | .spyderproject 517 | .spyproject 518 | 519 | # Rope project settings 520 | .ropeproject 521 | 522 | # mkdocs documentation 523 | /site 524 | 525 | # mypy 526 | .mypy_cache/ 527 | .dmypy.json 528 | dmypy.json 529 | 530 | # Pyre type checker 531 | .pyre/ 532 | 533 | # pytype static type analyzer 534 | .pytype/ 535 | 536 | # Cython debug symbols 537 | cython_debug/ 538 | 539 | # PyCharm 540 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 541 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 542 | # and can be added to the global gitignore or merged into this file. For a more nuclear 543 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 544 | #.idea/ -------------------------------------------------------------------------------- /consume.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | print("testing") 4 | 5 | response = requests.get('http://127.0.0.1:8000/drinks') 6 | print(response.json()) -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/db.sqlite3 -------------------------------------------------------------------------------- /drink_api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__init__.py -------------------------------------------------------------------------------- /drink_api/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/admin.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/admin.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/apps.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/apps.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/models.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/models.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/serializers.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/serializers.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/__pycache__/views.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/__pycache__/views.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Drink 4 | # Register your models here. 5 | admin.site.register(Drink) -------------------------------------------------------------------------------- /drink_api/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class DrinkApiConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'drink_api' 7 | -------------------------------------------------------------------------------- /drink_api/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1 on 2022-09-04 11:36 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Drink', 16 | fields=[ 17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=200)), 19 | ('description', models.CharField(max_length=500)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /drink_api/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/migrations/__init__.py -------------------------------------------------------------------------------- /drink_api/migrations/__pycache__/0001_initial.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/migrations/__pycache__/0001_initial.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/migrations/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drink_api/migrations/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /drink_api/models.py: -------------------------------------------------------------------------------- 1 | # Create your models here. 2 | from django.db import models 3 | 4 | class Drink(models.Model): 5 | name = models.CharField(max_length=200) 6 | description = models.CharField(max_length=500) 7 | 8 | def __str__(self): 9 | return self.name + self.description -------------------------------------------------------------------------------- /drink_api/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | 3 | from .models import Drink 4 | 5 | class DrinkSerializer(serializers.ModelSerializer): 6 | class Meta: 7 | model = Drink 8 | fields = ['id','name','description'] 9 | -------------------------------------------------------------------------------- /drink_api/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /drink_api/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | from rest_framework.urlpatterns import format_suffix_patterns 4 | urlpatterns = [ 5 | path('',views.drink_list,name="drinklist"), 6 | path("",views.drink_detail,name='drink_list'), 7 | ] 8 | 9 | 10 | urlpatterns = format_suffix_patterns(urlpatterns) -------------------------------------------------------------------------------- /drink_api/views.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | 3 | from .serializers import DrinkSerializer 4 | from .models import Drink 5 | from . import serializers 6 | from rest_framework.decorators import api_view 7 | # Create your views here. 8 | from rest_framework import status 9 | from rest_framework.response import Response 10 | @api_view(['GET','POST']) 11 | def drink_list(request,format=None): 12 | if request.method == "GET": 13 | drinks = Drink.objects.all() 14 | serializer = DrinkSerializer(drinks,many=True) 15 | return JsonResponse({'drinks':serializer.data},) 16 | 17 | if request.method == 'POST': 18 | serializer = DrinkSerializer(data = request.data) 19 | if serializer.is_valid(): 20 | serializer.save() 21 | return Response(serializer.data, status = status.HTTP_201_CREATED) 22 | 23 | @api_view(['GET','PUT','DELETE']) 24 | def drink_detail(request,id,format=None): 25 | try: 26 | drink = Drink.objects.get(pk=id) 27 | except Drink.DoesNotExist: 28 | return Response(status=status.HTTP_404_NOT_FOUND) 29 | 30 | if request.method == 'GET': 31 | serializer = DrinkSerializer(drink) 32 | return Response(serializer.data) 33 | elif request.method == 'PUT': 34 | serializer = DrinkSerializer(drink, data= request.data) 35 | if serializer.is_valid(): 36 | serializer.save() 37 | return Response(serializer.errors, status = status.HTTP_400_BAD_REQUEST) 38 | elif request.method == 'DELETE ': 39 | drink.delete() 40 | return Response(status=status.HTTP_204_NO_CONTENT) 41 | -------------------------------------------------------------------------------- /drinks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__init__.py -------------------------------------------------------------------------------- /drinks/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/__pycache__/admin.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/admin.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/__pycache__/models.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/models.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/__pycache__/settings.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/settings.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/__pycache__/wsgi.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/__pycache__/wsgi.cpython-310.pyc -------------------------------------------------------------------------------- /drinks/admin.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/admin.py -------------------------------------------------------------------------------- /drinks/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for drinks project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drinks.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /drinks/models.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/backendbuilderdev/django-api2/836dbd8dfbb78bdba7a1317f133cca25bd418feb/drinks/models.py -------------------------------------------------------------------------------- /drinks/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for drinks project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-n@q7t$l!d9nkbbxn)k00sx!!vr8)&hmagzmeel_vjdbopo!u57' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'rest_framework', 39 | 'drinks', 40 | 'drink_api', 41 | 'django.contrib.messages', 42 | 'django.contrib.staticfiles', 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | ] 54 | 55 | ROOT_URLCONF = 'drinks.urls' 56 | 57 | TEMPLATES = [ 58 | { 59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 60 | 'DIRS': [], 61 | 'APP_DIRS': True, 62 | 'OPTIONS': { 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'drinks.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/4.1/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': BASE_DIR / 'db.sqlite3', 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/4.1/howto/static-files/ 120 | 121 | STATIC_URL = 'static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /drinks/urls.py: -------------------------------------------------------------------------------- 1 | """drinks URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('drinks/',include('drink_api.urls')), 22 | ] 23 | -------------------------------------------------------------------------------- /drinks/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for drinks project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drinks.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drinks.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | --------------------------------------------------------------------------------