modelform

Django template does not output multiple forms and save to modelform

妖精的绣舞 提交于 2019-12-11 02:34:56
问题 the issue is that template does not output multiple forms and save to Assumptions modelform. I am trying to save input from multiple forms by adding different names from template to Assumptions.Name field in Assumptions model. However, this approach does not work for some reason. Advise how to solve it would be highly appreciated. Thank you in advance. views.py from django.shortcuts import render from .forms import modelformset_factory, AssumptionsForm from .models import Assumptions def get

Django one form / two models

北城以北 提交于 2019-12-11 02:13:32
问题 I have a very simple model for tracking events: class Event(models.Model): description = models.TextField() location = models.ForeignKey(Location) start = models.TimeField() duration = models.IntegerField() event_date = models.DateField() creator = models.ForeignKey(User) and I opted to extract the location in a separate table in order to be able to perform queries: class Location(models.Model): city = models.CharField(max_length=20) address = models.CharField(max_length=30). What would be

get_model equivalent for ModelForms?

落花浮王杯 提交于 2019-12-10 21:45:35
问题 I have a multiple ModelForm classes that each represent a different Model. I would like to have a generic 'create' function that loads the specified model form based on a URL parameter. It is possible to load a model dynamically with this: model_name = 'TestModel' m = get_model('AppLabel', model_name) Does anyone know how I can achieve the same for ModelForms, something like: modelform_name = 'TestModelForm' f = get_form('AppLabel', modelform_name) if f.is_valid(): ... I can not think of a

ModelForm class Contact has no attribute '_meta'

自古美人都是妖i 提交于 2019-12-10 18:36:11
问题 When I inherit ModelForm in my ContactForm I get this error, when I had it so modelform did not inherit from modelform no errors just no form on the html page. I really can't figure this one out AttributeError at /addacontact class Contact has no attribute '_meta' Environment: Request Method: GET Request URL: http://127.0.0.1:8000/addacontact Django Version: 1.4.2 Python Version: 2.7.3 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions',

After extending the User model in django, how do you create a ModelForm?

爷,独闯天下 提交于 2019-12-10 16:00:00
问题 I extended the User model in django to include several other variables, such as location, and employer. Now I'm trying to create a form that has the following fields: First name (from User) Last name (from User) Location (from UserProfile, which extends User via a foreign key) Employer (also from UserProfile) I have created a modelform: from django.forms import ModelForm from django.contrib import auth from alert.userHandling.models import UserProfile class ProfileForm(ModelForm): class Meta:

Removing a fields from a dynamic ModelForm

牧云@^-^@ 提交于 2019-12-10 14:10:39
问题 In a ModelForm, i have to test user permissions to let them filling the right fields : It is defined like this: class TitleForm(ModelForm): def __init__(self, user, *args, **kwargs): super(TitleForm,self).__init__(*args, **kwargs) choices = ['','----------------'] # company if user.has_perm("myapp.perm_company"): self.fields['company'] = forms.ModelChoiceField(widget=forms.HiddenInput(), queryset=Company.objects.all(), required=False) choices.append(1,'Company') # association if user.has_perm

Django, adding excluded properties to the submitted modelform

流过昼夜 提交于 2019-12-09 04:42:32
问题 I've a modelform and I excluded two fields, the create_date and the created_by fields. Now I get the "Not Null" error when using the save() method because the created_by is empty. I've tried to add the user id to the form before the save() method like this: form.cleaned_data['created_by'] = 1 and form.cleaned_data['created_by_id'] = 1 . But none of this works. Can someone explain to me how I can 'add' additional stuff to the submitted modelform so that it will save? class Location(models

Django Form With Foreign Key

会有一股神秘感。 提交于 2019-12-08 11:26:50
问题 I've made a model with foreign keys in order to save some typing, and I think it also looks cleaner this way: class Model_Sub( models.Model ): some_fields class Model_Main( models.Model ): field_1 = models.ForeignKey( Model_Sub, related_name="sub_field_1" ) field_2 = models.ForeignKey( Model_Sub, related_name="sub_field_2" ) But when I want my users to submit the form, I want new instances of the sub model, not from a query set. I want the Model_Sub to be seamlessly included with the main

Zend Framework 2 - Doctrine 2 Model Forms

六眼飞鱼酱① 提交于 2019-12-08 11:19:49
问题 Is there a way to autocreate forms based on the models I defined within Doctrine? In Django its a basic feature. I found some old sources where someone had tried to implement it by himself... but nothing up-to-date or official-looking These model forms save loads of time. I do ask myself why people don't complain about this (possibly) missing feature... 回答1: Zend 2 cannot create a form from the Entity itself. Doctrine 2 is not even part of the framework or tied to it as close as to Symfony 2.

Django modelformset_factory deleting objects marked by can_delete

扶醉桌前 提交于 2019-12-08 04:05:22
问题 Hello I have got question I have made modelformset_factory and in options I have choosen can_delete = True and now I don't know how to delete marked objects as 'DELETE' : True to delete them from database. I was trying to do this in some ways and it didnt work. I was looking for it also in django formsetmodels documentation but this didnt help me. With this option can_delete = True I get additional checkbox in my html page Delete and marking him only prints me in console on print: {'username'