Django formset_factory vs modelformset_factory vs inlineformset_factory

The difference between the 3 formset factories is basically: formset_factory lets you render a bunch of forms together, but these forms are NOT necessarily related to a particular database models (this is not what you need, since you have models for everything) modelformset_factory lets you create/edit a bunch of Django model objects together, for example, … Read more

Django. TemplateDoesNotExist in case of a custom widget

If you want to use a custom widget template stored somewhere under your “TEMPLATES” directory of your project then follow these steps: a) Use the TEMPLATES settings that you have provided in your question b) Set the FORM_RENDERER as following in the settings.py FORM_RENDERER = ‘django.forms.renderers.TemplatesSetting’ c) Add the app “django.forms” to the ‘INSTALLED_APPS‘ list … Read more

What are the steps to make a ModelForm work with a ManyToMany relationship with an intermediary model in Django?

If you use the save method right now, Django will try to save using the manager (which Django doesn’t allow). Unfortunately, the behavior you want is a little bit trickier than what ModelForm does by default. What you need to do is create a formset. First of all, you will need to change the options … Read more

Django-Registration & Django-Profile, using your own custom form

You’re halfway there – you’ve successfully built a custom form that replaces the default form. But you’re attempting to do your custom processing with a save() method on your model form. That was possible in older versions of django-registration, but I can see from the fact that you specified a backend in your URL conf … Read more

django – what goes into the form action parameter when view requires a parameter?

If you want to explicitly set the action, assuming you have a variable username in your template, <form name=”form” method=”post” action=”{% url myview.views username %}”> or you could assign a name for the url in your urls.py so you could reference it like this: # urls.py urlpatterns += patterns(‘myview.views’, url(r’^(?P<user>\w+)/’, ‘myview’, name=”myurl”), # I can’t … Read more

Django – Render CheckboxSelectMultiple() widget individually in template (manually)

This is my simple solution: render CheckboxSelectMultiple() manually in template <table> <thead> <tr> <td>&nbsp;</td> <td>V</td> <td>S</td> </tr> </thead> {% for pk, choice in form.options.field.widget.choices %} <tr> <td><a href=”https://stackoverflow.com/link/{{ choice }}”>{{ choice }}</a></td> <td> <label for=”id_options_{{ forloop.counter0 }}”> <input {% for m2moption in model.m2moptions.all %}{% if option.pk == pk %}checked=”checked”{% endif %}{% endfor %} type=”checkbox” id=”id_options_{{ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)