7๐
I have meet this problem.
The reason is there is NO something like form-TOTAL_FORMS, form-INITIAL_FORMS and form-MAX_NUM_FORMS)
in your POST
data.
You should use {{ formset.as_p }}
, this will render the management_form data from the formset. If you want to make the custom formset rendering, you should not forget the management_form of the formset to let POST data be with the mangement_form data.
6๐
When you use inline formset, you need to provide the instance that the objects relate to.
# First, fetch the instance from the db
workout = code_that_fetches_instance()
if request.method == "POST" :
formset = WorkoutInlineFormSet(request.POST, instance=workout)
...
else:
formset = WorkoutInlineFormSet(instance=workout)
See the example in the docs on using an inline formset in a view for more information.
If workout
and exercise
are your models, you should follow the python convention and rename them Workout
and Exercise
. Lowercase workout
should be the instance that all the exercises in your formset are linked to.
- How to import a Django project settings.py Python file from a sub-directory?
- Order queryset by alternating value
- Sphinx and re-usable Django apps
- Using Django minus the web server
- Django annotating with a first element of a related queryset
1๐
Change this:
formset = WorkoutInlineFormSet(request.POST)
to this:
formset = WorkoutInlineFormSet(request.POST or None, request.FILES or None)
- Creating a .gitignore file for a Django website
- How can I disable a model field in a django form
- AttributeError: 'RelatedManager' object has no attribute 'remove'
- How can I schedule a Task to execute at a specific time using celery?
- Django Rest Framework 3.1 breaks pagination.PaginationSerializer