Skip to content

Instantly share code, notes, and snippets.

@csarcom
Last active December 16, 2015 00:49
Show Gist options
  • Save csarcom/5350014 to your computer and use it in GitHub Desktop.
Save csarcom/5350014 to your computer and use it in GitHub Desktop.
#forms.py
class ContactsEscalationForm(forms.ModelForm):
class Meta:
Model = ContactsEscalation
exclude = ('dt_cancel',)
#models.py
class ContactsEscalation(LogicalExclusionModel):
name = models.CharField(max_length=45)
email = models.CharField(max_length=75)
phone = models.CharField(max_length=21, blank=True)
role = models.CharField(max_length=50)
is_fulltime_support = models.BooleanField(default=False)
account = models.ForeignKey('Accounts', null=True, blank=True)
#views.py
@login_required(login_url='/login')
def contacts_escalation(request):
account = Accounts.objects.get(contacts__user__email = request.user.email)
ContactsEscalationInlineFormSet = inlineformset_factory(Accounts, ContactsEscalation, form = ContactsEscalationForm,
extra=3)
if request.method == "POST":
formset = ContactsEscalationInlineFormSet(request.POST)
if formset.is_valid():
formset.save()
# Do something. Should generally end with a redirect. For example:
return HttpResponseRedirect(Http404)
else:
formset = ContactsEscalationInlineFormSet
return render_to_response("controlpanel/edit/contact_escalation.html", {"formset": formset,})
#template.html
{% extends "controlpanel/index/base_index.html" %}
{% load i18n %}
{% block table %}
<form method="post" action="">
{{ formset.management_form }}
<table>
{% for form in formset %}
{{ form }}
{% endfor %}
</table>
</form>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment