Momentum logo
Team 10 Classroom

🍔 Django with a Side of JavaScript 🍟

Posted on Nov 16th, 2021

🗓️ Today’s Topics

  • Progress report on Code Snippets and Flashcards
  • Incorporating JavaScript in a Django application

🎯 Project: Code Snippets | Flashcards

Still working on your project. (っ^з^)♪♬

Where you should be with Flashcards today

A logged in user should be able to see a list of all the decks, see the cards in a given deck (after it is selected from the list, for instance), and see the question and answer on a given card. The forms for creating a deck and creating cards for a deck should be done by now. You should be working on marking a card as answered, correctly or incorrectly, and be able to record that data somewhere. If decks belong to one user and are not shared, then you could record this on your deck, but it’s up to you how you model this.

Where you should be with Code Snippets today

A logged in user should be able to see a list of all public snippets and a list of their own snippets, to create new snippets, and to edit and delete existing snippets. You should have a way to manage copying snippets on the back end at least. You may also be ready to start implementing syntax highlighting with JS by this afternoon or evening.

🔖 Resources

Debugging while you work

Setting a breakpoint can help you figure out what code you need in your views!

JavaScript & Django

  • Django and AJAX
  • Fetching Data with Ajax and Django -> This article is really helpful and has really good code examples. Important notes:

    By including the ‘X-Requested-With’ header set to ‘XMLHttpRequest’ [in the AJAX request], the view will be able to check if the request is AJAX or not.

    # In the view function that handles the AJAX request
    request.headers.get('x-requested-with') == 'XMLHttpRequest'

⭐ EXTRA/TMI

  • Django Views the Right Way This is a detailed, informative deep dive on function-based views in Django and the reasons why, in the author’s opinion, they are better than class-based views.
  • jQuery This is not something I recommend using right now, but I include it here because a lot of the resources about using JavaScript in a web browser refer to it (several of the articles above do). It is not as popular as it once was, and it is incompatible with a framework like React. But you will sometimes come across it, and you may end up working with it at your job, so you might as well recognize it when you see it and look it up if you ever need it.

🦉 Code

🔎 Django Search 🕵️‍♂️

Posted on Nov 15th, 2021

🗓️ Today’s Topics

  • Checking in on Code Snippets and Flashcards progress
  • Git collaboration review & questions
  • Django review & questions
  • Implementing search
  • Foreign key recursive relationships

🎯 Project: Code Snippets | Flashcards

Keep on with your end-of-phase project. Today you should have models that you can use in the shell and in your application and at least a solid start on the CRUD functionality your application needs.

🔖 Resources

Debugging

Foreign Keys

Models & Queries

  • LearnDjango: SearchTutorial Will uses class-based views in this post but you can still follow almost all of his steps and use function-based views.
  • MDN: Sending Form Data Scroll down to the section on the GET method to see how to include form data as query parameters.

Collaborating on a web application

Posted on Nov 10th, 2021

🗓️ Today’s Topics

  • Many-to-many model relationships & queries
  • Slugs
  • Collaboration in a shared repo

✅ Questions to Check Your Understanding

You’ve been using Django for about a week now. Can you answer these questions? 🤔

  • If you want to show one specific book in the browser, how would that work in the urls and the views?
  • How do forms work in Django? You should be able to talk about form objects and how forms are handled in the views.
  • Can you create new objects, find objects, and find related objects in the Django shell?
  • How does Django know if a user is logged in?
  • How can you implement books with multiple categories?

🎯 Project: Django Team Project

Today we’ll begin our first real team project, with a shared repo. This will require more planning, a lot of communication and coordination, and adding on some new Git skills that will let us collaborate.

You will work in a shared repo and submit one application that your team will build together. You need to discuss who will do what, but keep in mind that the work needs to be shared as equally as possible.

You have two options to choose from for this assignment. Your team should meet to discuss and decide today which one you will do.

Then, the very first thing you should do is determine what models you will need and what attributes and relationships they should have. A diagram can be very helpful here.

This assignment is due next Thursday at the end of the Phase.

Dev Teams

For this project, the first team member listed should accept the assignment and enter the name of your team. The other team members can then accept the assignment and select the repo for their team.

  • Team Hufflepuff: Trent, Jeffrey, James A.
  • Team Ravenclaw: Janelle, Zack, James M.
  • Team Gryffindor: Jordyn, RJ, Lila
  • Team Slytherin: Trey, Jason, Keanya, Jonathan

👉 Link to Django Duplex assignment

✅ Project Checklist

  • Set up a new Django project from scratch. There is no starter code in the assignment repo.
  • Make sure to create a .gitignore file to exclude certain files (like your .env file and db.sqlite3) from Git. You can get one specific to a Django project at gitignore.io. Just search for Django and copy and paste the text you find there into your .gitignore file. It should be placed at the root of your repo.
  • Make sure to create a custom user model, following best practices. Do this before you run any other migrations. This guide may be helpful to you.
  • You may want to install django-debug-toolbar, django-extenstions, and django-environ, as we have done in previous projects.

🔖 Resources

Collaboration

  • GitHub Collaboration Docs
  • Git Collaboration slides
  • Git in VS Code Not everyone loves using git on the command line like I do. A lot of folks like using the integration in VS Code, so you might want to give it a try. This is a good place to start, but there are many other extensions that you could use as well.
  • Pair Programming Guide This template for a pairing session is practical and actionable. There are other resources on this site worth a look as well.

Django

🦉 Code & Notes

Django Models and Relationships

Posted on Nov 9th, 2021

🗓️ Today’s Topics

  • Review registration & authentication
  • Model fields
  • Database tables
  • One-to-many (O2M) and Many-to-many (M2M) relationships
  • ER Diagrams

🎯 Project

Continue working on Freeshelf, through Goals 2 and 3.

🔖 Resources

🦉 Code & Notes

Tags: phase-2 django

🍁 🧣 🫖 🍂 November of Django 🍂 🫖 🧣 🍁

Posted on Nov 8th, 2021

You’ve now seen how to handle data in a Django application with basic operations in these CRUD categories:

  • Create - when we add a new model instance to the database
  • Read - when we query the database to look up existing data
  • Update - when we query the database to find existing data so we can change it
  • Destroy - when we find existing data in the database and delete it

At the heart of many web applications you’ll find variations on this theme, so we’ll continue to practice it.

Today we’ll add in another essential part of web applications: user registration and login.

📋 Django Music Project Review

  • 😲 What was one AHA! moment you had?
  • ⏲️ What did you spend the most time on?
  • 😕 What is something that you’d like to understand better?

🎯 Project: Freeshelf

This is a 3-day assignment that you’ll work on all week. It is due on Thursday, November 11.

📚 Django Freeshelf

🔖 Resources

🦉 Code