I modified your code to only render fields and their associated help texts: <div id="storage"> <h1>Storage</h1> {% for form in storage_formset %} <div class="form-group"> <label class="col-sm-2 control-label">{{ form.help_texts }}</label> <div class="col-sm-10"> {{ form.errors }} {% for field in form %} {{ field }} {{ field.help_text }} {% endfor %} </div>...
django,foreign-key-relationship,inline-formset
Your issue is that you're not "initializing" the variable shoppinglist_id in your form def init Try this: class ShoppingListItemForm(ModelForm): class Meta: model = ShoppingListItem fields = ('item', 'brand', 'quantity', 'current', 'category', 'size', ) def __init__(self, *args, **kwargs): shoppinglist_id = kwargs.pop('shoppinglist_id', None) super(ShoppingListItemForm, self).__init__(*args, **kwargs) self.fields['category'].queryset = ListItemCategory.objects.filter(shoppinglist__id=shoppinglist_id) And you should...
django,django-models,django-forms,inline-formset
You've misunderstood what an inline formset is. It's for editing the "many" side of a one-to-many relationship: that is, given a parent model of City, you could edit inline the various Properties that belong to that city. You don't want a formset at all to simply edit the single City...
python,django,django-orm,inline-formset
I finally found a solution to my problem. There actually is a change in behavior with Django 1.7: formset.save(commit=False) no longer deletes deleted items (checkbox checked). You therefore have to use formset.deleted_objects to do it: working code below def post(self, request, *args, **kwargs): self.object = self.get_object() form_class = self.get_form_class() form...
Set the extra argument of the function to 1: StorageFormSet = inlineformset_factory(WorkOrder, Storage, fields=('sto_type', 'paper_type', 'paper_qnty', 'web_paper_qnty',), extra=1) ...
django,django-forms,formset,inline-formset
I've solved this problem using the technique described here rather than using a formset: https://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/...
Ok, so I've found that problem was not in the views.py nor in forms.py, but in template. Because I've built the template without using {{form.as_p/table/...}} The form had some extra inputs - DELETE,ID and foreignKey... after adding them to my for loop, everything works fine :)
python,django,django-models,django-admin,inline-formset
Don't use the inline for the tags. Regular M2M field will work in admin just fine. For more adequate M2M widget add the filter_horizontal property: class QuestionAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields': ['text', 'tags']}), ] filter_horizontal = ['tags'] ... To create a Tag from the QuestionAdmin press the green +...