inline-formset

Why isn't my dynamic formset displaying any fields

北城以北 提交于 2019-12-13 03:38:46
问题 My goal is to define an upload form for cars for users to upload a car with all relevant details, and adding images from the same page. The Admin form works perfectly, and I just want to emulate it in custom page-- a surprisingly difficult task! I'm using this tutorial, with the fields changed to match my project. I'm also using the django-dynamic-formset jQuery plugin to provide additional image fields as needed by the user. I've been stuck on this for a week, and I'm not sure exactly where

Inline formset adding wrong form

穿精又带淫゛_ 提交于 2019-12-13 03:37:11
问题 I have a form and two inline formsets. When I want to add photo_form actually doctors_form is added, but if I swap photo_form fieldset and doctor_form fieldset in html - everything works perfectly! What magic is going on?! forms.py class InstitutionForm(forms.ModelForm): class Meta: model = Institution fields = '__all__' error_css_class = 'error' required_css_class = 'required' def __init__(self, *args, **kwargs): super(InstitutionForm, self).__init__(*args, **kwargs) self.helper = FormHelper

How can I change the queryset of one of the fields in the form I'm passing to inlineformset_factory

最后都变了- 提交于 2019-12-13 02:06:37
问题 I'm using django extra views: # views.py from django.forms.models import inlineformset_factory from extra_views import (CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet, ) class LinkInline(InlineFormSet): model = Link form = LinkForm extra = 1 def get_form(self): return LinkForm({}) def get_formset(self): return inlineformset_factory(self.model, self.get_inline_model(), form=LinkForm, **self.get_factory_kwargs()) class TargetCreateView(BaseSingleClient, CreateWithInlinesView):

Imagefield in Inline formset not populated

旧街凉风 提交于 2019-12-12 04:25:40
问题 I have this piece of code: vehicle = get_object_or_404(Vehicle, stock_number=stock_number) if request.method == 'POST': vehicle_form = VehicleForm(request.POST, instance=vehicle) photos = PhotosFormSet(request.POST, request.FILES, instance=vehicle) if vehicle_form.is_valid() and photos.is_valid(): vehicle = vehicle_form.save() photos.save() request.user.message_set.create(message='The vehicle "%s" was edited successfully.' % vehicle.__str__()) return HttpResponseRedirect("/vehicles/details/%s

Django Inline formset for editing multiple related records at once - the right way to go?

吃可爱长大的小学妹 提交于 2019-12-12 02:58:33
问题 When using inline formsets, how does one do paging? I'm using django 1.1. The situation I'm in, is that the user needs to be able to edit the related objects quickly and easily (which is why I think I should be using an inline formset). However, there can be a more than a hundred objects to edit, which makes a pretty large formset, so paging would make sense. Is there a better way to be doing this? Thanks Bert 回答1: Unfortunately I couldn't get paging to work with formsets. Instead I extended

Django - inlineformset-factory (How to Edit)

痴心易碎 提交于 2019-12-11 04:41:18
问题 I saw many tutorials and questions in many foruns and websites. And when I search for "inline formset-factory" are many links appear. But few talk about how edit, with inline formset-factory. I have a problem in my project, I did it save, but when I will try edit, rise some errors This is my code class Dia_Producao(models.Model): id = models.AutoField(primary_key=True) diaTrabalho = models.CharField("Dia de Trabalho", choices=DIATRABALHO_CHOICES, blank=True, null=False, max_length=10)

Django overriding Save on inline formset

只谈情不闲聊 提交于 2019-12-10 11:49:56
问题 I am now zombified and am waiting for someone to hit me and put me to sleep. I know this is simple and since I am new to django and to python I am doing it wrong. I wanted a model FK field to be rendered as a text field..easy peasy (not the linux OS)....right? I don't think so... well, I got one solution on SO reverse foreign key relationship but alas it did not work for me and I tried and tried and treid...and so on... I place my code here and if anyone for sake of all that is holy or evil

Change queryset of model field in inlineformset of non parent model

为君一笑 提交于 2019-12-10 11:15:22
问题 I am using an inline formset and need to change the queryset of one of the non parent model's form fields when the formset is instantiated. class Foo(Model): name = models.TextField() class Bar(Model): foo = models.ForiegnKey(Foo) other_model = models.ForeignKey(OtherModel) class BarForm(ModelForm): class Meta: model=Bar foo = Foo.object.get(id=1) FormSet = inlineformset_factory(Foo, Bar, form=BarForm) formset = FormSet(instance=foo) Depending on the value of foo which isn't determined until

Django BaseGenericInlineFormSet forms not inheriting FormSet instance as form instance related_object

十年热恋 提交于 2019-12-10 10:21:17
问题 I'm using Django 1.8 and I have an Image class that looks like this: # The `child` class class Image(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() related_object = GenericForeignKey('content_type', 'object_id') image = models.ImageField(...) def clean(self): related_class = self.content_type.model_class() # Do some validation that relies on the related_class And a "parent" class that has a GenericRelation to it: # The `parent` class

Django inline foreign key does not match parent primary key

爷,独闯天下 提交于 2019-12-10 02:58:40
问题 I need some help getting past a django error using inline forms. I can't seem to figure this out. I could probably force-insert the eventID if I could figure out how to do that before it tries to validate. When I submit my form I get an error: Hidden field (event): The inline foreign key did not match the parent instance primary key Is there any way to make this code work? The following code is supposed to let a teacher enrol multiple students for an event. ------ models.py ------------ class