A
A
Alexander2018-04-28 12:55:27
Django
Alexander, 2018-04-28 12:55:27

Is it possible to fill each select with its own value in inlineformset?

Good afternoon, I do not know how to formulate the question correctly. Here I am displaying the form using inline formset

CategoryPriceFormSet = inlineformset_factory(
    Performer,
    CategoryPrice,
    fields=('name', 'price'),
    fk_name='performer',
    extra=CATEGORY_COUNT,
    max_num=CATEGORY_COUNT
)

# Модель
class CategoryPrice(models.Model):
    performer = models.ForeignKey(
        Performer,
        on_delete=models.CASCADE,
    )
    name = models.ForeignKey(Category, on_delete=models.CASCADE, null=True)
    price = models.CharField(max_length=64, blank=True, null=True)

Now it turned out that the template displays 3 forms, and these are name and price. The name field is rendered as a select with no value selected. There are 3 categories in the database. The question is whether it is possible using django to make sure that each select is filled with its own category, like this https://jsfiddle.net/zowqvcu5/

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