formsets

creating a django form in formset dynamically like inline forms in django admin with jquery

半腔热情 提交于 2020-01-05 05:46:29
问题 I have a two models Publisher and Book like below models.py class Publisher(models.Model): name = models.CharField(max_length=255) class Book(models.model): name = models.CharField(max_length=255) price = models.DecimalField() generic = generic.GenericForeignKey() publisher_id = models.PositiveIntegerField() forms.py class PublisherForm(ModelForm): model = Publisher class BookForm(ModelForm): model = Book exclude = ('generic', 'publisher_id',) def __init__(self, *args, **kwargs): super

inline formset factory update view

删除回忆录丶 提交于 2019-12-24 06:03:07
问题 i want to get in inline formset factory in update view extra=0 , if it have more than 1 contact. So this is my code forms.py class ShopForm(ModelForm): class Meta: model = Shop exclude = ['user', 'slug', 'counter'] def __init__(self, *args, **kwargs): super(ShopForm, self).__init__(*args, **kwargs) for field in iter(self.fields): self.fields[field].widget.attrs.update({ 'class': 'form-control' }) def clean_logo(self): logo = self.cleaned_data['logo'] if not logo: raise forms.ValidationError(

inline formset factory update view

試著忘記壹切 提交于 2019-12-24 06:02:19
问题 i want to get in inline formset factory in update view extra=0 , if it have more than 1 contact. So this is my code forms.py class ShopForm(ModelForm): class Meta: model = Shop exclude = ['user', 'slug', 'counter'] def __init__(self, *args, **kwargs): super(ShopForm, self).__init__(*args, **kwargs) for field in iter(self.fields): self.fields[field].widget.attrs.update({ 'class': 'form-control' }) def clean_logo(self): logo = self.cleaned_data['logo'] if not logo: raise forms.ValidationError(

django multiple forms with formsets

心已入冬 提交于 2019-12-19 04:55:45
问题 I have a model: class HospitalDoctor(models.Model): hospital = models.ForeignKey(Hospital) full_name = models.CharField(max_length=100, unique=True) expertization = models.CharField(max_length=50) nmc_no = models.CharField(max_length=20) timings = models.ManyToManyField('Timing', related_name='shift_timing') appointment = models.IntegerField(default=0) def __unicode__(self): return self.full_name class Timing(models.Model): hospital = models.ForeignKey(Hospital) doctor = models.ForeignKey

dynamically added row to inline formset not reflected in the post request in views.py in django

回眸只為那壹抹淺笑 提交于 2019-12-13 05:47:10
问题 I'm trying to add dynamic forms to my inline formset using the steps mentioned in the post: Add a dynamic form to a django formset using javascript in a right way I have inline formsets which i'm rendering using crispy forms. rendering code in template: <div> {{ formset.management_form|crispy }} </div> <div id="items-form-container"> {% for form in formset.forms %} <div id="item-{{ forloop.counter0 }}"> {% crispy form formset.crispy_helper %} </div> {% endfor %} </div> empty form template is

Django error / value too long for type character varying(1)

淺唱寂寞╮ 提交于 2019-12-12 04:16:47
问题 I'm trying to add new formset field to my model/forms, but when i want save it, i gets an error " value too long for type character varying(1)". Can anyone help me with that? I'm begginer at django. This error is start's show up when i add "study_1" field in views. if university and field: new_obj.append(UserLink(user=user, university=university, city_1=city_1, grade=grade, field=field, description_1 = description_1, study_1 = study_1)) Here's my code: views.py: @login_required def profile

pre-populating partial Initial data in a Django formset

ⅰ亾dé卋堺 提交于 2019-12-12 03:54:26
问题 I’m having difficulty implementing initial data in my django formset. For context, I’m building an attendance app where a list of students exist and need to be assessed for attendance every day. What I’m trying to do is have an administrator click on a link which has a date listed on it. They will then be taken to data grid where each row represents the number of students in the system along with 4 columns (student name, date, present/absent drop down, a notes field). The goal is to have the

Django 'ManagementForm data is missing or has been tampered with' when saving modelForms with foreign key link

醉酒当歌 提交于 2019-12-06 19:47:26
问题 I am rather new to Django so this may be an easy question. I have 2 modelForms where there is a ForeignKey to another. My main goal is to save Indicators with a link to Disease (FK), such that for a particular disease, you can have multiple indicators. With the code below, I get an error when I hit submit that says 'ManagementForm data is missing or has been tampered with'. Also, the code in views.py does not seem to be validating at the 3rd 'if' statement where there is a return

Trying to pass a QuerySet as initial data to a formset

会有一股神秘感。 提交于 2019-12-03 16:21:23
问题 I'm trying to build a page for an inventory system that will allow a user to update a quantity of items received. I want to show a table of all products and let the user enter the quantity received, which I'll post and iterate over to update the database. Here is my view: def new_shipment(request): list_of_active_products = Product.objects.filter(status=1) ShipmentFormSet = formset_factory(ShipmentForm, extra=0) formset = ShipmentFormSet(initial=list_of_active_products) return render_to

django multiple forms with formsets

喜你入骨 提交于 2019-12-01 01:55:57
I have a model: class HospitalDoctor(models.Model): hospital = models.ForeignKey(Hospital) full_name = models.CharField(max_length=100, unique=True) expertization = models.CharField(max_length=50) nmc_no = models.CharField(max_length=20) timings = models.ManyToManyField('Timing', related_name='shift_timing') appointment = models.IntegerField(default=0) def __unicode__(self): return self.full_name class Timing(models.Model): hospital = models.ForeignKey(Hospital) doctor = models.ForeignKey(HospitalDoctor) day = models.CharField(max_length=20) mng_start = models.IntegerField() mng_end = models