Summary

This was a pretty demanding chapter, and you learned a lot of new information.

For starters, we looked at Django management commands. They are an important feature of Django. All Django commands that you run, such as python manage.py startapp, are management commands as well, so you should already know how powerful they can be. In bigger projects, you almost always have a few management commands to automate your tasks for you.

We also looked at how Django creates a string representation of our models using the __str__ method on our model class. It's not just used when printing to the console either. Any time you try to use your model objects as strings, even in your templates, Django uses this representation, so it's important to have a good format that can immediately give you all the important information about an object.

This chapter also introduced advance query methods, specifically the distinct and values methods that allow you to issue more complicated SQL queries to get data in exactly the format you want from the database. However, this is just the beginning. In later chapters, we might need to use more complicated query methods. You might want to look at the Django documentation for queryset methods at https://docs.djangoproject.com/en/stable/ref/models/querysets/ to learn about more methods of querying the databases that Django provides.

In addition to getting data from the database in a format that we wanted, we also looked at preparing a somewhat complicated data structure with the data to pass all the required information to templates, and then saw how to use that data structure in our templates.

Often, you have complicated data validation rules that you need to ensure are passing before you can save data to a database. We looked at how to achieve this in this chapter by overriding the save method of our model classes.

Finally, you learned how to create simple API endpoints and how to test them using curl or Postman. Overall, this was a big chapter that introduced a lot of new concepts that will be used in later chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.66