Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- urls.py
- urlpatterns = [
- path('author/<str:username>', AuthorPostIndexView.as_view(),
- name='author_post_index'),
- ]
- models.py
- class Person(models.Model):
- username = models.CharField(max_length = 50, null=True, unique = True)
- post = models.ManyToManyField(Post,blank=True,null=True,
- related_name='authors')
- class Post(models.Model):
- title = models.CharField(max_length=255, blank=True, null=True)
- views.py
- # - commented out as non of these worked. Some of them I have broken
- playing around with desperation to fix so they are with lack logic,
- sketches. Tried those one by one.
- class AuthorPostIndexView(ListView):
- model = Person
- template_name ='authorpostindex.html'
- # def get_queryset(self):
- # username = self.kwargs['username']
- # authorpost = username.post.all()
- # return username
- # def get_queryset(self):
- # if self.request.method == 'GET':
- # queryset = Person.objects.all()
- # url_username = self.kwargs('username', None)
- # if url_username is not None:
- # queryset =
- queryset.filter(person__username=url_username).post.all()
- # else:
- # queryset = "No queryset"
- # def get(self, request, *args, **kwargs):
- # author = Person.objects.get(username=username)
- # authorpost = author.post.all()
- # return authorpost
- authorpostindex.html
- # Tried different solution depending from queryset, none worked.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement