No video

A Quick Intro to Model Formsets in Django

  Рет қаралды 38,664

Pretty Printed

Pretty Printed

Күн бұрын

Пікірлер: 105
@prettyprinted
@prettyprinted 4 жыл бұрын
Join my free course on the basics of using the database in Django: prettyprinted.com/djangodata
@mikkeljrgensen3850
@mikkeljrgensen3850 5 жыл бұрын
Such wonderful tutorials you make. Precise, no fumbling about and super well presented. You're the best, Anthony!
@prettyprinted
@prettyprinted 5 жыл бұрын
Thanks!
@mikkeljrgensen3850
@mikkeljrgensen3850 5 жыл бұрын
@@prettyprinted No sweat! While I have you here: Might I inquire as to how you got to where you're at? I'm guessing formal education..?
@prettyprinted
@prettyprinted 5 жыл бұрын
@@mikkeljrgensen3850 I have very little formal education on my own. I most stuff on my own and from working as a programmer.
@narendrasudrik7763
@narendrasudrik7763 5 ай бұрын
Excellent! precise and very useful. Thanks very much.
@user-cp9lo9zv7b
@user-cp9lo9zv7b 7 ай бұрын
Hi Anthony, You are a great teacher. I like the easy informal tone. A wish for me would be formset combined with Select2 dropdown fields. I have a hard time getting this to work. Thanks in advance!
@benjaminelemi3424
@benjaminelemi3424 Жыл бұрын
Thank you very much. Can you do a video of how to use modelformset to handle an update of records where some fields will be read-only. Thank you.
@ericharper5002
@ericharper5002 3 жыл бұрын
Thank you for the clear tutorial. Really helped me with my Django project.
@DincerHoca
@DincerHoca 4 жыл бұрын
This is a very nice introduction to model formsets and it would be great if you make more videos on it.
@CR4WLFC
@CR4WLFC 5 жыл бұрын
using formset and dynamic js fields.
@h3ckphy246
@h3ckphy246 2 жыл бұрын
Best video explanation
@MagnusAnand
@MagnusAnand 3 жыл бұрын
thanks for the explanation
@mrmuranga
@mrmuranga 4 жыл бұрын
clean and thorough as always...I always learn something new from your videos...please do something on developing for rest framework (drf)upto hosting incorporating both normal Django and DRF .....
@prettyprinted
@prettyprinted 4 жыл бұрын
I'll see what I can do. Thanks for watching!
@gregtuve1109
@gregtuve1109 5 жыл бұрын
It would be pretty nifty if you A) Covered how to pass database error messages back to the user B) Covered how to use the DOM to store the rows locally until it was time to submit an entire batch (to minimize round trips), C) told malik why people need multiple copies of the same form, since he didn't get it the first time around, D) covered the redirect pattern that prevents people from submitting the set of new form values twice after refreshing the page or hitting the back button, E) Covered how to override common methods like form.save or the way it the form responds to enter. Personally I want my form to shift from field to field every time someone enters a space, and simply go to the next row of values down when the user hits enter. Then there's F) How to add keyboard shortcuts so that a specific key combination "presses" a specific button. Also, I agreed with David: Cover the differences between the three types of factory.
@prettyprinted
@prettyprinted 5 жыл бұрын
Thanks for all the ideas! I'll see what I can do.
@Skaxarrat
@Skaxarrat 5 жыл бұрын
A good video would be differences between 'modelform_factory', 'modelformset_factory' and 'inlineformset_factory'. On a theoric and practical level
@prettyprinted
@prettyprinted 5 жыл бұрын
I like that idea! Thanks.
@jonathanwarner2420
@jonathanwarner2420 5 жыл бұрын
@@prettyprinted David's suggestion is great!. Maybe you can build up on the django documentation concerning modelform_factory', 'modelformset_factory' and 'inlineformset_factory'. So you don't have to explain everything explicitly and the student will be able to read up things, he doesn't understand. Source code (perhaps on github) would be great, too!
@marvin-kevinjuan2129
@marvin-kevinjuan2129 5 жыл бұрын
@@prettyprinted That would be really awesome, if you'd create such a tutorial.
@prettyprinted
@prettyprinted 5 жыл бұрын
@@jonathanwarner2420 Thanks for the idea!
@mikkeljrgensen3850
@mikkeljrgensen3850 5 жыл бұрын
This. So much this! I'll throw in my firstborn (provided I ever have one of those).
@saliksheraz6236
@saliksheraz6236 4 жыл бұрын
Very good and helpful video brother, really helpful
@ambig1
@ambig1 5 жыл бұрын
something like add a + or - symbol next to each entry and upon pressing it i can add or delete items. use case -1 a user wants to add multiple phone numbers and a description. phonenumber1 home - phonenumber2 mobile - phonenumber3 office - phonenumber4 mobile2 +
@nero71845
@nero71845 4 жыл бұрын
thank u sir very helpful
@spm06
@spm06 2 ай бұрын
Nice Explanation Sir, i have some doubts, i want form multiple times while clicking add more button, not to specify extra field
@ultimatefifamobileshow
@ultimatefifamobileshow 4 жыл бұрын
thanks for putting up these series, i am trying to create a page where a user can create a question and give its options set and on the page he should be able to add more questions dynamically and for each question form he can add as many options as he wants and finally submit the full page Data as json , how do it do it, i wouldn’t want to get the entire code but a little help with the things that are required like formset ,ajax calls and etc
@pmale90
@pmale90 5 жыл бұрын
Nice video. My request for the next video: Use django forms to select object(Example objects(3), Example objects(2)......... ) and then show his data ( from displayed video, that would be 'Name' and 'Location' values ) in web browser.
@prettyprinted
@prettyprinted 5 жыл бұрын
So like a dropdown that contains all the objects in a certain model. Once I submit the form, I would see all the data associated with that object?
@pmale90
@pmale90 5 жыл бұрын
Yes, something like that. Why am I asking this? I have objects lat = 50 & lon = 19, lat = 50 & lon19.1(~6000 combinations). When I open one of these objects, I see the information about that point (in which country it is located, at what height it is). How to use forms(or some other way), specify a specific object lat&lon and display the data of a point in the web browser. Thanks for your reply
@prettyprinted
@prettyprinted 5 жыл бұрын
@@pmale90 Oh I see. Try using the __str__ method in your model and see if that helps.
@esportsnexus
@esportsnexus 5 жыл бұрын
Make a video on setting up logging(probably the best way in production) with Django Thanks!
@prettyprinted
@prettyprinted 5 жыл бұрын
Good idea. Thanks.
@SuperDashdash
@SuperDashdash 5 жыл бұрын
Example on a page contains a questionnaire with more than one form with a condition that each form accepts multiple tabulated multi-fields with more than one row.
@prettyprinted
@prettyprinted 5 жыл бұрын
I'll see what I can do. Thanks for the idea.
@vangasurya8896
@vangasurya8896 4 жыл бұрын
can you make a video about formsetfactories usage.how to use formset factories and how to make multiple rows for a form with no repeattitions of table headings
@nomoredrama2992
@nomoredrama2992 5 жыл бұрын
Thaks, it was helpful, and I wish you could make a video on chained /dependent dropdown list in django form
@prettyprinted
@prettyprinted 5 жыл бұрын
Thanks for watching. I'll put dependent drop downs on my list and see what I can do.
@amiaynarayan619
@amiaynarayan619 3 жыл бұрын
You are the reason, i have been able to get this far in django and flask. Could you tell me how to use this in CreateView and with single form, update multiple Models(Example, Example1, Example2, where these are related tables(Example2 has Example and Example1 as foreign keys).
@user-qn6pq1dk5h
@user-qn6pq1dk5h Жыл бұрын
Thank you
@godspower_eze
@godspower_eze 4 жыл бұрын
Please could you make a video on how to user modelforms inside of inlineformset factory and how to display errors while using them
@MrKronos999
@MrKronos999 3 жыл бұрын
For a modelformset_factory, with a parent and child table , form.save(commit=False) gives an instance of the parent model. How do I loop through the instances of child model that is about to be saved?
@georgesmith3022
@georgesmith3022 4 жыл бұрын
I think the purpose of formsets is to use them in one to many model relationships and not on their own
@abiral_neupane4045
@abiral_neupane4045 3 жыл бұрын
how do you use prefix in modelformsets. i have multiple model formsets and the name clashes while trying to update my objects
@mikefromru2341
@mikefromru2341 5 жыл бұрын
Make a video about django-rest-framework, please.
@prettyprinted
@prettyprinted 5 жыл бұрын
I already have some. You can search my channel for them.
@richardlong2412
@richardlong2412 5 жыл бұрын
can you show how to manual print out a formset from the modelformset factory or any class based view. I would like to add in like a plus sign to add more instead of having them there by default and also a - sign to remove one you do not want. This is similar to the admin page in django. Can this be done in modelformsets.
@AzizurRehmanShaikhOracubesERP
@AzizurRehmanShaikhOracubesERP Жыл бұрын
VERY GOOD. BUT WHAT ABOUT MASTER DETAIL FORM?
@skillsagewithravi
@skillsagewithravi 4 жыл бұрын
post a example for dynamic data display forms in a single view function
@atchutram9894
@atchutram9894 3 жыл бұрын
How to make only one of the forms is required?
@fadyghalayiny1920
@fadyghalayiny1920 4 жыл бұрын
can you give me example if i want to allow current logged in user to be saved when using formsets without having the option to select user
@sidd24100
@sidd24100 4 жыл бұрын
I created 3 forms from the same model, with different fields in each form. I am not sure how to submit the forms as each form has only specific fields and all the model fields are mandatory.
@EstadoPensante
@EstadoPensante 5 жыл бұрын
THANKS BRO, THIS VIDEO WILL SAVE ME rsrsrs
@prettyprinted
@prettyprinted 5 жыл бұрын
I'm glad it helps. Thanks for watching.
@collegesuggestor6309
@collegesuggestor6309 4 жыл бұрын
i followed the same tutorial and added 'can_delete = True' in modelformset_factory parameters but its not deleting. and there is no error generating
@qureshlakdawala1069
@qureshlakdawala1069 5 жыл бұрын
hello sir plz make a video of login and logout form with the help of our own model designed or with the help of fromsets
@nabindahal2340
@nabindahal2340 3 жыл бұрын
how to store in database directly ??
@ambig1
@ambig1 5 жыл бұрын
please a do a video about how to redner a many to many model using forms. scenario : one author can have many books, a book can have many authors. model>form>view>template.
@prettyprinted
@prettyprinted 5 жыл бұрын
I'll look into and see what I can do.
@ambig1
@ambig1 5 жыл бұрын
@@prettyprinted appreciate your consideration. Just pressed the bell icon, to not miss it when you upload it.
@wispawelwis38
@wispawelwis38 2 жыл бұрын
how about multiple formsets in one view?
@medoabdin480
@medoabdin480 3 жыл бұрын
please try to explain this issue why when I use formsets to update images I used the extra argument to create just 3 image fields however I got more than one image when I update the formsets. you can create a user and create a product then updated the sub-images many times to see the image field will repeat itself and don't save just 3 images: this is an example djolx.pythonanywhere.com/details/34/
@EliasPaiFilho
@EliasPaiFilho 5 жыл бұрын
Very Good!
@prettyprinted
@prettyprinted 5 жыл бұрын
Thanks for watching.
@kamilguchowski2793
@kamilguchowski2793 4 жыл бұрын
Hey, is it possible to make it on The CreateView, UpdateView and other?
@lhotse1716
@lhotse1716 5 жыл бұрын
How would this be applied in a case where you have a modelform already defined in forms.py, like you did in the video "Creating Forms from Models [...]", and you want to turn that into a model formset? Could you just call that modelform instead of specifying (Example, fields='name', 'location')?
@prettyprinted
@prettyprinted 5 жыл бұрын
You should be able to use it along side your existing modelform. Although it would be strange to use the same model in two different ways.
@mayanktripathi4u
@mayanktripathi4u 5 жыл бұрын
Hi, I had made two models, and trying to save both using forms, but nothing happens and no error. Also tried printing the data but seems nothing is printed. Not sure where the data is disapperaing. Please help. below is the model.py class Profile(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) class FamilyMember(models.Model): profile = models.ForeignKey(Profile, on_delete = models.CASCADE) name = models.CharField(max_length=100) relationship = models.CharField(max_length=100) and the view.py as below. def profileAdd(request): ProfileFormSet = modelformset_factory(Profile, fields = ('first_name', 'last_name', ), extra = 1) FamilyFormSet = inlineformset_factory(Profile, FamilyMember, fields = ('name','relationship',), can_delete = False, extra = 1) form_profile = ProfileFormSet(queryset = Profile.objects.none()) form_family = FamilyFormSet() if request.method == 'POST': if form_profile.is_valid(): profile = form_profile.save() print (profile) if form_family.is_valid(): instances = form_family.save(commit = False) form_family.profile = profile.id # form_family.save() print(profile.id) print(instances) return redirect('profile-detail', profile_id = profile.id) return render(request, 'dynamicaddfields/profile-add.html', {'form_profile' : form_profile, 'form_family': form_family})
@isaacndutumo
@isaacndutumo 4 жыл бұрын
Am work on a project where am working with formset and your video was very helpful but how can i save several instance because when i save the form only the first record is saved. Below is the view code def add_prescription_to_patient(request,pk): patient = get_object_or_404(Patient, pk=pk) PrescriptionFormSet = modelformset_factory(Prescription, fields = ('medication','number_of_days','times_daily','total','instructions',), extra=2) if request.method == 'POST': form = PrescriptionFormSet(request.POST) instances = form.save(commit=False) for instance in instances: instance.patient = patient instance.user = request.user instance.save() return redirect('patient_prescription_detail', pk=patient.pk) else: form = PrescriptionFormSet(queryset = Prescription.objects.none()) return render(request, "product/prescription_form1.html",{"form": form})
@rayr268
@rayr268 3 жыл бұрын
Anyone know how to delete the form entry without the form failing?
@shuvayanmukherjee225
@shuvayanmukherjee225 5 жыл бұрын
Can we have such feature inside the admin page, where we can add multiple fields in the models based on the requirements?
@prettyprinted
@prettyprinted 5 жыл бұрын
You can modify the admin page, yes. I'm not sure on exactly how you want to modify it though, so I can't give you any specific advice.
@jnscollier
@jnscollier 4 жыл бұрын
How to use a formset and two models
@ermalgashimramori
@ermalgashimramori 5 жыл бұрын
Can you please make a form with different users to have different permissions accessing fields in the form. Example- I have a store with multiple locations, I want the user from his location to have access to edit his field but only to view others location field.
@prettyprinted
@prettyprinted 5 жыл бұрын
I'll take that into consideration. Thanks for the idea.
@n1ce_1k
@n1ce_1k 4 жыл бұрын
How it can be used in CreateView?
@ramvithanala7674
@ramvithanala7674 5 жыл бұрын
What is the difference between these these 3 forms could you make one video on this particular topic
@prettyprinted
@prettyprinted 5 жыл бұрын
Definitely will.
@malikrumi1206
@malikrumi1206 5 жыл бұрын
A practical, real world use case would make this sooooo much better. As it stands, why would ANYONE want extra blank copies of the forms some user has already filled in? It's pointless. Give it some thought, I am sure you can do better.
@prettyprinted
@prettyprinted 5 жыл бұрын
You're right, I can do better. I'll work on a more detailed example.
@EliasPaiFilho
@EliasPaiFilho 5 жыл бұрын
I support your project to teach us, it would be nice if the extra was created dynamically by the user at the click of a button for example. Can you do this in templates outside of admin?
@GiuseppeSerraonline
@GiuseppeSerraonline 5 жыл бұрын
can you with a formset creating a table grid form?
@prettyprinted
@prettyprinted 5 жыл бұрын
What do you mean by table grid form?
@GiuseppeSerraonline
@GiuseppeSerraonline 5 жыл бұрын
@@prettyprinted My mistake, thanks for asking
@DongsapaVn
@DongsapaVn 2 жыл бұрын
delete ??
@ayuzawamisaki239
@ayuzawamisaki239 5 жыл бұрын
Also can u tell me how to display error in form template
@prettyprinted
@prettyprinted 5 жыл бұрын
You can use .errors on the form inside of the template. Here's more info: docs.djangoproject.com/en/2.1/ref/forms/api/#django.forms.Form.errors
@ayuzawamisaki239
@ayuzawamisaki239 5 жыл бұрын
@@prettyprinted nope it won't work for django formset..
@abdillahmohamed9585
@abdillahmohamed9585 5 жыл бұрын
How to insert 2 different models in the same form in Django?
@prettyprinted
@prettyprinted 5 жыл бұрын
It would be easiest to create two form objects but have one form in your HTML. Then you can insert data into each model in your view where you handle the form data.
@abdillahmohamed9585
@abdillahmohamed9585 5 жыл бұрын
I'm new in Django, How to display the list of the current model in the same form and load the data while clicking in the submitting button and clear the form fields?
@xyzmoral262
@xyzmoral262 5 жыл бұрын
'inlineformset_factory' next to go.
@prettyprinted
@prettyprinted 5 жыл бұрын
Someone else recommended this, so I'll definitely cover this.
@EliasPaiFilho
@EliasPaiFilho 5 жыл бұрын
I support your project to teach us, it would be nice if the extra was created dynamically by the user at the click of a button for example. Can you do this in templates outside of admin?
@prettyprinted
@prettyprinted 5 жыл бұрын
@@EliasPaiFilho I'll look into that. Thanks for the idea.
@walidnewaz6475
@walidnewaz6475 4 жыл бұрын
Here is my views.py: paste.ubuntu.com/p/hgR7vXmYBp/ And here is my models.py: paste.ubuntu.com/p/ttVSzFWG24/ I am able to add single product under one "ref_no" as usual. Now i wanted to add multiple products under one "ref_no" which is in Order model. How can i do this using Django formset?
@mvaldes
@mvaldes 5 жыл бұрын
Class based views
@prettyprinted
@prettyprinted 5 жыл бұрын
I was supposed to cover those and I forgot. Thanks for the idea and for reminding me.
@mrvalvet9856
@mrvalvet9856 3 жыл бұрын
Thanks for the tutorial, but I'm still confused as to why and when you'd want to use formsets. An example from real life would have been more useful.
@nikhilbhardwaj6055
@nikhilbhardwaj6055 5 жыл бұрын
make a simple app of DjanoRestFramework how to work with them in templates
@prettyprinted
@prettyprinted 5 жыл бұрын
The two aren't necessarily connected, but if I cover frontend frameworks more in the future, then I could use DRF as the backend.
@skillsagewithravi
@skillsagewithravi 4 жыл бұрын
thank you
How to Use the ifchanged Template Tag in Django
9:58
Pretty Printed
Рет қаралды 4,1 М.
Using the Inline Form Set Factory in Django (Part 1 of 2)
19:31
Pretty Printed
Рет қаралды 58 М.
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 98 МЛН
SPONGEBOB POWER-UPS IN BRAWL STARS!!!
08:35
Brawl Stars
Рет қаралды 24 МЛН
Extend Your Django User Framework With a One To One Field
11:39
Pretty Printed
Рет қаралды 42 М.
A Quick Intro to Translation in Django (Internationalization)
11:09
Pretty Printed
Рет қаралды 47 М.
Django & HTMX - Dynamic Form Creation and Submission
24:36
BugBytes
Рет қаралды 28 М.
Style Django Forms With Bootstrap - Django Blog #5
15:46
Codemy.com
Рет қаралды 126 М.
Django Forms Tutorial For Beginners - Get Started Fast! (2018)
29:36
The Dumbfounds
Рет қаралды 165 М.
Django Dynamic Forms Tutorial with Htmx
48:27
Matt Freire
Рет қаралды 67 М.