title
Using the Inline Form Set Factory in Django (Part 1 of 2)

description
In this video I compare using the regular model form set factory with the inline form set factory when it comes to models with relationships. Need one-on-one help with your project? I can help through my coaching program. Learn more here: https://prettyprinted.com/coaching Join my free course on working with the database and models in Django: https://prettyprinted.com/djangodatabase Get the code here: http://prettyprinted.com/l/kGg Twitter: https://twitter.com/pretty_printed Github: https://github.com/prettyprinted

detail
{'title': 'Using the Inline Form Set Factory in Django (Part 1 of 2)', 'heatmap': [{'end': 515.398, 'start': 491.764, 'weight': 0.704}, {'end': 539.294, 'start': 527.97, 'weight': 1}, {'end': 1009.674, 'start': 992.965, 'weight': 0.846}], 'summary': "Tutorial series titled 'using the inline form set factory in django (part 1 of 2)' demonstrates the advantages of using the inline form set factory in django over the model form set factory, covers creating models and using the inline form set factory to associate languages with programmers, and discusses efficient formset creation and streamlined form handling in django.", 'chapters': [{'end': 38.321, 'segs': [{'end': 38.321, 'src': 'embed', 'start': 1.223, 'weight': 0, 'content': [{'end': 2.864, 'text': "Hey everyone, it's Anthony from PrettyPrinted here.", 'start': 1.223, 'duration': 1.641}, {'end': 8.246, 'text': "In today's video, I want to show you how to use the inline form set factory in Django.", 'start': 3.224, 'duration': 5.022}, {'end': 19.51, 'text': "So this is very closely related to the model form set factory and I'll show you how to use both to accomplish the same thing and why using the inline form set factory is a little bit better to accomplish what you want to do.", 'start': 8.546, 'duration': 10.964}, {'end': 24.593, 'text': 'but before i get into that, i just want to remind you that i do have my website, prettyprinted.com.', 'start': 19.97, 'duration': 4.623}, {'end': 29.556, 'text': 'i have more structured courses on there that cover various topics.', 'start': 24.593, 'duration': 4.963}, {'end': 34.759, 'text': 'so if you want to take a course where you can watch multiple videos on the same topic, just go to my website.', 'start': 29.556, 'duration': 5.203}, {'end': 38.321, 'text': 'i have both free courses and premium courses.', 'start': 34.759, 'duration': 3.562}], 'summary': 'Anthony explains using inline form set factory in django and promotes his website with structured courses.', 'duration': 37.098, 'max_score': 1.223, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP41223.jpg'}], 'start': 1.223, 'title': 'Using django inline form set factory', 'summary': 'Demonstrates the advantages of using the inline form set factory in django over the model form set factory and promotes prettyprinted.com, offering structured courses on various topics including free and premium options.', 'chapters': [{'end': 38.321, 'start': 1.223, 'title': 'Django inline form set factory', 'summary': "Demonstrates how to use the inline form set factory in django, emphasizing its advantages over the model form set factory and promoting the instructor's website, prettyprinted.com, which offers structured courses on various topics, including both free and premium options.", 'duration': 37.098, 'highlights': ['The chapter focuses on demonstrating the usage of the inline form set factory in Django, highlighting its advantages over the model form set factory for achieving the same goal.', 'The instructor promotes prettyprinted.com, which offers structured courses covering various topics, including free and premium options.']}], 'duration': 37.098, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP41223.jpg', 'highlights': ['The chapter focuses on demonstrating the usage of the inline form set factory in Django, highlighting its advantages over the model form set factory for achieving the same goal.', 'The instructor promotes prettyprinted.com, which offers structured courses covering various topics, including free and premium options.']}, {'end': 654.04, 'segs': [{'end': 192.567, 'src': 'embed', 'start': 157.052, 'weight': 4, 'content': [{'end': 158.214, 'text': 'Okay, so I have the two models.', 'start': 157.052, 'duration': 1.162}, {'end': 162.097, 'text': 'I have the programmer model and I have the language model.', 'start': 158.274, 'duration': 3.823}, {'end': 165.26, 'text': "So I'll go ahead and make the migrations for that.", 'start': 162.497, 'duration': 2.763}, {'end': 170.405, 'text': "And then I'll actually migrate.", 'start': 168.583, 'duration': 1.822}, {'end': 181.582, 'text': "And then I'll add it to my admin so I can quickly add in some records just to have some data in there to begin with.", 'start': 174.218, 'duration': 7.364}, {'end': 182.922, 'text': "So let's see.", 'start': 182.142, 'duration': 0.78}, {'end': 184.843, 'text': 'Run server.', 'start': 184.183, 'duration': 0.66}, {'end': 192.567, 'text': 'And then, oh, need to add it to admin.', 'start': 189.525, 'duration': 3.042}], 'summary': 'Creating programmer and language models, making migrations, and adding to admin for data entry.', 'duration': 35.515, 'max_score': 157.052, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4157052.jpg'}, {'end': 340.562, 'src': 'embed', 'start': 307.539, 'weight': 0, 'content': [{'end': 308.46, 'text': 'I have the model set up.', 'start': 307.539, 'duration': 0.921}, {'end': 321.511, 'text': "And now what I'll do is I'll go to my views and I'll import those two models because I'll be using them from models import programmer and language.", 'start': 309.884, 'duration': 11.627}, {'end': 331.176, 'text': 'All right, so what I wanna do is I want to create a form that allows me to edit all of the languages associated with a particular programmer.', 'start': 322.191, 'duration': 8.985}, {'end': 340.562, 'text': "So what I'll do is in my index, I'm gonna take an author ID or let's say a programmer ID Programmers can be authors.", 'start': 331.656, 'duration': 8.906}], 'summary': 'Setting up model, importing models, and creating a form to edit languages for a programmer.', 'duration': 33.023, 'max_score': 307.539, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4307539.jpg'}, {'end': 465.511, 'src': 'embed', 'start': 435.363, 'weight': 1, 'content': [{'end': 442.247, 'text': "So the reason why I'm doing this is because eventually I have to associate the programmer that's passed in with this language.", 'start': 435.363, 'duration': 6.884}, {'end': 444.729, 'text': "But for now, I'm just creating the FormSet.", 'start': 442.787, 'duration': 1.942}, {'end': 451.757, 'text': 'Now what I want to do is just the basics of actually displaying the FormSet.', 'start': 446.19, 'duration': 5.567}, {'end': 465.511, 'text': "I'll say FormSet equals LanguageFormSet, and I'm going to use a query set for this one because I want to limit it by the programmer.", 'start': 451.837, 'duration': 13.674}], 'summary': 'Creating a formset to associate programmer with language', 'duration': 30.148, 'max_score': 435.363, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4435363.jpg'}, {'end': 516.977, 'src': 'heatmap', 'start': 491.764, 'weight': 0.704, 'content': [{'end': 496.968, 'text': 'So I have that and then return render requests.', 'start': 491.764, 'duration': 5.204}, {'end': 504.773, 'text': "I'll create a template called index really quick and I'll pass the form sets to that template.", 'start': 497.888, 'duration': 6.885}, {'end': 507.855, 'text': "So I'll create a new file.", 'start': 506.474, 'duration': 1.381}, {'end': 515.398, 'text': 'So I need a directory templates and then index.', 'start': 509.696, 'duration': 5.702}, {'end': 516.977, 'text': "I'll keep this really simple.", 'start': 515.938, 'duration': 1.039}], 'summary': 'Creating a new template called index and passing form sets to it.', 'duration': 25.213, 'max_score': 491.764, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4491764.jpg'}, {'end': 559.86, 'src': 'heatmap', 'start': 527.97, 'weight': 1, 'content': [{'end': 529.871, 'text': 'Alright, so that should be enough to see.', 'start': 527.97, 'duration': 1.901}, {'end': 532.352, 'text': "So let's see if we can take a look.", 'start': 530.191, 'duration': 2.161}, {'end': 539.294, 'text': "So I'll pass in one as the programmer ID and we see C++, Python, and then blank, which is exactly what I want.", 'start': 532.532, 'duration': 6.762}, {'end': 542.896, 'text': 'So I need to surround this by form tags.', 'start': 540.055, 'duration': 2.841}, {'end': 559.86, 'text': "And then method is going to be posts and I'll be posting to the same endpoint so it doesn't really make a difference if I put in the action.", 'start': 546.437, 'duration': 13.423}], 'summary': 'Programmer id 1 displays c++ and python; need to add form tags and use posts method for endpoint.', 'duration': 31.89, 'max_score': 527.97, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4527970.jpg'}, {'end': 654.04, 'src': 'embed', 'start': 617.395, 'weight': 3, 'content': [{'end': 622.199, 'text': 'The only difference is I can pass in request.post.', 'start': 617.395, 'duration': 4.804}, {'end': 627.483, 'text': 'So this is just like a normal model form set.', 'start': 622.499, 'duration': 4.984}, {'end': 630.845, 'text': "I'm passing in the request data.", 'start': 628.684, 'duration': 2.161}, {'end': 641.832, 'text': 'That way, I can associate the data that I filled in the form with the actual data in the model, which is the whole point of the form sets.', 'start': 631.066, 'duration': 10.766}, {'end': 654.04, 'text': "If I say, if form set is valid, I'm going to save that form set, but I don't want to commit.", 'start': 641.892, 'duration': 12.148}], 'summary': 'Using request.post to pass data into a model form set, preserving form data and not committing the form set if valid.', 'duration': 36.645, 'max_score': 617.395, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4617395.jpg'}], 'start': 38.321, 'title': 'Django form set factories and models', 'summary': "Covers creating models and using inline form set factory to associate languages with programmers, allowing for editing, adding, and deleting records. it also demonstrates using django's model form set factory to create and display a form set with a query set limited by a programmer id, emphasizing the creation and handling of form sets and their association with model data.", 'chapters': [{'end': 364.697, 'start': 38.321, 'title': 'Creating models and using inline form set factory', 'summary': 'Explains how to create a programmer and language model, set up a relationship between them, and use the inline form set factory to associate languages with programmers, allowing for editing, adding, and deleting records. it also demonstrates adding records through the admin interface and importing models into views for creating a form to edit associated languages with a specific programmer.', 'duration': 326.376, 'highlights': ['The chapter demonstrates creating a programmer and language model, establishing a relationship between them, and using the inline form set factory to enable editing, adding, and deleting records for associated languages with programmers. It also showcases the addition of records through the admin interface, including adding programmers and languages.', 'The demonstration includes the process of importing models into views for creating a form that allows editing of languages associated with a specific programmer by taking in the programmer ID and retrieving the associated programmer object for further modification.']}, {'end': 654.04, 'start': 369.835, 'title': 'Using django model form set factory', 'summary': "Demonstrates the use of django's model form set factory to create and display a form set with a query set limited by a programmer id, emphasizing the creation and handling of form sets and their association with model data.", 'duration': 284.205, 'highlights': ["The chapter explains the process of creating a form set using Django's model form set factory, specifically for associating a programmer with a language model, and displays the form set with a query set limited by the programmer's ID.", 'The chapter demonstrates the handling of post requests by creating a form set based on the post data and using the same query set, emphasizing the association of form data with the model and the importance of form set validity for data saving.']}], 'duration': 615.719, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP438321.jpg', 'highlights': ['The chapter demonstrates creating a programmer and language model, establishing a relationship between them, and using the inline form set factory to enable editing, adding, and deleting records for associated languages with programmers.', "The chapter explains the process of creating a form set using Django's model form set factory, specifically for associating a programmer with a language model, and displays the form set with a query set limited by the programmer's ID.", 'The demonstration includes the process of importing models into views for creating a form that allows editing of languages associated with a specific programmer by taking in the programmer ID and retrieving the associated programmer object for further modification.', 'The chapter demonstrates the handling of post requests by creating a form set based on the post data and using the same query set, emphasizing the association of form data with the model and the importance of form set validity for data saving.', 'It also showcases the addition of records through the admin interface, including adding programmers and languages.']}, {'end': 1170.196, 'segs': [{'end': 686.165, 'src': 'embed', 'start': 658.553, 'weight': 5, 'content': [{'end': 664.535, 'text': "So the reason why I'm not committing here is because if I try to commit here, it's going to fail,", 'start': 658.553, 'duration': 5.982}, {'end': 668.876, 'text': 'because the language is supposed to have a programmer from the model.', 'start': 664.535, 'duration': 4.341}, {'end': 674.578, 'text': "So right here, when I'm filling out this form, none of these languages have an associated programmer.", 'start': 669.356, 'duration': 5.222}, {'end': 686.165, 'text': "I did use a query to get all of those here using programmer ID, but once the query is done there's no connection between, uh,", 'start': 674.998, 'duration': 11.167}], 'summary': 'Unable to commit due to lack of associated programmers for languages.', 'duration': 27.612, 'max_score': 658.553, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4658553.jpg'}, {'end': 723.398, 'src': 'embed', 'start': 701.516, 'weight': 4, 'content': [{'end': 710.583, 'text': "And it's going to return all of the instances of the things that I just created in the form like the old ones and any new ones that I choose to create.", 'start': 701.516, 'duration': 9.067}, {'end': 714.185, 'text': 'Then what I have to do is I have to loop over those.', 'start': 712.315, 'duration': 1.87}, {'end': 723.398, 'text': "So for instance in instances, What I'm going to do is for each instance, I'm going to associate the programmer ID with that instance.", 'start': 714.406, 'duration': 8.992}], 'summary': 'Returning instances of things, associating programmer id with each instance.', 'duration': 21.882, 'max_score': 701.516, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4701516.jpg'}, {'end': 844.458, 'src': 'embed', 'start': 816.423, 'weight': 6, 'content': [{'end': 820.046, 'text': 'So if I go to number two, I see Java and Ruby.', 'start': 816.423, 'duration': 3.623}, {'end': 822.407, 'text': 'Those are the two languages associated with David.', 'start': 820.086, 'duration': 2.321}, {'end': 829.733, 'text': "So I'll add a third one, C, and we should have another language associated for David.", 'start': 823.148, 'duration': 6.585}, {'end': 834.295, 'text': 'So if I refresh this, C appears, and David is the programmer.', 'start': 829.793, 'duration': 4.502}, {'end': 838.276, 'text': 'And the reason why this is happening is because the ID that I have here in the URL.', 'start': 834.655, 'duration': 3.621}, {'end': 844.458, 'text': 'So one is Anthony, I created Anthony first, and two is David, I created David second.', 'start': 838.356, 'duration': 6.102}], 'summary': 'David is associated with java, ruby, and c. anthony was created first, and david was created second.', 'duration': 28.035, 'max_score': 816.423, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4816423.jpg'}, {'end': 1015.031, 'src': 'heatmap', 'start': 992.965, 'weight': 0.846, 'content': [{'end': 1001.429, 'text': "I'll just copy this and I'll put this below and take out the posts since this is the Git case.", 'start': 992.965, 'duration': 8.464}, {'end': 1005.171, 'text': "Then let's take a look at what happens.", 'start': 1003.571, 'duration': 1.6}, {'end': 1006.352, 'text': "I'm looking at David's now.", 'start': 1005.211, 'duration': 1.141}, {'end': 1009.674, 'text': 'I refresh and we see things look a little bit differently.', 'start': 1006.792, 'duration': 2.882}, {'end': 1015.031, 'text': 'So I still see the same names, Java, Ruby, C, but I see some extra things.', 'start': 1010.908, 'duration': 4.123}], 'summary': 'Analyzing changes in git case, noticing additional items alongside existing names.', 'duration': 22.066, 'max_score': 992.965, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4992965.jpg'}, {'end': 1050.514, 'src': 'embed', 'start': 1018.694, 'weight': 1, 'content': [{'end': 1022.077, 'text': "So the three extra fields, that's not really that big of a deal.", 'start': 1018.694, 'duration': 3.383}, {'end': 1025.599, 'text': "That's just a parameter when you want to create the form set.", 'start': 1022.097, 'duration': 3.502}, {'end': 1028.321, 'text': 'So if you want to have three extra fields, you can have three extra fields.', 'start': 1025.76, 'duration': 2.561}, {'end': 1031.724, 'text': 'If you want to have five, you can, but by default is three.', 'start': 1028.362, 'duration': 3.362}, {'end': 1033.686, 'text': 'But the cool thing is you have this delete.', 'start': 1032.025, 'duration': 1.661}, {'end': 1037.79, 'text': 'So if I check delete for Ruby and hit save, Ruby is gone.', 'start': 1033.727, 'duration': 4.063}, {'end': 1042.627, 'text': "And then if I refresh here, we see there's no more Ruby.", 'start': 1039.645, 'duration': 2.982}, {'end': 1050.514, 'text': "If I add in a few languages, let's say small talk, um, Scala and closure.", 'start': 1043.048, 'duration': 7.466}], 'summary': 'The form set allows for up to three extra fields by default, with the option to add or delete languages.', 'duration': 31.82, 'max_score': 1018.694, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP41018694.jpg'}, {'end': 1146.71, 'src': 'embed', 'start': 1119.946, 'weight': 0, 'content': [{'end': 1124.51, 'text': 'then an inline form set factory is something that you can use in your project.', 'start': 1119.946, 'duration': 4.564}, {'end': 1126.332, 'text': 'So I hope all that helped.', 'start': 1124.93, 'duration': 1.402}, {'end': 1129.214, 'text': "I know there's a lot of setup in the video,", 'start': 1127.673, 'duration': 1.541}, {'end': 1137.28, 'text': 'but once we got into it things went pretty quickly and we can see the differences between a plain model form set factory and inline form set factory.', 'start': 1129.214, 'duration': 8.066}, {'end': 1142.908, 'text': 'So just a reminder if you want to go to my website, I do have courses on Django.', 'start': 1138.106, 'duration': 4.802}, {'end': 1146.71, 'text': 'so if you want to follow that in a structured way, just check out my website.', 'start': 1142.908, 'duration': 3.802}], 'summary': 'Inline form set factory in django can be used in projects for quick setup and differentiation from plain model form set factory. check out courses on django at the website.', 'duration': 26.764, 'max_score': 1119.946, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP41119946.jpg'}], 'start': 658.553, 'title': 'Database entry and formset factory', 'summary': 'Discusses associating programming languages with programmers using ids, resolving errors, implementing inline form set factory, and using inline formset factory in django, resulting in efficient formsets creation and streamlined form handling.', 'chapters': [{'end': 967.695, 'start': 658.553, 'title': 'Database entry with programmer id', 'summary': 'Describes the process of associating programming languages with specific programmers using programmer ids, querying, and form sets, with a focus on resolving errors and implementing inline form set factory, ultimately facilitating seamless database entry and association.', 'duration': 309.142, 'highlights': ['The process of associating programming languages with specific programmers using programmer IDs The speaker discusses the process of associating programming languages with specific programmers by using programmer IDs to establish a connection between the languages and the programmers.', 'Implementing inline form set factory to facilitate seamless database entry and association The speaker demonstrates the implementation of the inline form set factory to optimize the process of database entry and association, simplifying the code and improving efficiency.', 'Resolving errors and issues related to missing programmer IDs and incorrect model form sets The speaker addresses errors related to missing programmer IDs and incorrect model form sets, emphasizing the importance of accurately filling in the programmer ID and correcting any typographical mistakes in the code.', 'Querying and looping over instances to associate programmer IDs with the created form entries The speaker explains the use of queries and looping over instances to associate programmer IDs with the created form entries, ensuring accurate database entry and association.']}, {'end': 1170.196, 'start': 967.795, 'title': 'Using inline formset factory in django', 'summary': 'Demonstrates the usage of inline formset factory in django, allowing for efficient creation and manipulation of formsets with associated parent instances, resulting in simplified code and streamlined form handling.', 'duration': 202.401, 'highlights': ['Using inline formset factory simplifies code and form handling The usage of inline formset factory in Django allows for accomplishing the exact same functionality with less code, removing unnecessary code and extra setup, resulting in streamlined form handling and efficient manipulation of formsets with associated parent instances.', 'Ability to add and delete instances from formsets The inline formset factory provides the functionality to add and delete instances from formsets, enabling the dynamic addition and removal of associated parent instances, as demonstrated by the ability to add new languages and delete existing ones with a simple form submission.', 'Flexibility in defining extra fields for formsets The inline formset factory offers flexibility in defining extra fields for formsets, allowing for the customization of the number of extra fields to be included, with the default being three, showcasing the adaptability and configurability of the formset creation process.']}], 'duration': 511.643, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JIvJL1HizP4/pics/JIvJL1HizP4658553.jpg', 'highlights': ['Using inline formset factory simplifies code and form handling', 'Ability to add and delete instances from formsets', 'Implementing inline form set factory to facilitate seamless database entry and association', 'Flexibility in defining extra fields for formsets', 'Querying and looping over instances to associate programmer IDs with the created form entries', 'Resolving errors and issues related to missing programmer IDs and incorrect model form sets', 'The process of associating programming languages with specific programmers using programmer IDs']}], 'highlights': ['The chapter demonstrates creating a programmer and language model, establishing a relationship between them, and using the inline form set factory to enable editing, adding, and deleting records for associated languages with programmers.', 'The chapter focuses on demonstrating the usage of the inline form set factory in Django, highlighting its advantages over the model form set factory for achieving the same goal.', 'Using inline formset factory simplifies code and form handling', 'Ability to add and delete instances from formsets', 'Implementing inline form set factory to facilitate seamless database entry and association', 'Flexibility in defining extra fields for formsets', 'Querying and looping over instances to associate programmer IDs with the created form entries', 'Resolving errors and issues related to missing programmer IDs and incorrect model form sets', 'The process of associating programming languages with specific programmers using programmer IDs', 'The instructor promotes prettyprinted.com, which offers structured courses covering various topics, including free and premium options.']}