django-forms

Django Model Inheritance versus OneToOne field

Deadly 提交于 2019-12-24 13:33:44
问题 EDIT: Advantages and disadvantages of both methods. SO, I have three models: Person, Client, Member Person is a base model, Client and Member are profiles for Person. class Person(AbstractBaseUser, PermissionsMixin): email = models.EmailField( verbose_name=_('email address'), max_length=255, unique=True, ) class Client(User): #or maybe models.Model and explicit OneToField first_name = models.CharField(verbose_name=_('first name'), max_length=30) last_name = models.CharField(verbose_name=_(

Django: using 'can_order' to change order of forms in FormSet

余生长醉 提交于 2019-12-24 12:35:19
问题 I have a form with one field that keeps only the name of family members. I want user be able to change the order as the user wishes. The current order is the order of their creation. I found the flag can_order for my formset; when I add it to my formset, another field appeared besides the names and that field is an integer showing the number in the list. class FamilyMemebrsNameForm(forms.Form): name= forms.CharField(label=_('name'), max_length=250) FamilyMemberNameItem = formset_factory(

save method in a view

江枫思渺然 提交于 2019-12-24 12:27:19
问题 I have a very simple model: class Artist(models.Model): name = models.CharField(max_length=64, unique=False) band = models.CharField(max_length=64, unique=False) instrument = models.CharField(max_length=64, unique=False) def __unicode__ (self): return self.name that I'm using as a model form: from django.forms import ModelForm from artistmod.artistcat.models import * class ArtistForm(ModelForm): class Meta: model = Artist but I can't seem to construct a view that will save the form data to

django : set default value for formset_factory form element

拈花ヽ惹草 提交于 2019-12-24 12:20:55
问题 Model: class AssociatedFileCourse(models.Model) file_original = models.FileField(upload_to = 'assets/associated_files') session = models.ForeignKey(Session) title = models.CharField(max_length=500) Form: class AddAssociatedFilesForm(ModelForm): class Meta: model = AssociatedFileCourse If I had to create a single form from above defination and set some initial value, It could have done using initial parameter like form = AddAssociatedFilesForm(initial={'session': Session.objects.get(pk=id)})

Copy Selected Checkbox Value From One Checkbox To Another Immediately Using JQUERY

本秂侑毒 提交于 2019-12-24 12:12:56
问题 I'm relatively new to Jquery and have been struggling with this problem for the last day or so. I am trying to do something seemingly simple, but I can't quite work it out. I have two identical checkboxes with many entries and multiple choices can be selected by the end user in either checkbox. If a value in checkboxa is selected, I want it to immediately select the identical value in the checkboxb. I have researched many solutions, and I have tried the following: $(document).ready(function (

How do you load a custom field in django

折月煮酒 提交于 2019-12-24 11:54:14
问题 note : This is closely related to the answer in this question : django admin - add custom form fields that are not part of the model In Django it is possible to create custom ModelForms that have "rouge" fields that don't pertain to a specific database field in any model. In the following code example there is a custom field that called 'extra_field'. It appears in the admin page for it's model instance and it can be accessed in the save method but there does not appear to be a 'load' method.

formset is valid but form has no attribute cleaned_data!

一笑奈何 提交于 2019-12-24 11:42:03
问题 Ok, so I have a formset that is valid. But gives me a error that that form has no attribute cleaned_data.. Honestly I have absolutely no clue what's happening.. I tried my code on terminal and it returned a empty dictionary.. without errors.. forms: class Clinical(forms.Form): _names = list(ClinicalForm.objects.values_list('form_id', 'form_name')) _names.append(("New", u'Nova entrada')) cliform_name = forms.ChoiceField(widget=RadioSelect(), choices=_names, label ="", required=True) views:

Django form insert record instead of update record

孤人 提交于 2019-12-24 11:37:26
问题 I am having some issues trying to update some records in Django: When i try to update some record, the app insert a new one, I don't know why i have this behavior. Model class DetalleRecepcion(models.Model): id_proveedor = models.ForeignKey(Proveedor,db_column='id_proveedor',primary_key=True, verbose_name='Proveedor') anio = models.IntegerField( null=False) mes = models.IntegerField(verbose_name='Mes') fecha_recepcion = models.DateField(verbose_name='Fecha Recepcion') usuario = models

Pre-populating Django Forms

耗尽温柔 提交于 2019-12-24 11:35:23
问题 I'm trying to have a Django Form from a query, but I keep doing it the wrong way. Checked out a few examples, but I'm doing it a bit different. Here's my code, Le Form class ItemForm(ModelForm): class Meta: model = Item exclude = ('deleted') And part of the view def index(request): user = User try: last_modified_list = ShoppingList.objects.filter(deleted='0').filter(owner=user).latest('date_modified') items = Item.objects.filter(shopping_list=last_modified_list).filter(deleted='0') except

Using a Django FileField in an inline formset

守給你的承諾、 提交于 2019-12-24 11:17:04
问题 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 made, but the attachment that's getting inlined doesn't get saved. forms.py class ReportForm(forms.ModelForm): accidentDate = forms.DateField(widget=SelectDateWidget( empty_label=("Choose Year",