I get data in from POST and validate it via this standard snippet:
entry_formset = EntryFormSet(request.POST, request.FILES, prefix='entries')
if entry_formset.is_valid():
....
The EntryFormSet modelform overrides a foreign key field widget to present a text field. That way, the user can enter an existing key (suggested via an Aja...
I have a problem where I need to display a lot of forms for detail data for a hierarchical data set. I want to display some relational fields as labels for the forms and I'm struggling with a way to do this in a more robust way. Here is the code...
class Category(models.Model):
name = models.CharField(max_length=160)
class Item(mod...
Hey there,
I've been looking through the site and trying to find something to help me, but I can't find anything. I'll begin with showing the models that relate to this:
class Game(models.Model):
home_team = models.ForeignKey(Team, related_name='home_team')
away_team = models.ForeignKey(Team, related_name='away_team')
round ...
Hey guys,
My problem is similar to http://stackoverflow.com/questions/622982/django-passing-custom-form-parameters-to-formset/624013
Ive have these classes
class Game(models.Model):
home_team = models.ForeignKey(Team, related_name='home_team')
away_team = models.ForeignKey(Team, related_name='away_team')
round = models.Fore...
I have a Model Formset that should take files sent via POST and add them to the database.
However, the form includes the IDs of files already in the database, which leads to information being overwritten. For example, the HTML output for the form looks like this:
<label for="id_files-0-theFile">File:</label>
<input type="file" nam...
I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing request.user.
What I haven't been able to fi...
I have an inline model formset, and I'd like to make fields non-editable if those fields already have values when the page is loaded. If the user clicks an "Edit" button on that row, it would become editable and (using JavaScript) I would replace the original widgets with editable ones. I'd like to do something like this when loading t...
In my view I create a formset of photos belonging to a specific article, this works brilliantly, and I am able to render and process the forms. However for the image field I would like to display the already uploaded image. Normally I would access the path through the instance form.instance.image.get_thumbnail_url however that doesn't wo...
Application:
This is a workshop proposal system for a conference. A user can create presenters and workshops, and link them together. Each user should only have access to the presenters and workshops that s/he created/owns.
# Models:
class Workshop(models.Model):
name = models.CharField(max_length=140, db_index=True)
presenter...
I have two models (ModelParent and ModelChild) with same m2m fields on Subject model.
ModelChild has a foreign key on ModelParent and ModelChild is defined as inline for ModelParent on admin page.
### models.py ###
class Subject(Models.Model):
pass
class ModelParent(models.Model):
subjects_parent = ManyToManyField(Subject)...
Having a ModelFormSet built with modelformset_factory and using a model with an optional ForeignKey, how can I make empty (null) associations to validate on that form?
Here is a sample code:
### model
class Prueba(models.Model):
cliente = models.ForeignKey(Cliente, null = True)
valor = models.CharField(max_length = 20)
### vi...
I'd like to be able to use a customized form in a modelformset_factory. For example:
models.py
class Author(models.Model):
name = models.CharField()
address = models.CharField()
class AuthorForm(ModelForm):
class Meta:
model = Author
views.py
def test_render(request):
myModelFormset = modelformset_factory(Aut...
I've been looking for a way to create a read-only form field and every article I've found on the subject comes with a statement that "this is a bad idea". Now for an individual form, I can understand that there are other ways to solve the problem, but using a read only form field in a modelformset seems like a completely natural idea.
...
I try to add initial values to the empty form of a modelformset_factory.
FormSet = modelformset_factory(MyModel, extra=2)
formset = FormSet(queryset=MyModel.objects.none(), initial=[{'foo': 'bar'}, {'foo': 'bar'}])
I would like to set initial value to the formset.empty_form , how can I achieve this ?
...
I have a models.py class as below
class Educational_Qualification(models.Model):
user = models.ForeignKey(User)
exam = models.CharField(max_length=40)
pass_month = models.CharField(max_length=40)
I have a views.py as below
def create_qualification(request):
QFormSet = modelformset_factory(Educational_Qualification, extra=3,...
I am trying to take a modelformset, then process the records that have been changed after the form is submitted. For new records, I need to do certain action like set one form field equal to a hidden field and add some time stamps. For edited records, I do not need to do these actions, just to save the model's edited data. For unchaged r...
As title says, how can I override it - specifically, how to change its widget from default TextInput to HiddenInput? And why isn't it hidden to begin with :S
I tried passing custom callback function as formfield callback to modelformset_factory but it only changed the default fields originating from model.
I also tried specifying anothe...
I have created a formset from a model that has an ImageField inside it. Now when editing the formset I would like to show the image next to the other fields in the template so the user can see what images they have uploaded.
From what I understand their is no simple way of saying:
{% for form in model_formset %}
{{form.model}}
...
My goal is to have a formset that lists 5 versions of the same form. On submit the form should create the filled out forms in the DB.
My issue is that the forms come repopulated with data. Which is bad. Any thoughts on what I might be doing wrong?
Models.py
from django.db import models
from django.contrib.auth.models import User
PR...
How can i go about making list that do this in Django.
I want it to look like:
Item A
add
Item B
add
Item C
add
where items are from Item models. When the add button is clicked, the item will be added to a list model.
I use modelformset so that i could get Item list which is already populated in the Item model. I have...