Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ItemInline(InlineFormSet):
- """
- Item inline class
- """
- extra = 1
- model = Item
- form_class = CreateItemForm
- class CreatePacketView(LoginRequiredMixin, CreateWithInlinesView):
- """
- Handles request for '/add/packet/to_c/<cid>'
- """
- model = Packet
- inlines = [ItemInline]
- form_class = CreatePacketForm
- template_name = CREATE_PACKET_TEMPLATE
- def forms_valid(self, form, inlines):
- """
- :param form:
- :return:
- """
- form.instance.created_by = self.request.user
- form.instance.updated_by = self.request.user
- form.instance.customer = self.get_customer_object(self.kwargs['cid'])
- return super(CreatePacketView, self).forms_valid(form, inlines)
- @staticmethod
- def get_customer_object(cid):
- """
- :return:
- """
- return get_object_or_404(Customer, pk=cid)
- <html>
- <head>
- <script type="text/javascript" src="{% static 'girvi/js/jquery-1.3.2.min.js' %}"></script>
- <script type="text/javascript" src="{% static 'girvi/js/jquery.formset.js' %}"></script>
- <script type="text/javascript">
- $(function() {
- $('#item_form').formset({
- prefix: '{{ formset.prefix }}'
- });
- });
- </script>
- </head>
- <body>
- <form id="packet_form" method="post" action="" style="margin: 0 20% 0 20%;padding: 10px;">
- {% csrf_token %}
- {{ form.non_field_errors }}
- {{ form }}
- {% for formset in inlines %}
- <div id="item_form">
- <div id="{{ formset.prefix }}">
- {% for subform in formset.forms %}
- {{ subform.name.errors }}
- <label>{{ subform.name.label }}</label>
- {{ subform.name }}
- <br>
- {{ subform.type.errors }}
- <label>{{ subform.type.label }}</label>
- {{ subform.type }}
- <br>
- {{ subform.weight.errors }}
- <label>{{ subform.weight.label }}</label>
- {{ subform.weight }}
- <br>
- {{ subform.purity_percent.errors }}
- <label>{{ subform.purity_percent.label }}</label>
- {{ subform.purity_percent }}
- <br>
- {{ subform.worth.errors }}
- <label>{{ subform.worth.label }}</label>
- {{ subform.worth }}
- <br>
- {{ subform.money_lent.errors }}
- <label>{{ subform.money_lent.label }}</label>
- {{ subform.money_lent }}
- <br>
- {{ subform.roi_charged.errors }}
- <label>{{ subform.roi_charged.label }}</label>
- {{ subform.roi_charged }}
- <br>
- {{ subform.remark.errors }}
- <label>{{ subform.remark.label }}</label>
- {{ subform.remark }}
- <br>
- {{ formset.management_form }}
- {% endfor %}
- </div>
- </div>
- {% endfor %}
- <div align="middle">
- <button type="submit">Submit</button>
- <button type="reset">Reset</button>
- </div>
- </form>
- </body>
- </html>
- item_set-0-purity_percent : u'22'
- item_set-0-worth : u'3232'
- item_set-0-roi_charged : u'3'
- item_set-NaN-purity_percent : u'32'
- item_set-NaN-type : u'2'
- item_set-NaN-name : u'9'
- item_set-0-name : u'4'
- item_set-0-money_lent : u'323'
- item_set-MAX_NUM_FORMS : u''
- item_set-NaN-remark : u''
- item_set-NaN-worth : u'212'
- item_set-INITIAL_FORMS : u''
- item_set-TOTAL_FORMS : u''
- item_set-NaN-weight : u'232'
- item_set-NaN-roi_charged : u'32'
- item_set-NaN-money_lent : u'21'
- item_set-MIN_NUM_FORMS : u''
- item_set-0-weight : u'323'
- csrfmiddlewaretoken : u'7ac0Q1sFcFbPi3bpsDaibYhpRd2zOHlz'
- item_set-0-remark : u''
- item_set-0-type : u'1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement