ListView making queryset based on parameter

ListView making queryset based on parameter

Content Index :

ListView making queryset based on parameter
Tag : django , By : Matt Croydon
Date : January 12 2021, 08:33 AM

I wish this help you it's difficult to say which one is better but both approaches work. Anyway at the end i finally found a better approach - is to use django-filters, which is done for filtering based on criteria.

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

django filter queryset based on count of another queryset

Tag : python , By : Boris
Date : March 29 2020, 07:55 AM
will be helpful for those in need First, you can query list of book which has review, and then get compliment by using django exclude
bookname_has_review = Review.objects.all().distinct().values_list('bookname', flat=True)
book_not_have_review = Book.objects.all().exclude(name__in=bookname_has_review)

How to create Prefetch queryset based on parent queryset in django

Tag : django , By : Michael Gunderson
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Here is the scenario, a project model which contains multiple bids.
Project.objects.filter(whatever condition).prefetch_related(
     Prefetch('bids', queryset=Bid.objects.all())
Project.objects.filter(whatever condition).prefetch_related('bids')
Project.objects.filter(whatever condition).prefetch_related(
     Prefetch('winning_bids', queryset=Bid.objects.filter(status='WINNING'))

How to display a template based on a queryset done in a class based view where one of the argument for queryset comes fr

Tag : django , By : ikey
Date : March 29 2020, 07:55 AM
around this issue Your view should be based on Post. Then you can use all the existing logic of the view but additionally filter by the author username.
class AuthorPostIndexView(ListView):
    model = Post
    template_name ='authorpostindex.html'

    def get_queryset(self):
       queryset = super().get_queryset()
       username = self.kwargs['username']
       return queryset.filter(authors__username=username)

Filter the queryset based on the domain making the request

Tag : django , By : Cosmin
Date : March 29 2020, 07:55 AM
Any of those help The qet_queryset [drf-doc] is supposed to, like the name suggests, return a QuerySet, not the response of that queryset. You should simply return:
class ListProperties(generics.ListAPIView):
    queryset = models.Property.objects.all()
    serializer_class = frontend.PropertyCard
    filter_class = filters.PropertyFilterset
    pagination_class = pagination.PropertyPageNumberPagination

    def get_queryset(self):
        domain = self.request.META['HTTP_DOMAIN']
        return self.queryset.filter(company__domain=domain)
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)

ListView is missing a QuerySet. Define ListView.model, ListView.queryset, or override ListView.get_queryset()

Tag : python , By : Mossy Breen
Date : March 29 2020, 07:55 AM
Any of those help There is an error in your urls.py, you did not refer to the SchoolListView, but to the generic ListView itself. You can fix this by writing:
# app/urls.py

from django.urls import path
from . import views

#My name space
app_name = 'basicapp'

urlpatterns = [
    # SchoolListView instead of ListView
    path('', views.SchoolListListView.as_view(), name='list'),
    # probably SchoolDetailView instead of DetailView, and with a pk in the url
    path('details', views.DetailView.as_view(), name='details')
Related Posts Related QUESTIONS :
  • django - dynamic form fieldsets
  • How to unit test Django-CMS extensions?
  • Optimising API queries using JSONField()
  • Displaying foreign key with DRF create api
  • QuerySet Optimisations in Django
  • Setting up media file access on AWS S3
  • Download link from ForeignKey model
  • Data not showing on template
  • Django 2.2 set ModelChoiceField initial value without id/pk
  • Django REST Framework Deep Dive - Where is it determined that an enpoint needs an auth token
  • Keeping items per page static while paginating
  • Need help on nested Django Rest Framework
  • Wagtail RichTextField not showing in Django ModelForm
  • Date Validation --> end date must be greater than start date
  • Nginx, SPA & Sphinx Doco Authentication
  • Django reverse 'str' object has no attribute 'get'
  • Unknown interpreted text role "setting" with Django docstring and Sphinx
  • Django CONN_MAX_AGE is set to 0 but connection remains open after executing query
  • Error message 'mkvirtualenv is not recognized as an internal or external command'
  • How to use PythonAnywhere SFTP to store uploaded files to get past file size limitations in Django Filer?
  • Django REST Framework: Why Adding IsAuthenticated Permissions Only Threw 500 Internal Error Instead of 401 / 403 Errors?
  • Django Admin: Restrict staff to update
  • Django 2.2 Time and Date Localization Specifics
  • FOREIGN KEY constraint failed because of models.DO_NOTHING
  • How To Remove Row in django-extra-views?
  • django select_related('created_by').... what is the context variables?
  • Django Admin - Upload multiple images to multiple model objects in a single upload
  • Wagtail PASSWORD_REQUIRED_TEMPLATE is not overriding the default login
  • get checkbox items list from table in django without using django-forms
  • Django Running Particular Test
  • How do I display output of a python within Html in django?
  • How can I capture errors and exceptions data from frontend response to django to add more context
  • Django generate group by different than id
  • populate table with initial data
  • Django (admin.e104) must inherit from 'InlineModelAdmin'
  • how to display a html file stored in s3 in aws in my django template?
  • Django: AttributeError: type object 'GroupModel' has no attribute '_meta'
  • SQLite objects created in a thread can only be used in that same thread with Django 2.2.2 and ipdb
  • Django - query filter on manytomany is exists
  • Django REST Framework: URLs without PK
  • How to access a Postgres database from a python program without django or heroku
  • When trying set corsheaders in settings.py file
  • 400(Bad request) status code when making request with axios in reactjs
  • ERR_CONNECTION_REFUSED with Django and Vue.js bundle files
  • LDAP Authentication not working in Graphite
  • send value from anchor tag to views
  • The views didn't return an HttpResponse object. It returned None instead
  • Sum of related objects across 2 FK to the same table, with conditions
  • Queryset Django - according to parameters date in weight compartment
  • how to convert Django 2.0 url() to path()
  • Signal/Method for every executed sql statement
  • How to sum django model fields
  • django template styntex {% if p.category == "help" %} {% endif %} is not work
  • NGINX 502 bad gateway gunicorn timeout
  • How to pass a variable from a template to a view in Django
  • How to force redirect_uri to use HTTPS with python-social-app?
  • How to restrict Django models from using certain foreign key values?
  • Product items is not iterable from models
  • Removing items from celery_beat doesn't remove them from database schedule
  • Column field is not recognized/not defined
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com