Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Matt Layman
Matt Layman

Posted on • Originally published atmattlayman.com

Handle Default Values - Building SaaS #65

In this episode, I updated a model to handle the default duration of new tasks. This default needed to come from the Course model instead of the CourseTask model so we had to determine how best to set that data in various forms. I also fixed some drop down selection bugs that populated a form with the wrong data. We made sure that all the code was well tested.

I created a newdefault_task_duration field to theCourse model. The field records the number of minutes that will be set when create a new task. We added the field and wrote some model tests to confirm the behavior.

Then we updated theCourse creation and edit forms. To do this, I needed to add the new field to theCourseForm model form and update the template to include the new field. After that, I fixed the POST tests that broke because the required field was missing.

Once theCourse form was done, I moved on to theCourseTask views. We had to useget_initial to populate theCourseTask form with the right data from theCourse. The data inget_initial was also needed byget_context_data so I created acached_property to store the course and save an extra SQL query.

The next issue that I fixed was a problem with the selector for the task form. The form would display the wrong grade levels when a task could be added to multiple grades. The code pulled the grades from the current school year instead of the pulling the grade levels from the schoool year associated with the course. We found the error in the code and corrected the queries that were needed. After correcting the code, I added some test code to confirm that the problem was fixed programmatically.

At the end of the stream, I answered some questions from the stream about software interviews and portfolios.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Matt Layman is a software engineer from Frederick, MD. He is an open source software maintainer and advocate for Python.
  • Location
    Frederick, MD, USA
  • Work
    Senior Software Engineer at Doctor on Demand
  • Joined

More fromMatt Layman

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp