Do you frequently perform the same query and filter operation in multiple views? Avoid duplication using model managers.
- [Instructor] In this section we'll discuss using…Model Managers to help keep your complex data…operations dry and manageable.…We'll discuss model managers in this video…and in the next video extend our knowledge…so that we can use Managers to create new objects.…And finally, look at custom manage.py commands.…Let's start out with an over view of managers.…Every model has a manager, by default it's called Objects.…In previous videos we've looked up songs…using the default manager.…We use syntax such as…song.objects.filter.…
I'm sure you've seen that numerous times…and didn't really give it a second thought.…If you have some special behavior you'd like to add…you can create your own manager and use it…instead of the default one.…You don't even have to call it objects,…though I would stick with that name…unless you have good reason to use something else.…You can have multiple model managers…but I'd start out small and get more complex over time.…Having heavily customized or multiple model managers…can impact how Django admin area works.…
Django is one of the world's leading web development platforms. This Python web framework makes your app building experience smoother, faster, and easier. It is a key feature behind the success of many start-ups across the world, including Instagram and Nextdoor. This course introduces next-level advanced concepts to help you build your own professional-grade Django applications.
Author Kevin Veroneau starts off by explaining how class-based views—a powerful, but often poorly understood feature—work in Django. Then learn how to create custom middleware to help organize frequently used code. Have you ever wanted to build a complete RESTful API? Find out how to do just that, starting with a basic read-only API and then adding key-based authentication to allow the full range of CRUD functionality. Plus, discover how to use model managers and the Q method to make it easier to get the data we need to our views and clients.
For the finishing touches, dive into the details of caching to improve application performance, and then add custom management commands to help automate routine tasks.
- Extending class-based views
- Creating custom class-based views
- Managing your database with middleware
- Creating template filters and tags
- Building a RESTful API
- Modeling advanced database relationships and queries
- Using a model manager for your application