Questions tagged [inline-formset]

1

votes
0

answer
151

Views

Django ManagementForm data is missing or has been tampered error on request.POST

When i pass request.POST parameter to my CargoUnitFormSet. It get this error in command line. File 'C:\Python27\lib\site-packages\django\utils\functional.py', line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File 'C:\Python27\lib\site-packages\django\forms\formsets.py', l...
Harun ERGUL
1

votes
0

answer
179

Views

Django Formset: saving only the first form of formset

SubTaskFormSet are my SubTasks Forms that i'm having troubles to save properly. In html template i'm dynamically adding/removing inputs thats correspond to elements of my formset, the problem is: only the first form from de formset is being saved. This is how its being created the formset(extra=1 d...
Bruno Brito
1

votes
0

answer
172

Views

Django form with inline/nested data

I'm trying to create an editor for a question whereas the question can have multiple files associated with it. I've tried to get it to work with inline_formsets but I can't seem to get it working properly. The form I'm trying to create is for a Question whereas I want the user to be able to upload f...
steven landau
1

votes
0

answer
113

Views

How to apply autocomplete in manytomany field in django

I would like to apply the autocomplete option for my Preorder.preorder_has_products.through model in order to be able to load products with autocomplete(i tried unsuccessfully).Moreover, I have an inline implementation in order to be able to select for one preorder more than one product. The obstacl...
gtopal
1

votes
1

answer
2k

Views

Django form validation with inline formsets

I have a main form and three inline forsets all on one HTML page for the purpose of creating Estimates for customers. The 'main' form's primary key is used as the foreign key for all three inline formsets. I can create new estimates, save them, change the data, etc. no problem. However, it only work...
Garfonzo
1

votes
1

answer
3.8k

Views

Django inline formset setup

I've setup my classes as below: class InspectionGroup(models.Model): group = models.CharField(max_length=50) class InspectionItem(models.Model): group = models.ForeignKey(InspectionGroup) item = models.CharField(max_length=50) class InspectionQuestion(models.Model): item = models.ForeignKey(Inspecti...
Stephen M
1

votes
2

answer
720

Views

How to reset “DELETE” param to False in django's custom formset's clean method

I made custom formset with custom clean method in it. It's look like: class MyFormsetBase(forms.models.BaseModelFormSet): def __init__(self, *args, **kwargs): .... super(AdvOrderBidFormsetBase, self).__init__(*args, **kwargs) def clean(self): .... if error: raise forms.ValidationError('some validati...
Tural Gurbanov
1

votes
1

answer
127

Views

Creating modelformset instances initialised from database objects

I have a setup at the moment with a series of Objects in my database of type CellType. What I seem to need is the inline formset, which apparently simplifies working with foreign key relationships between models. What I want is a formset, consisting one form for each of a CellCount instance, linked...
jvc26
1

votes
1

answer
83

Views

Inserting Errors into an InlineFormSet Custom Validator

I am using the following custom form validator to ensure that there is not more than one correct entry submitted to my application through an InlineFormSet. class BaseAnswerFormSet(forms.models.BaseInlineFormSet): def clean(self): if any(self.errors): return if len([d['correct'] for d in self.forms...
ajt
1

votes
1

answer
2.4k

Views

Django inline formset validation passes but no objects are saved

I have this form: class ServiceTargetForm(forms.ModelForm): class Meta: model = ServiceTarget fields=('target_type', 'target_value', 'target_threshold') all the fields are required. To make everything more complicated this model has unique_together condition: class ServiceTarget(models.Model): serv...
Odif Yltsaeb
1

votes
2

answer
1.3k

Views

django ignore changed field in formset

I have the following models: class Recipe(models.Model): fields... class Ingredient(models.Model): fields... class UsesIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient = models.ForeignKey(Ingredient) amount = models.FloatField() group = models.CharField() I have a view which l...
Gargamel
1

votes
1

answer
3.3k

Views

Inline formset for Django UpdateView

I have the following forms in my Django application: class SurveyAreaForm(ModelForm): class Media(object): js = formset_media_js class Meta: model = SurveyArea exclude = ['survey', ] widgets = { 'action_by': CustomDateInput(), } AreaFormSet = inlineformset_factory(Survey, SurveyArea, form=SurveyArea...
Matthew Daly
1

votes
1

answer
758

Views

Inline formsets - How to set default values for child form

I have an inline formset factory with a Parent entity and a child entiy. I need to set the child form initial values depending on the parent's attributes. I thought that doing this in the init of my BaseFormset form would be the best way. So here's what I do: class MyBaseFormset(BaseInlineFormSet):...
Ron
1

votes
1

answer
653

Views

Formset, foreign key and OneToOne

I want to create registration form without use any external app but I do not manage to save foregin and OneToOne relation with a formset. Here my models.py : class UserProfile(models.Model): user = models.OneToOneField(User) avatar = models.ImageField(null=True, blank=True, upload_to='avatar/') webs...
Oyabi
1

votes
1

answer
970

Views

How does initial and extra relate in Django inline formsets?

The Django documentation says that 'As shown above you can define the number of extra forms. What this means is that you are telling the formset how many additional forms to show in addition to the number of forms it generates from the initial data.' Source here. However, (at least) with inline for...
jleeothon
1

votes
1

answer
144

Views

Render only fields in a Django inline_formset

I want to render only fields in a Django inline_formset. This is my template: Storage {% for form in storage_formset %} {{ form.help_texts }} {{ form.errors }} {{ form }} {% endfor %} And this is my form: help = {'field1' : 'help1', 'field2' : 'help2'} StorageFormSet = inlineformset_factory(WorkOrde...
Roger Gonzalez
1

votes
1

answer
1.1k

Views

Django. Filter new entry inline with data based on parent pk

Making good progress with my Django project but for this sticking usability issue. I want to be able to filter dropdowns in inline forms based on the parent id. For example. The Theme model belongs to a course. class Theme (models.Model): id = models.AutoField(primary_key=True) # AutoField? code =...
Davies-Barnard
1

votes
1

answer
177

Views

Django - Find out which model instance I'm editing in an inline formset

Note: I'm new to Django and Python. I'm not sure if I've misunderstood the use of inline formsets in some way. I needed to be able to edit certain fields for multiple instances of a Guest model (linked to a parent Invite model) at the same time in one form. After a lot of back and forth, I managed t...
1

votes
1

answer
255

Views

Django inlineformset_factory with queryset

I need to filter foreignkey select options on a form based on an object id passed by a view. I have the following view: @login_required() def QAView(request, equipamento_id): form = ActividadeForm() equipamento = Equipamento.objects.get(id=equipamento_id) testes_list = Teste.objects.filter(equipame...
user2466766
1

votes
1

answer
270

Views

BaseInlineFormSet clean method in admin false trigger?

I am trying to update a field in Admin but it raises Validation Error from clean method which I have defined as follows in forms.py: class BasePhoneFormSet(BaseInlineFormSet): def clean(self): super(BasePhoneFormSet, self).clean() if any(self.errors): return phone_numbers = [] for form in self.forms...
static
1

votes
1

answer
335

Views

javascript event handler not correctly work in django inline formset

I designed a inline formset as follows: class EventForm(ModelForm): class Meta: model = Event exclude = ['created'] class GalleryForm(ModelForm): class Meta: model= Gallery exclude = ['pub_date'] GalleryFormSet = inlineformset_factory(Event, Gallery, extra=0, min_num=1, fields=('title','image' )) It...
dj pro
1

votes
1

answer
223

Views

excluding id field in an inline formset when saving

I have two models, connected by a foreign key. One is an inline formset. For some reason, the formset ids are being identified as Primary Keys in the database, and every time the form is submitted, the table belonging to the formset is basically overwritten. When saving, how do I ignore the formse...
Davida C
1

votes
1

answer
279

Views

Django - Modify Inlineformset Delete button

I do a custom UI/UX for an inlineformset. By default the inlineformset widget has a delete button. I wan to add and remove forms from inlineformset dynamic using javascript. In some cases the delete is just a button instead of the checkbox, in other cases is in a modal window. When a user click dele...
user3541631
1

votes
1

answer
152

Views

How to dynamically filter ModelChoice's queryset in a Inlineformset?

I just want to filter select field in a inlineformset. Scenario: Every task has own report.Each task has a booking .Booking has several booked items.I want to display only related bookeditems based on booking in report form.Report form is generated using signals and while editing i'm using inlinefor...
Emil George James
1

votes
1

answer
1k

Views

Django nested formsets adding forms dynamically

I'm trying to create a survey page using Django that has the functionality to add questions and choices(for each question) dynamically. I have three following model classes: Survey, Question and Choice. I did a lot of research to figure out how to go about implementing the forms and it seems nested...
ehka
1

votes
1

answer
52

Views

Linking to other Foreign Model with DetailView and Formset in Django

I am new to django-formset. I have been trying to find a way to link the models at formset (Model_CustomerCart and Model_CustomerCartItem) with the other model named Model_ItemPrice. Such that with DetailView, the html page can display a list of items and also their corresponding price. Does anyone...
Fxs7576
1

votes
1

answer
68

Views

Accessing Parent of Inline Form Sets in template?

I am wondering how to access the parent of the inline form set in Django. Here is what I am currently doing: views.py def upload(request): [Code Ommitted] formSet = inlineformset_factory(Tombstone, Tank, form = TombstoneForm) form = formSet(instance=t) return render(request, 'edit_form2.html', {'for...
Jordan Rose
1

votes
2

answer
0

Views

inlineformset_factory custom form id

I am writing a web application that uses ajax to add new forms on the page. Existing forms are made using inlineformset_factory. When client side gets the form it inserts it in the right position and updates the value of #id_form_type-TOTAL_FORMS' (form_type is name of the form in this example). Exi...
del-boy
1

votes
1

answer
0

Views

Django : Inline editing of related model using inlineformset

I'm still stuck with the inline Tree-like-eiditing of related models on same page. I've got three models, A, B and C. Class A Class B fb = foreignkey(A) Class C fc = foreignkey(B) In admin.py I'm doing something like AdminA inlines = [inlineB] AdminB inlines = [inlineC] I want that when I edit/add...
Neo
1

votes
2

answer
158

Views

How can I get an image URL from an image field in an InlineFormset?

I have the following models: class Event(models.Model): name = models.CharField(max_length=128, null=True, blank=True) class Picture(models.Model): event = models.ForeignKey(Event) image = models.ImageField(upload_to='media') Picture has an FK to Event model, so when I want to use them in a form (cr...
Roger Gonzalez
1

votes
1

answer
169

Views

Django: Dynamic inline forms with filter upon user selection

I have created these models: class Service(models.Model): name = models.CharField(blank=False, max_length=200)code here class Monitor(models.Model): name = models.CharField(blank=False, max_length=100) services = models.ManyToManyField(Service, related_name='monitors') class Student(models.Model): n...
ESS
1

votes
1

answer
675

Views

How to label a form instance within a django inline formset?

I have what I think is a common enough situation, but can't seem to get my head around it. I've used the django.forms.inlineformset_factory to create a formset of forms which allow the user to alter aspects of a foreign key object, and these are working fine. The trouble is that I want to be able t...
keri
1

votes
1

answer
824

Views

How can I change the queryset of one of the fields in the form I'm passing to inlineformset_factory

I'm using django extra views: # views.py from django.forms.models import inlineformset_factory from extra_views import (CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet, ) class LinkInline(InlineFormSet): model = Link form = LinkForm extra = 1 def get_form(self): return LinkForm({}) def g...
la_f0ka
0

votes
0

answer
5

Views

Creating a form wizard / formset to answer questions from a table and saving them into another (Survey)

I am new to Django. I apologize if I don't make much sense. I have an EU project to create a survey tool for adult educators who are assisting migrants and refugees. I would like to use a WizardView/SessionView together with formset to answer a set of 24 questions from a matrix based on Max-Neef's H...
Fatih
1

votes
1

answer
1.3k

Views

How to create an inline formset for a reverse foreign key relationship

I have a Property Model as follows = class Property(models.Model): property_type = models.CharField(max_length=255, default='Apartment') specifications = models.CharField(max_length=255, default='Basic') built_up_area = models.FloatField(max_length=6, null=False, default=0) total_area = models.Floa...
utkbansal
2

votes
2

answer
2.9k

Views

specify queryset when instantiating an inlineformset

I have the following in views.py to generate a page that shows an inline set of forms for a user's 'qualifications' from django.db.models import User from models import UserQualification def edit_quals(request): QualsFormSet = inlineformset_factory(User, UserQualification, fields=('qualification', '...
rsp
2

votes
1

answer
2.4k

Views

DJANGO: How to render model object name in form instead of literal “model object”?

I have the following models: Department, Projects, Departmentprojects, Employees, and Membership. A Department has many Projects and Projects have many Employees that are assigned roles through Membership. I am trying to create a InlineFormset so that an EU can assign an Employee's role to multiple...
thedeepfield
18

votes
1

answer
15.3k

Views

how to limit django admin inline formsets

How do you limit the inline formset in django admin? Problem: I have a table A with 1 to n relationship with B. Table A should have at least one Table B item and a max of 5 Table B items. Thanks
ginad
3

votes
0

answer
80

Views

django: inlineformset very slow

I have the following models: class Recipe(models.Model): .... class Ingredient(models.Model): .... class RecipePosition(models.Model): recipe = models.ForeignKey(Recipe,related_name='recipe_positions', on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient,related_name='ingredie...
Santhosh Yedidi
6

votes
2

answer
16.7k

Views

Django: how to display form errors for each model object in a inline formset

I have a author model and a books model. A user can modify properties of all the books from a given author. I want to be able to display errors for each individual book rather than have all the errors listed on the top, How can I do this? MODELS from django.db import models from django.forms import...
thedeepfield

View additional questions