All Questions
621
questions
79
votes
6
answers
88k
views
Django required field in model form
I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py
class CircuitForm(ModelForm):
class Meta:
model = Circuit
...
48
votes
2
answers
43k
views
How can I fill up form with model object data?
I want to fill up form with data from model instance. But my form has less fields than model. If I have code like this:
class Item(models.Model)
name = models.CharField(max_length=100)
price =...
43
votes
3
answers
72k
views
Restrict django FloatField to 2 decimal places
I am looking for a way to limit the FloatField in Django to 2 decimal places. Has anyone got a clue of how this could be done without having to use a DecimalField?
I tried decimal_places=2, but this ...
43
votes
6
answers
75k
views
How can I change a Django form field value before saving?
if request.method == 'POST':
userf = UsersModelForm(request.POST)
username = userf.data['username']
password = userf.data['password']
passwordrepeat = userf.data['passwordrepeat']
...
32
votes
4
answers
44k
views
How to set initial data for Django admin model add instance form?
How can I set an initial value of a field in the automatically generated form for adding a Django model instance, before the form is displayed? I am using Django 1.3.1.
My model is the following:
...
19
votes
2
answers
23k
views
Rails Simple Form custom association select field
I have a select field and I want to put a custom attribute at it called name, I tried to do it like that:
<%= f.association :in_charge, :collection => User.lawyer.map{ |l| [l.name, l.id, {:...
17
votes
6
answers
21k
views
How to choose the value and label from Django ModelChoiceField queryset
I was trying to create a django form and one of my field contain a ModelChoiceField
class FooForm(forms.Form):
person = forms.ModelChoiceField(queryset=Person.objects.filter(is_active=True)....
17
votes
1
answer
9k
views
is a ModelChoiceField always required?
I have a model
class Article(models.Model):
.
.
language = models.ForeignKey(Language, help_text="Select the article's language")
parent_article = models.ForeignKey('self', null=True, ...
15
votes
3
answers
15k
views
Conditionally Require Only One Field In Django Model Form
Anyway to make a field conditionally required based on whether or not another field in the same form has been filled out?
If field1 has no data, but field2 does
form is valid.
If field1 has no ...
15
votes
2
answers
14k
views
Join table for has_many through in Rails
I am new to programming & rails and there's something I dont fully understand.
I am creating an app with
product has_many categories
category has_many products
If I understand correctly I need ...
14
votes
4
answers
14k
views
Can't resolve image into URL: to_model delegated to attachment, but attachment is nil in Rails 5.2
I have the following form:
<%= form_with(model: user, local: true) do |form| %>
<% if user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user....
14
votes
2
answers
4k
views
Raise ValidationError from pre_save receiver function?
I'd like to inform the user if something fails during processing of the data in instance in my pre_save receiver function.
Is it possible to raise a custom ValidationError from the receiver function? ...
13
votes
3
answers
40k
views
Cannot assign must be a instance. Django
Ive been trying to create a django project that has users and those users can add titles of books they have created. But each time I enter a book title (not on the admin page) I get this error
Cannot ...
12
votes
9
answers
25k
views
Yii form model validation- either one is required
I have two fields on the form ( forgotpassword form ) username and email Id . User should enter one of them . I mean to retrieve the password user can enter user name or the email id . Could some ...
12
votes
3
answers
23k
views
How can I get a textarea from model+ModelForm?
models.py=>
from django.db import models
from django.forms import ModelForm
from datetime import date
import datetime
from django import forms
from django.forms import Textarea
class Post(models....
12
votes
1
answer
9k
views
Rails 3 - how to save (un)checked checkboxes?
I have in a form (form_tag) several checkboxes like this:
<%=check_box_tag 'model_name[column_name]', 1, (@data.model_name.column_name == 1 ? true : false)%>
And updating them like:
variable =...
11
votes
3
answers
64k
views
MVC 5 Multiple Models in a Single View
Could somebody please provide an example of how to combine two models within one view?
Currently I have a page called RecordCard which contains:
@model IEnumerable<WebApplication1.Models.Weight&...
9
votes
2
answers
2k
views
Django: combine lazy translation with mark safe in model choices
Yeah, so, I want to store translated choices for my model, but Django disagrees with me on this one. Version of Django is 1.3 and the model and choices look something like this:
from django.db import ...
9
votes
2
answers
14k
views
This field is required. Error with ImageField and FileField on Django
I am new on Django, I am using Django 1.6.1 and in one of my form I get the next error
This field is required.
I don't understand why I get this error, my form is very basic, so my Model, the ...
8
votes
1
answer
14k
views
Why is "blank" is missing in django.forms.CharField, but present in django.db.models.CharField?
Background
I have a model with two fields that are set the blank:
class News(models.Model): ...
8
votes
2
answers
12k
views
Ruby on Rails: create records for multiple models with one form and one submit
I have a 3 models: quote, customer, and item. Each quote has one customer and one item. I would like to create a new quote, a new customer, and a new item in their respective tables when I press the ...
7
votes
3
answers
15k
views
Rails - Is there a way to update a single attribute?
I was just wondering, I have a model that, besides the id's from other models (FK), it has a single attribute boolean. I want to know how can I create a button that changes this boolean and just that
...
7
votes
3
answers
10k
views
laravel form model binding - date formatting
I have Laravel. I have a form. I have a MySQL database. There are some dates in it. When I bind the model and the form, the form is dutifully populated with raw MySQL dates. This is obviously not ...
6
votes
3
answers
9k
views
clarification/when/where to use super in django/python
Actually we know super is used to find the "parent class" and return its object, something like/using self.__class__.__mro__
What I was confused about is when to use it exactly?
Suppose we have a ...
6
votes
3
answers
5k
views
How to remove the unselected item in a select and radio input in Django
If a model's field is a choice or foreign key, the widget on the page is a select input or radios if you specify that. Django places "---------" in the first item as an unselected value. How can I ...
6
votes
2
answers
12k
views
Django: model maxlength and form maxlength
I need to somehow hook the Model's max_length constraints into a Form object.
Say I define a Model with a field: name = models.CharField(max_length=30)
Now I define a Form object with the same field:...
6
votes
2
answers
15k
views
Yii - multiple records in one form submission
Does anyone know how to add multiple records using just one form in Yii? All the records belong to the same model and are of the same format.
Many thanks,
Nick
6
votes
4
answers
6k
views
Adding extra fields to django-registration form
I have a model called "Organization" that I've setup as a User profile and I would like to have the fields from the "Organization" model show up on the registration page. How do I go about doing this ...
6
votes
1
answer
5k
views
django: How to make one form from multiple models containing foreignkeys
I am trying to make a form on one page that uses multiple models. The models reference each other. I am having trouble getting the form to validate because I cant figure out how to get the id of two ...
6
votes
1
answer
4k
views
Django: ManyToManyField, add object if it doesn't already exist
I'm trying to use ModelForms in Django to add content to my database which includes a ManyToManyField. Here is the relevant part of my model:
class Category(models.Model):
name = models....
5
votes
2
answers
16k
views
django use model choices in modelform
I was wondering how i should use my model choices options, in my ModelForm.
Example(model):
class NPCGuild(models.Model):
CATEGORIES=(
('COM', 'Combat'),
('CRA', 'Crafting'),
...
5
votes
1
answer
4k
views
How to pass a model containing an IEnumerable model (complex) into a controller from a view C# MVC3?
I have had a look through other questions and answers on this site but cannot find the answer I need.
I have a StudentRecord entity:
public class StudentRecord : Persistent {
public virtual ...
5
votes
2
answers
7k
views
django model search form
Firstly, I did my homework and looked around before posting! My question seems like a very basic thing that must’ve been covered before.
I'm now looking at Django-filter as a potential solution, but ...
5
votes
2
answers
5k
views
Rails - one form to two models
I am building a form in Rails (version 4.2.5) to collect basic information about stores, and I would like to have the form submit data to two separate models - one called Store, which collects ...
5
votes
2
answers
2k
views
Is it possible to show model help text as a title attribute on forms in Django?
I want to show the model field help_text as an HTML title attribute in a form, instead of it being appended to the end of the line, as is the default.
I like all the information about a model Field ...
5
votes
2
answers
6k
views
How to fill a Django form using test Client
I'd like to test my Django forms, but I got this error
django.core.exceptions.ValidationError: ['ManagementForm data is missing or has been tampered with']
doing this :
self.client.post(self.url, ...
5
votes
4
answers
81
views
Should default model fields be set by the Form or the Model?
Which option is best, 1 or 2?
1.
class TopicForm(forms.Form):
name = forms.CharField(required=True)
body = RichTextFormField(required=True)
def save(self, request):
t = models....
5
votes
1
answer
10k
views
How do I make cakePHP's form helper 'create' action use a custom id?
I'm building a site that requires multiple forms for the same model in varying numbers throughout a single page. These forms belong to an object with an id. Currently, since I can't figure out how to ...
5
votes
1
answer
4k
views
Django: creating dynamic forms
I have these models and I want to build forms based on the data:
class Location(models.Model):
name=models.CharField(max_length=255)
location_id=models.CharField(max_length=255)
...
5
votes
1
answer
911
views
Rails validation best practice
I have this validation for my user:
validates :password,
presence: true,
confirmation: true,
length: { minimum: 6 },
:on => :create
This is obvious. When I'm creating (registering) a ...
5
votes
5
answers
17k
views
Struts 2: updating a list of objects from a form with model driven architecture
I already searched and found several approaches here, but I can't get them working for my project.
I want to show an edit page for a list of objects, which should all be updated at once. I use the ...
5
votes
2
answers
11k
views
Extjs 4, forms with checkboxes and loadRecord
In my Extjs4 application I have a grid and a form.
The user model:
Ext.define('TestApplication.model.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int', useNull: ...
5
votes
0
answers
2k
views
How to trigger ng-model value in angularjs if browser auto fill scripts filled out the forms [duplicate]
So I have a generic problem with chrom autofill scripts and my guess is that for all autofill script this would be a problem.
When input fields get set with autofills, how do I register them with the ...
5
votes
2
answers
2k
views
VueJS with Large Forms
I have a huge form with 20+ fields. i feel so much redundancy on the code i write now. What is the best way ?
<script>
new Vue({
data : {
user : {
first_name : "",
...
4
votes
1
answer
3k
views
How can I use Laravel form model binding with bootstrap?
I am trying to display a bootstrap formatted form bound to my User model. However, the form-model binding seems to only work out when I use input fields that are not formatted with bootstrap styles.
...
4
votes
2
answers
7k
views
Django Form ChoiceField with Queryset
I need to get the other users of the firm within the ModelForm to set the main user, I do not know how to get variables inside the form for this?
In the view the variable needed would be:
request....
4
votes
1
answer
3k
views
How to automatically fill in the form with data from other models in Rails
I'm new to Rails. I'm trying to make an app where students can log in and signup for the exam. I have the following models and controllers which are related to that:
The subject has the following ...
4
votes
3
answers
2k
views
What's the best approach for data validation between forms and models on Laravel 5?
I'm used to have model and form validation together, in another framework. But I'm migrating to Laravel and trying to understand its mindset.
What's the best approach for data validation? I've seen ...
4
votes
3
answers
1k
views
nested image model objects not showing on edit action
I've been ignoring this problem for a while but I can't any longer. My nested image model objects, product_images are not showing when I render a product's edit view. Due to this my application calls ...
4
votes
2
answers
4k
views
Null fields after form submit in Spring
I've got a Product with a Rating rating attribute. I've got a product update form (updateStart method) which doesn't contain the rating field (since I don't want it to be editable).
The problem is ...