Right way to make embedded forms - django

What is the right way to make embedded form with manyToMany, oneToMany, etc? I would like to build form rendering like django auto-generated admin (ref).

See: https://docs.djangoproject.com/en/1.5/topics/forms/formsets/ for examples of how to render one or more forms for models that are associated to other models.

Related

Do I need to create forms.py for my forms in Django?

I'm about to create a form in my website made in Django with elements that have complex input types from different plugins (like calendar plugins). Also, I'll be using a Validator plugin which validates the input before submission.
My question is do I need to create forms.py and like model the form or can I just create the form manually? The former seems like a very hassle process. Which one is more efficient and recommended?
As #dmitryro said you can create your forms manually in the templates and then getting in the request. It's recommended to use the forms api provided by Django since it allows you to reuse, validate, and customize your forms.
As to whether or not it is a good practice that depends completely on you but if you are trying to scale an application I would recommend use the forms.
It is good to use Django's built in form.
If we use django's form then we only have to write python code and django will create corresponding html for it. And our code will be short and clean.

Django: Best way to handle multiselect US state selection

What is the best way to include in a model to save multi-select US states? I need a user to select several states and save this data in a model (via form OR modelform ).
I tried LocalFlavor USStateField model it doesn't seem to work for me since I can't call it like a regular model.
This django app i've written may help you.

Django Admin like Inlines in my ModelForm

I'm trying to replicate the inlines in the Django admin for adding related models on a FKd model on my own non admin ModelForm. In particular, when you use a StackeAdminInline and you get the "+ Add another XXX" bit of Javascript to add more of the related model.
It must be possible if the admin can do it, but I can't find a project with an example of how to do this. Can anyone point me at something? Am using Crispy Forms, although happy not to if need be. I did see https://github.com/runekaagaard/django-crispy-forms-fancy-formsets but seems as though this wasn't preferred by the Crispy maintainers, and was thinking there must be some more Djangoic way of doing this if the admin can do it already.
Thanks!
The JS used by the admin is based on this jQuery plugin http://code.google.com/p/django-dynamic-formset/ which is still reasonably maintained.

use of built in forms and views like PasswordChangeForm in django1.3

I am new to django,In django1.3 how can I use the Built-in forms like PasswordChangeForm ,PasswordResetForm etc and the same using built-in views.Can any one share some liks or codes ,ideas,am absolutely .new to Django,Thanks in advance
Django by default has all these forms built in views. For all those features, all you need to do is to, point them at relevant URL positions, that map to the specific views.
This question has already been answered:
Adding forgot-password feature to Django admin site

Reusing Admin forms for user views in django?

Django is making very nice forms after creating a models.py and an admin.py.
How can I reuse these forms (with the extra nice handling of foreign keys and many-to-many fields) in my own views?
ModelForm does only generate "simple" forms. Where do I get the extra batteries?
I was actually able to replicate those green buttons in my forms by following the instructions on this page: http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/
A stock ModelForm will do almost all of what the admin does (ForeignKeys will turn into a dropdown select, ManyToManyFields will turn into a multiple-select).
The main exception would be the little green plus buttons for adding a new entry. It would be pretty hard to make those generic, as they depend on a number of admin-specific things: knowing where to find an add page for the linked model; JS to popup a window, close it on submit, and update the parent page; etc. You can dig into the admin and figure out how it implements those extra niceties, but there is not going to be a simple way to drop them into your code.
The other nicety you might be wanting is the filter_horizontal or filter_vertical alternative UIs for a ManyToManyField. Those are implemented as ordinary form widgets, so the potential is there for reusing them in your own code, but I'm guessing it'll take some experimentation and customization to make it work properly.