Questions tagged [inline-formset]

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.2k

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
2

votes
1

answer
917

Views

when adding a new inline to my formset, my datepickers stop working

Bit of a strange one today. I've a very basic project. A form and added to that I have an inline form. It's books to authors. When the form loads(/authors/create/) I have a author name and underneath I have a form where I can add books to that author. To be able to have dynamic inlines(able to add o...
darren
2

votes
1

answer
406

Views

Django One-To-Many Model and Admin inlines

I 'm trying to define 2 models in django like so: class Selector(models.Model): # A Beautiful Soup selector selector = models.CharField(max_length=ELEMENT_SELECTOR_MAX_LENGTH, null=True, blank=True) def __str__(self): return self.selector class Provider(models.Model): # Articles' parent container se...
mitsest
6

votes
2

answer
9.3k

Views

Initial Data for Django Inline Formsets

I have put together a form to save a recipe. It makes use of a form and an inline formset. I have users with text files containing recipes and they would like to cut and paste the data to make entry easier. I have worked out how to populate the form portion after processing the raw text input but...
Sinidex
2

votes
1

answer
267

Views

Customize inline_formset field display of foreign key

I have a model called Access that links to two other models. class Access (models.Model): portfolio_id = models.ForeignKey(Portfolio) user_id = models.ForeignKey(User) title = models.CharField(max_length=30, null=True, blank=True) access_rights = models.PositiveIntegerField(choices=ACCESS_CHOICES) I...
rc_cola15
2

votes
2

answer
1.6k

Views

Alter fields in Django formset using clean

How do you alter fields in each form of a Django formset using the clean method? class MyInlineFormSet(BaseInlineFormSet): def clean(self): if self.cleaned_data['inputted'] == self.cleaned_data['answer']: self.cleaned_data['is_correct'] = True return self.cleaned_data This isn't working and I've see...
ssomnoremac
2

votes
1

answer
231

Views

How do I make a foreign key appear as its own form instead of a dropdown menu?

I'm trying to create a formset for a list of movies like so: class MovieList(models.Model): user = models.ForeignKey(User) movie = models.ForeignKey(Movie) class Movie(models.Model): genre = models.ForeignKey(Genre) name = models.CharField(max_length=300) MovieListFormSet = inlineformset_factory(Use...
tkon J.
1

votes
2

answer
862

Views

Inline form validation returns empty formset.errors list

I have the following inline formset: CreateClientFormset = inlineformset_factory( Client, EventType, fields=( 'name', ), extra=0, can_delete=True, min_num=1, validate_min=True, widgets={ 'name': forms.TextInput(attrs={ 'class':'form-control', 'maxlength' : 50 }) }) And the following view: def create...
Roger Gonzalez
1

votes
1

answer
546

Views

Django Inline formsets only saving three objects

I have a question object that has a foreign key field to a discussion object. I am trying to render a form using a discussion ModelForm, and a question Inline formset. When it renders an empty form to the page, everything works fine, and all the fields are where they need to be. The error is that I...
JBT
6

votes
1

answer
487

Views

Django admin: Inline straight to second-level relationship

I have a three-levels Invoice model which I'd like to display on Django's admin area... in a "kind of special" way. Allow me to provide a bit of background: Each Invoice is conformed by several SubInvoice(s), and each SubInvoice is conformed by several InvoiceItem(s), which contain a break down of t...
BorrajaX
3

votes
2

answer
1k

Views

Django Inline for ManyToMany generate duplicate queries

I'm experiencing some major performing issue with my django admin. Lots of duplicate queries based on how many inlines that I have. models.py class Setting(models.Model): name = models.CharField(max_length=50, unique=True) class Meta: ordering = ('name',) def __str__(self): return self.name class Di...
H Bui
3

votes
1

answer
875

Views

Django inlineformset - custom save method

This is my models.py class Invoices(models.Model): ... sum_w_vat = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_wo_vat = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_discount = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_vat = models...
Mission
3

votes
2

answer
9.1k

Views

Django: Aquiring form id from formset

I am not sure if title describes what i want accurately. What i want is to achieve something like that: Django add / remove form without multiple submit. But i have not list of items i have formset and forms. The form of this formset does contain information i could use for creating link like that {...
Odif Yltsaeb
1

votes
1

answer
1k

Views

Using a Django FileField in an inline formset

having issues getting the file to upload in my app. A User submits a report and can add attachments (through a foreign key relationship). I've got the inline form showing up and will work if I leave it blank, but when I try to upload a file then submit the form I get a 500 error. The base report is...
mKane848
2

votes
1

answer
502

Views

Access inline object in InlineModelAdmin form

I have such a problem: I want to limit foreign key choices in inline model admin, but I want to do this based on some values specified in this inline object. How can I access inline object (not parent object) inside InlineModelAdmin methods (specifically in formfield_for_foreignkey(self, db_field, r...
andrzejdoro
2

votes
1

answer
7.8k

Views

Django: inline formset example from documentation

I have been given a hint to try out the inline formset as a solution to a problem. Just experimenting with it in a sandbox project. I am trying to replicate the exact same example as in the Django documentation and it fails. :( Models: TITLE_CHOICES = ( ('MR', 'Mr.'), ('MRS', 'Mrs.'), ('MS', 'Ms.'),...
Houman
3

votes
1

answer
1.6k

Views

formset, inlineformset_Factory and kwargs

I have a couple models lets call them Model A and Model B. There is a foreign key to A from B. That is the cardinality between A and B is 1:n. I have made a corresponding ModelForm for B called MF_B. I have an additional field I define in B. e.g. class MF_B(forms.ModelForm): stuff = forms.MultipleCh...
w--
2

votes
0

answer
2.3k

Views

Django Inline formsets with Form wizard¶

I have two models, the second one have a ForeignKeyto the first one. I'm using Django form wizzard to complet many regrouped fields in separated steps. The problem is when I arrive in the "TeamMember" step, where I'm supposed to let the user enter many members. I was thinking to use Django Inline fo...
yann
2

votes
2

answer
3.6k

Views

Custom formset templates in Django

I am using a Django formset for this model: class Book(models.Model): book_id=models.AutoField(primary_key=True,unique=True) book_name=models.CharField(max_length=30) publisher_name=models.CharField(max_length=40) author=models.ForeignKey(Author) The formset is defined thus: BookFormset = inlineform...
user2086641
1

votes
1

answer
250

Views

Where has cleaned_data vanished in Django 1.11?

I have created an inlineformset_factory as below : formset = inlineformset_factory(Author, Book, form=BookForm, formset=BaseBookFormSet, can_order=False, can_delete=True, extra=1, fields=('id', name) ) BookForm is as below: class BookForm(forms.ModelForm): name = forms.Charfield(required=True) def...
anshuman
3

votes
1

answer
1.9k

Views

raise forms.ValidationError not working

I have the following models: class Project(models.Model): title = models.CharField(max_length="100") pub_date = models.DateField(auto_now_add=True, editable=False) budget = models.IntegerField() class Milestone(models.Model): title = models.CharField(max_length="50") budget_percentage = models.Integ...
Santiago
2

votes
1

answer
1k

Views

Django inline-formset with an image field not updating

I have a listing model and a photo model: class Listing(models.Model): title = models.CharField(max_length=255) ... class Photo(models.Model): image = models.ImageField(upload_to=create_file_path) listing = models.ForeignKey(Listing, related_name='photos') I am using a CBV, UpdateView, to edit a lis...
Rob
36

votes
3

answer
29.4k

Views

Creating a model and related models with Inline formsets

[I have posted this at the Django users | Google Groups also.] Using the example in the inline formset docs, I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new objects using inline formsets, but have been unable t...
chefsmart
3

votes
1

answer
333

Views

Django GenericTabularInline for multiple databases

I've been trying to make the GenericTabularInline class work in a two-admin two-databases setup by inheriting from it and overriding some methods in the BaseModelAdmin class, as is done in the Django docs (https://docs.djangoproject.com/en/dev/topics/db/multi-db/), but if a child model is edited in...
zerobydefinition
2

votes
0

answer
132

Views

Inline formset not rendering form field

I have models: class MediaInfo(models.Model): title = models.CharField(max_length=50,blank=True) description = models.CharField(max_length=255,blank=True) media_file = models.FileField(upload_to=get_upload_file_name) def __unicode__(self): return self.title class Media(models.Model): media_files = m...
gamer
4

votes
1

answer
1.9k

Views

django: How to use inlineformset within the formwizard?

I'm displaying two separate sample projects. The first is a Contact related and shows the principle of using the formwizard. The second is an ingredients to recipes related project which shows how to use inlines within a form. I want inlines to be in my formwizard the same way they work in a normal...
darren
3

votes
2

answer
1.1k

Views

dynamically populating fields in a formset

I have two models that looks like this: class RouteBase(models.Model): base = models.ForeignKey("Base") route = models.ForeignKey("Route") sequence = models.IntegerField() class Route(models.Model): bases = models.ManyToManyField("Base", through="RouteBase", blank=True)...
priestc
2

votes
1

answer
1.6k

Views

MultiValueDictKeyError while updating inline formsets

I'm having an issue with Django while updating inline formsets. I want to update a form and an inline formset, but it raises this error: "MultiValueDictKeyError" Exception Value: "u'clientphone_set-0-id'" This is my view: def edit_client(request, client_id): client_to_edit = Client.objects.get(id=c...
Roger Gonzalez
2

votes
2

answer
145

Views

Passing queryset to foreignkeyfield in django inlineform

I got a little problem which I thought must me quite common. Here's the problem described very generic: class Ownable(models.Model): user = models.ForeignKey(django.contrib.auth.models.User) class Meta: abstract = True class Bowl(Ownable): pass class Pea(Ownable): bowl = models.ForeignKey(bowl) Rela...
codingjoe
7

votes
1

answer
2.9k

Views

Django inline foreign key does not match parent primary key

I need some help getting past a django error using inline forms. I can't seem to figure this out. I could probably force-insert the eventID if I could figure out how to do that before it tries to validate. When I submit my form I get an error: Hidden field (event): The inline foreign key did not m...
codingJoe
3

votes
1

answer
2k

Views

Make inlineformset in django required

I am new to django (until now, I used the symfony PHP Framework). My problem is this: I have a model Event and model Date. The Date has a foreign key to Event, so that an Event may (or should) have one or more Dates. Now I want to have a form to create Events and this form should include a subform f...
sewid
2

votes
1

answer
1.4k

Views

Inline formset factory - pass request to child form

I'm facing a quite challenging taks: I need an inlineformset_factory connecting my ParentEntity to my foreign key-bound ChildEntities. My ChildEntity contains a foreign key relation I need to filter per logged-in user - so I need the request in the ChildForm. What I've tried so far: I tried to use t...
Ron
2

votes
0

answer
480

Views

Django inline formset(UI) delete/remove

I'm trying to do a inline formset with UI not with django built in inlineformset_factory form. Here I'm done with add_view and edit_view. Here in the edit view I can update the existing record for the both parent and child model,and can add new record to the child model. But I cant remove the existi...
Ajay Kumar
3

votes
1

answer
1.9k

Views

How to imitate django admin's OneToOneField optional form

I would like to imitate the functionality that the Django Admin site offers when a model has a OneToOneField to another model, where it is optional to fill the form for the OneToOne model. The form for that field is always shown, but if it is empty, a OneToOneField's object is not created, only the...
foo_fighter

View additional questions