def member_add(request, slug): form = SocietyMemberForm if request.method == 'POST': form = SocietyMemberForm(request.POST, request.FILES) if form.is_valid(): mem = form.save() mem.society = Society.objects.get(slug=slug) mem.save() return HttpResponseRedirect(reverse('societymembers:member_index', args=[slug])) context = {'form': form, 'slug': slug} return render(request, 'societymembers/new.html', context)
def member_edit(request, slug, member_id): member = get_object_or_404(SocietyMember, id=member_id) # Superusers or society admins can delete society members. if request.user.is_superuser or request.user.society_set.filter(slug=slug).exists(): form = SocietyMemberForm(request.POST or none, instance=instance) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('societymembers:member_index', args=[slug])) else: return HttpResponseRedirect(reverse('societymembers:member_denied')) object = SocietyMemberForm(data=model_to_dict(member)) return render(request, 'societymembers/detail.html', {'object':object, 'member_id' : member_id})