Sometimes, you want to combine data from different models. It's not hard to do this with Python, but generic relationships allow Django to do this for you.
- [Instructor] As you start to build non-trivial apps,…you'll occasionally feel constrained by the limits…of the database techniques demonstrated…in most Django tutorials.…The great news is that you actually have…a lot of power available to you if you just…dig a little deeper, and that's what we'll do…in this section.…We'll start out by discussing generic relationships.…Then, we'll work on using advanced formsets…to make data management easier.…Then we'll cover how to do advanced queries…using the Q function.…In this video, we'll focus on generic relationships.…
In the last section, we created a song database.…There was a model for artist, albums, and songs.…Suppose you wanted to add a favorites feature…where you can see a list of your favorite songs,…artists, and albums.…You could do three queries and…combine the results in Python.…But wouldn't it be nice if there was a way…to not repeat ourselves?…Django has the concept of generic relationships.…These are just like a foreign key relationship,…but the join is done with Python,…
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