Django FormWizard prefill on edit - django

I'm using a FormWizard to edit objects and I want to be able to prefill the fields from database when the edit page is loaded.
For example if my URL is 'category_edit_wizard/5', the field 'title' should have the value of the category with the ID 5 when the page is loaded.
Any way to do that?
Thank you

If you're using django-formwizard or the new formwizard implementation introduced in Django 1.4 you can use ModelForm's as a step form and pass an instance_dict when creating the WizardView instance.
instance_dict works the same way initial_dict works - see
https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.initial_dict
If you're using the old formwizard implementation from Django 1.3 and lower, you can pass initial as described here: https://django-formtools.readthedocs.io/en/latest/wizard.html#providing-initial-data-for-the-forms

Related

mezzanine cms: can the values of meta fields in the form page be saved in database?

I am new to mezzanine cms. I have some questions about the form page.
In the admin interface, I added a form page. On the bottom of the form page, there is a "meta" section which I can add some fields to the form page I created. My questions are:
1) for the meta fields I added, can I save the values of the fields
in the database?
2) can the meta fields be from a database table fields? For example,
I have a user profile model, can I use the fields in the profile
model as meta fields in the form page? and how?
3) what are the purposes of the form page in mezzanine cms?
Thank you!
Mezzanine's Form page is for when you don't want to define your own model. It dynamically constructs a model to save entered data and potentially email it someplace. This is appropriate if the form is defined by a non-programmer admin or if the only purpose of the form is to collect data and send it somewhere.
However, this is probably not a good choice if the purpose is to use the data in your application. For that, it is better to define your own model and use django's ModelForm.

Can anyone please explain me the what are Django modelform_factory and modelformset_factory?

Kindly explain me the what are Django modelform_factory and modelformset_factory, and how do they correlate to the Django models, forms and modelforms?
I'm a beginner to Django and came across these terms. Looked up on the internet but wasn't able to find any good source of information on these.
Thank you.
modelform_factory is a method to create forms in views , without defining form in forms.py file.
There are multiple places, where you have automatically generated forms or formsets, the most visible is admin and Generic Class Views.
Every time you are working with HTML forms do add or modify data - you should use forms.Form. If you are working with the model - there is forms.ModelForm which is build on top of the Form - handling automatically declaration of fields, some validations and instance save. Then on top of this you have modelform_factory - which is generating on-demand ModelForm - so it is kind of shortcut to define default ModelForm for your model.
Similar, modelformset_factory is generating ModelFormSet to be used with one-to-many relations.

Create multiple objects in django admin at once

For example, I have a Post model:
Class Post(models.Model):
title = models.Charfield(max_length=200)
# other fields
I wonder is there a way to create multiple posts at once in admin. In other words, I need a formset instead of single form on post creation page.
I've heard recently about a django app that exactly does this job. It's called django-bulk-admin and enables bulk add/update in the admin.
Possibly, the best way to do exactly what you want is extend the ModelAdmin class, because it has no formsets on it, except for those used on InlineFormsets.
After that you could customize the admin change_form template, to include your formsets
The quick-and-dirty way to do it using admin is wrap your Post model as an inline formset of another modeladmin and add the extra option to it.

how to remove data that already in use in onetoonefield django admin form

in onetoonefield django admin form displays all existing data. How to display only the data that has not been in use?
or how to remove data that already in used?
sorry, my english is bad ..

How do you use django forms to save to more than one model?

Say I have a single form that has a field type and depending on what type the user inputs, the data is placed into a model/table. How do you do this with django forms?
Thanks!
In Django, a form for more than one model is called a FormSet.