SHARE
TWEET

Untitled

a guest Jun 15th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. urls.py
  2.  
  3.  
  4. urlpatterns = [
  5. path('author/<str:username>', AuthorPostIndexView.as_view(),
  6. name='author_post_index'),
  7. ]
  8.  
  9.  
  10.  
  11.  
  12. models.py
  13.  
  14. class Person(models.Model):
  15.     username = models.CharField(max_length = 50, null=True, unique = True)
  16.     post = models.ManyToManyField(Post,blank=True,null=True,
  17. related_name='authors')
  18.  
  19. class Post(models.Model):
  20.     title = models.CharField(max_length=255, blank=True, null=True)
  21.  
  22.  
  23.  
  24.  
  25.  
  26. views.py
  27.  
  28. # - commented out as non of these worked. Some of them I have broken
  29.  playing around with desperation to fix so they are with lack logic,
  30.  sketches. Tried those one by one.
  31.  
  32.  
  33. class AuthorPostIndexView(ListView):
  34.     model = Person
  35.     template_name ='authorpostindex.html'
  36.  
  37. #    def get_queryset(self):
  38. #       username = self.kwargs['username']
  39. #       authorpost = username.post.all()
  40. #       return username
  41.  
  42.  
  43. #    def get_queryset(self):
  44. #        if self.request.method == 'GET':
  45. #             queryset = Person.objects.all()          
  46. #             url_username = self.kwargs('username', None)
  47. #             if url_username is not None:
  48. #                 queryset =
  49.  queryset.filter(person__username=url_username).post.all()
  50. #             else:
  51. #                 queryset = "No queryset"
  52.  
  53.  
  54. #    def get(self, request, *args, **kwargs):
  55. #     author = Person.objects.get(username=username)
  56. #     authorpost = author.post.all()
  57. #     return authorpost
  58.  
  59.  
  60.  
  61. authorpostindex.html
  62.  
  63. # Tried different solution depending from queryset, none worked.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top