Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Django in Production

You're reading from   Django in Production Expert tips, strategies, and essential frameworks for writing scalable and maintainable code in Django

Arrow left icon
Product type Paperback
Published in Apr 2024
Publisher Packt
ISBN-13 9781804610480
Length 348 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Arghya Saha Arghya Saha
Author Profile Icon Arghya Saha
Arghya Saha
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1 – Using Django and DRF to Build Modern Web Application
2. Chapter 1: Setting Up Django with DRF FREE CHAPTER 3. Chapter 2: Exploring Django ORM, Models, and Migrations 4. Chapter 3: Serializing Data with DRF 5. Chapter 4: Exploring Django Admin and Management Commands 6. Chapter 5: Mastering Django Authentication and Authorization 7. Part 2 – Using the Advanced Concepts of Django
8. Chapter 6: Caching, Logging, and Throttling 9. Chapter 7: Using Pagination, Django Signals, and Custom Middleware 10. Chapter 8: Using Celery with Django 11. Chapter 9: Writing Tests in Django 12. Chapter 10: Exploring Conventions in Django 13. Part 3 – Dockerizing and Setting Up a CI Pipeline for Django Application
14. Chapter 11: Dockerizing Django Applications 15. Chapter 12: Working with Git and CI Pipelines Using Django 16. Part 4 – Deploying and Monitoring Django Applications in Production
17. Chapter 13: Deploying Django in AWS 18. Chapter 14: Monitoring Django Application 19. Index 20. Other Books You May Enjoy

Implementing Serializer relations

Django models have three types of relational fields – ForeignKey, ManyToManyField, and OneToOneField (all of them support reverse relationships too). So far, we have learned how to use model serializers efficiently, but let’s now explore how we can work with related fields in Serializers.

By default, when a model has any related field, ModelSerializer will link the associated field to PrimaryKeyRelatedField in the serializer definition. A DRF serializer will use PrimaryKeyRelatedField for all kinds of related field serializers, with different options passed.

Here, we will learn how to create related field serializers:

  • For ForeignKey, the DRF model serializer assigns PrimaryKeyRelatedField to the serializer
  • For OneToOneField, the DRF model serializer assigns PrimaryKeyRelatedField to the serializer with an additional UniqueValidator attached
  • For ManyToManyField, the DRF model serializer assigns PrimaryKeyRelatedField...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime