Snippets

Andrew Authors

Created by Andrew last modified
dg  = Post.objects.order_by().values('authors').distinct()
>>> for authors in dg:
...     print(authors)
{'authors': 'James%20Patterson'}
{'authors': 'J%20D%20Robb'}
{'authors': 'David%20Baldacci'}
{'authors': 'Nora%20Roberts'}
{'authors': 'Janet%20Evanovich'}


So this is not correct at all yet but you might get the idea im going for... 

following this video:
https://www.youtube.com/watch?v=2gmS4LAHTOM
views.py

@login_required
def list_authors
  authorsname=Post.objects.all()
  cname = request. Post.get('dropdown1')
  if request.method == 'GET':
    form = AuthorForm()
  else:
    authors = Post.objects.get(cname = cname)
    # author.delete() ''' Use case in video was delete, i dont want that '''
    return redirect('/users/account/')
  return render(request, 'worklist.html', {'form': form, 'authorsname': authorsname})



  <form action="{& url 'worklist' %}" method="POST" >{% csrf_token %}
  <table>
  <tr><td>Author Name :</td>
    <td>
      <select name='dropdown1'>
        {% for author  in authornames %}
          <option value="{{ author.cname }}">{{ author.cname }}</option>
        {% endfor %}
    </td>
  <td><input type="submit" value="Select Author" /></td></tr>
  </table>

  urls.py
  url(r'^catagory/del/$','book.views.del_catagory', name='delcatagory'),

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.