B
B
Boldy2015-03-09 12:47:11
Django
Boldy, 2015-03-09 12:47:11

Why aren't auto-generated inline objects created in django?

The code:

class FilterPaymentFormSet(BaseInlineFormSet):

    def __init__(self, *args, **kwargs):
        dates = [date.today(), ]
        second_payment_date = next_nth_day_of_month(the_date=dates[0], n=10, include_today=False)
        dates.append(second_payment_date)
        while len(dates) < 22:
            dates.append(next_nth_day_of_month(the_date=dates[-1], n=10, include_today=False))
        initial_values = list()
        for k in range(20):
            entry = dict()
            entry['payment_date'] = dates[k]
            if not k:
                entry['total'] = 4500
                entry['paid'] = True
            else:
                entry['total'] = 3500
            initial_values.append(entry)
        kwargs['initial'] = initial_values
        super(FilterPaymentFormSet, self).__init__(*args, **kwargs)


class FilterPaymentInline(admin.TabularInline):
    model = FilterPayment

    def get_extra(self, request, obj=None, **kwargs):
        extra = 21
        if obj:
            return 0
        return extra
    formset = FilterPaymentFormSet
    ordering = ('payment_date', )

When I click "create a new object" - 21 inlines are immediately created with the correct data. But when I save the object and go into it again, everything disappears, the inline becomes empty. What's the matter?

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