Skip to content

Releases: octaflop/django_music

Web Endpoints / API Example

03 Sep 01:55
Compare
Choose a tag to compare

4. web_endpoint

Instead of creating new models, we'll use the old ones from web_db to create Endpoints.

Endpoints are simply api endpoints which can be used by javascript or mobile to make changes to the DB.

  1. Spin up web_endpoints via ./manage.py startapp web_endpoints and mv it to apps
  2. Add web_endpoints to our INSTALLED_APPS list
  3. Ensure that [rest_framework](http://www.django-rest-framework.org) has been added to INSTALLED_APPS
  4. Create serializers for our Album and Song models in web_endpoints/serializers.py.
  5. We then use ViewSets and Routers to link everything else up.
  6. We will also write a custom creation method for the nested serializer.

Web DB / ORM Example

03 Sep 01:10
Compare
Choose a tag to compare

3. web_db

Now we're going to play with Django's ORM and admin: One of the main selling-points of Django vs other Web Libraries.

  1. Repeat steps 1-8 in web_pages
  2. Let's create a few DB models in models.py
  3. Now we need migrations for them
  4. We create the migrations with ./manage.py makemigrations web_db
  5. And migrate the db with ./manage.py migrate. Note, this will migrate all apps if you haven't done so already.
  6. Note, if you're using the repo, that we added a 0002 migration to populate with initial data
  7. We make things easier by using include for our URLS and adding our own urls.py definitions in the app, instead of the site.
  8. We also use Generic Views for listing.
  9. And we also add an admin.py file for easy management of the DB.
  10. We can visit localhost:8000/admin and localhost:8000/db/songs; etc for more views.
  11. Because our urls are named, we can use the {% url %} django template tag to directly link to a model's page (or the list page)

Web App Example

02 Sep 23:28
Compare
Choose a tag to compare

2. web_app

  1. Same steps as 1-8 in 01_web_page , substituting pages for app
  2. Let's edit the view this time. Note that template variables are just python dictionaries.
  3. Also edit the template.
  4. Create a new template and view function: dynamic.html.
  5. Add a <form> to this template using django forms
  6. Don't forget about csrf!

Web pages Example

02 Sep 22:45
Compare
Choose a tag to compare

1. web_pages

  1. git checkout -b web_page
  2. ./manage.py startapp web_pages && mv web_pages apps/web_pages
  3. Edit apps/django_music/urls.py
  4. Edit apps/web_pages/views.py
  5. Create a templates directory: mkdir -p apps/web_pages/templates/web_pages/
  6. Create a template in that directory
  7. Go to the local URL you set, in our case: `localhost:8000/pages/