On Wed, Nov 8, 2017 at 1:38 PM Jack <[email protected]> wrote: > On my HTML page, I have a list of Agent's (Agent is my custom User > model). Beside each agent is a 'Send Invite' button. To create a > `TeamInvitation`, I need to specify which Agent is attached to its > `receiver_agent` field (a OneToOneField with Agent) > > There are multiple Agents displayed on the HTML page, and they are listed > in order with template tags. I need to input something after `pk` at > `receiver_agent = Agent.objects.get(pk = ???)`, but I don't know what to > input. > > *views.py* > > class InviteAgentSearchResults(ListView): > model = Agent > form_class = AgentSearchForm > template_name = 'invite_agent_search_results.html' > > def get_queryset(self): > # ... Code to find correct list of agents > > def post(self, request, *args, **kwargs): > invite = TeamInvitation.objects.create(receiver_agent = > Agent.objects.get(pk = ???)) > return HttpResponse('Invite successfully sent.') > > *HTML:* > > {% for agent in agent_list %} > <div class="agent"> > # ... Some code here > > <form method="post"> # The "Send Invite" button > {% csrf_token %} > <button class="button1"><span>Send Invite</span></button> > </form> > </div> > {% endfor %} > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/bd0439e2-7fdd-4f7c-b6ce-4847d4a877c8%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/bd0439e2-7fdd-4f7c-b6ce-4847d4a877c8%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > It seems to me that the quickest thing would be to make each agent a separate form.
Alternatively, you could set up some JavaScript: Add the agent.id to a hidden input, separated by commas, and have that hidden field submitted via the form Then on the backend separate out each ID and have the invites sent one by one. I would be happy to write some code if you wish. -- -- Adam F. Simon, PhD Calabasas, CA. cell: 818-425-3719 home: 818-880-8405 Feel free to link w/ me: LinkedIn -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-jdcwcBY1weuVrgT%2Bcrq_B4iqTECBznUDB%2BMHjDYc84fM%3DXA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

