M
M
mr_drinkens892014-08-11 20:07:26
Django
mr_drinkens89, 2014-08-11 20:07:26

How to set initial values ​​in django inlines?

Prompt on a question.
there is a model:

class ProductTechInfo(models.Model):
    """техническая информация для продуктов
    """
    product = models.ForeignKey(Product, verbose_name=_(u"товар"), related_name="techinfo")
    name = models.ForeignKey(TechInfo, verbose_name=_(u"имя"), related_name="name")
    value = models.TextField(_(u'значение'), blank=True)

Next, in the admin panel, I create a form based on this model:
class TechInfoForm(forms.ModelForm):
    class Meta:
        model = ProductTechInfo
        fields = ("name", "value", )
        widgets = {
            'value': Textarea(attrs={'rows': 2}),
        }

Well, I output everything as Inline:
class ProductTechInfoInline(admin.TabularInline):
    model = ProductTechInfo
    form = TechInfoForm
    extra = 2

How do I populate properties with initial values ​​in a form?
i.e. how do I do it like this:
'property1': text field
'property2': text field
'property3': text field
'property1-3' is substituted when loading initial values ​​from the list.
Let's say list_attr = ['property1','property2','property3'].
and in a loop we insert each property.
thank.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question