mindcurrent / djanky-django

Daniel's Janky Attempt at a Django RESTful API Server
0 stars 1 forks source link

Create data model for first app: polls #10

Open dpcunningham opened 4 years ago

dpcunningham commented 4 years ago

Following: Creating models:

Now we’ll define your models – essentially, your database layout, with additional metadata...

$ pwd
/home/dpc/dpc.data/local.FS/lfs.03-Projects.Active/project.MindCurrent/dev/python/djankysite

$ vi ./polls/models.py     # Define model w/ djaongo's (pretty nice OO/class-driven) dialect
$ cat  ./polls/models.py 

$ vi  ./djankysite/settings.py   # Plug the new app into the site...
$ cat  ./djankysite/settings.py 

$ python3 manage.py makemigrations polls  # Generate the classes
Migrations for 'polls':
  polls/migrations/0001_initial.py
    - Create model Question
    - Create model Choice

$ cat ./polls/migrations/0001_initial.py    # Look at the generated classes...

$ python3 manage.py sqlmigrate polls 0001  # Test-run: show us the SQL

$ python3 manage.py migrate  # Looks OK  -- make it happen, cap'n!
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, polls, sessions
Running migrations:
  Applying polls.0001_initial... OK

OK, now (per the guide) we can start: Playing with the API (see the next issue).

Now, let’s hop into the interactive Python shell and play around with the free API Django gives you. To invoke the Python shell, use this command: