Answer the question
In order to leave comments, you need to log in
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', )
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question