H
H
huko2015-09-13 18:08:36
Django
huko, 2015-09-13 18:08:36

How to display the filled formset of all data from the table at once?

There is a table with 10 entries, how to display the completed formset of all this data with the possibility of editing it? More precisely, I do not need to display all the data, but on a certain basis, but not the essence.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanOne, 2015-09-14
@huko

I think the documentation https://docs.djangoproject.com/en/1.8/ref/forms/models/
about filtering data in forsets will help you understand the formsets, examples - stackoverflow.com/questions/9711313/django-how-to- ... , stackoverflow.com/questions/2581049/filter-queryse...
well, if you are completely depressed, then an example:
form:

class DatesOperationForm(forms.ModelForm):
    class Meta:
        model = OperationDate

DateFormSet = inlineformset_factory(Operation, OperationDate, extra=1, can_delete=False, form=DatesOperationForm)

view:
class OperationDetail(UpdateView):
    form_class = OperationForm
    

    def get_context_data(self, **kwargs):
        context = super(OperationDetail, self).get_context_data(**kwargs)
        context['form_dates'] = DateFormSet(instance=self.object)
        return context

models:
class Operation(models.Model):
    name = models.CharField(u"Название", max_length=255)
    sum = models.DecimalField(u"Сумма", max_digits=10, decimal_places=2)
    category = models.ForeignKey(CategoryOperation, verbose_name=u"Категория", null=True, blank=True,
                                 related_name='operations')
   ...
class OperationDate(models.Model):
    operation = models.ForeignKey(Operation, verbose_name=u"Опреация")
    ....

In fact, you pass instance Operation to the formset, everything else will be done by Dzhang itself. Well, if necessary, conjure with queryset.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question