inline-formset

Initial Data for Django Inline Formsets

十年热恋 提交于 2019-12-09 16:08:19
问题 I have put together a form to save a recipe. It makes use of a form and an inline formset. I have users with text files containing recipes and they would like to cut and paste the data to make entry easier. I have worked out how to populate the form portion after processing the raw text input but I cannot figure out how to populate the inline formset. It seems like the solution is almost spelled out here: http://code.djangoproject.com/ticket/12213 but I can't quite put the pieces together. My

Django : Inline editing of related model using inlineformset

坚强是说给别人听的谎言 提交于 2019-12-06 16:49:00
I'm still stuck with the inline Tree-like-eiditing of related models on same page. I've got three models, A, B and C. Class A Class B fb = foreignkey(A) Class C fc = foreignkey(B) In admin.py I'm doing something like AdminA inlines = [inlineB] AdminB inlines = [inlineC] I want that when I edit/add model A, I should be able to add ModelB inline, and add Model B's related Model C entries. I was trying out inlineformsets, but can't find out how to use them for my purpose. Moreover, I found this old discussion on same problem . But again, since I'm new to Django, I don't know how to make it work.

Change queryset of model field in inlineformset of non parent model

让人想犯罪 __ 提交于 2019-12-06 12:51:38
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 I enter the view code, I need to alter the queryset of the 'other_model' field in the BarForm for all

Django Inline for ManyToMany generate duplicate queries

醉酒当歌 提交于 2019-12-06 08:44:25
问题 I'm experiencing some major performing issue with my django admin. Lots of duplicate queries based on how many inlines that I have. models.py class Setting(models.Model): name = models.CharField(max_length=50, unique=True) class Meta: ordering = ('name',) def __str__(self): return self.name class DisplayedGroup(models.Model): name = models.CharField(max_length=30, unique=True) position = models.PositiveSmallIntegerField(default=100) class Meta: ordering = ('priority',) def __str__(self):

Nested and Segmented Crispy Layouts

末鹿安然 提交于 2019-12-06 06:59:06
TLDR Question: How do you make one crispy form with a ¿segmented?(not sure if this is considered inline) layout with multiple models(some related, some not). I am trying to understand several things in Django: forms, formsets, nested forms, and crispy, and I've been at it for a while, and feel I am close, just need someone to help connect the dots. I'm not sure how to accomplish it without crispy, so I started down this path thinking crispy was the solution. Please correct if I am wrong, thanks :) I would like one form (as in HTML form, not necessarily Django Form), that has a primary model

Django BaseGenericInlineFormSet forms not inheriting FormSet instance as form instance related_object

拥有回忆 提交于 2019-12-05 20:23:56
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 class Product(models.Model): ... images = GenericRelation('Image') This is my (simplified) view: from

Django: How to change a field widget in a Inline Formset

两盒软妹~` 提交于 2019-12-05 14:56:45
问题 I am new to Django and I think I am missing this in the docs. The problem is that in inline-formset I dont declare a form, just pass two models to construct it. I want to know how can I change a widget of a single field using inline formset? 回答1: As of Django 1.6, you can use the widgets parameter of modelformset_factory in order to customize the widget of a particular field: AuthorFormSet = modelformset_factory(Author, widgets={ 'name': Textarea(attrs={'cols': 80, 'rows': 20}) }) and

Testing InlineFormset clean methods

我的梦境 提交于 2019-12-05 05:48:55
I have a Django project, with 2 models, a Structure and Bracket , the Bracket has a ForeignKey to a Structure (i.e. one-to-many, one Structure has many Brackets). I created a TabularInline for the admin site, so that there would be a table of Brackets on the Structure. I added a custom formset with some a custom clean method to do some extra validation, you can't have a Bracket that conflicts with another Bracket on the same Structure etc. The admin looks like this: class BracketInline(admin.TabularInline): model = Bracket formset = BracketInlineFormset class StructureAdmin(admin.ModelAdmin):

Django inlineformset - custom save method

放肆的年华 提交于 2019-12-05 02:58:08
问题 This is my models.py class Invoices(models.Model): ... sum_w_vat = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_wo_vat = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_discount = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_vat = models.DecimalField(max_digits=7, decimal_places=2, default=0) sum_paid = models.DecimalField(max_digits=7, decimal_places=2, default=0) ... class InvoiceItems(models.Model): invoice = models.ForeignKey

Enable Django admin functionality at frontend with inlines

和自甴很熟 提交于 2019-12-05 02:52:09
I have decided to move some functionality from my admin website into the frontend. Functionality includes the administration of one model with some foreign key inlines. For that I have installed django-dynamic-formset JQuery plugin (link git ) and struggling with it already for couple of days. Here is one of the problems . The same functionality is already implemented in Django admin. I can add, modify, remove inlines and modify model instance as I want. I am wondering why should I use this JQuery plugin and why there are not so many good tutorials on the topic in the Internet? I need a good