Hiding the products with quantity 0 from view django rest framework2019 Community Moderator ElectionAttributeError - type object 'Services' has no attribute 'service_price'Saving form data rewrites the same rowShow information of subclass in list_display djangoDjango south migration error with unique field in postgresql databaseRadio buttons in django adminDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerHow to expose some specific fields of model_b based on a field of model_a?django how to hide specific form filed and loop data inputHow to define Mode with generic ForeignKey in DjangoHow to implement update_or_create inside create method of ModelSerializer

Why didn’t Eve recognize the little cockroach as a living organism?

Would it be believable to defy demographics in a story?

How to find the largest number(s) in a list of elements?

Exposing a company lying about themselves in a tightly knit industry: Is my career at risk on the long run?

Someone scrambled my calling sign- who am I?

Does convergence of polynomials imply that of its coefficients?

How much propellant is used up until liftoff?

Unfrosted light bulb

Air travel with refrigerated insulin

TDE Master Key Rotation

Isn't the word "experience" wrongly used in this context?

Are hand made posters acceptable in Academia?

When should a starting writer get his own webpage?

Animating wave motion in water

Single word to change groups

Should a narrator ever describe things based on a characters view instead of fact?

Is xar preinstalled on macOS?

Is there any common country to visit for uk and schengen visa?

What is the difference between something being completely legal and being completely decriminalized?

UK Tourist Visa- Enquiry

How can a new country break out from a developed country without war?

Did Nintendo change its mind about 68000 SNES?

The English Debate

Why is "la Gestapo" feminine?



Hiding the products with quantity 0 from view django rest framework



2019 Community Moderator ElectionAttributeError - type object 'Services' has no attribute 'service_price'Saving form data rewrites the same rowShow information of subclass in list_display djangoDjango south migration error with unique field in postgresql databaseRadio buttons in django adminDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerHow to expose some specific fields of model_b based on a field of model_a?django how to hide specific form filed and loop data inputHow to define Mode with generic ForeignKey in DjangoHow to implement update_or_create inside create method of ModelSerializer










0















How can I hide the products from view with quantity == 0?
This is my models.py



class Product(models.Model):
title = models.CharField(max_length=255, db_index=True)
description = models.TextField()
price = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
quantity = models.PositiveIntegerField()
color = models.CharField(choices=COLOR_CHOICES, default='BLACK', max_length=100)
category = models.ManyToManyField(Category, related_name='products')

class Meta:
ordering = ('-id',)

def __str__(self):
return self.title

@property
def instock(self):
return self.quantity > 0


and my views.py



class ProductsList(generics.ListAPIView):
queryset = Product.objects.all().order_by('-id')
serializer_class = ProductSerializer
filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
filter_class = ProductFilter









share|improve this question


























    0















    How can I hide the products from view with quantity == 0?
    This is my models.py



    class Product(models.Model):
    title = models.CharField(max_length=255, db_index=True)
    description = models.TextField()
    price = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
    quantity = models.PositiveIntegerField()
    color = models.CharField(choices=COLOR_CHOICES, default='BLACK', max_length=100)
    category = models.ManyToManyField(Category, related_name='products')

    class Meta:
    ordering = ('-id',)

    def __str__(self):
    return self.title

    @property
    def instock(self):
    return self.quantity > 0


    and my views.py



    class ProductsList(generics.ListAPIView):
    queryset = Product.objects.all().order_by('-id')
    serializer_class = ProductSerializer
    filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
    filter_class = ProductFilter









    share|improve this question
























      0












      0








      0








      How can I hide the products from view with quantity == 0?
      This is my models.py



      class Product(models.Model):
      title = models.CharField(max_length=255, db_index=True)
      description = models.TextField()
      price = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
      quantity = models.PositiveIntegerField()
      color = models.CharField(choices=COLOR_CHOICES, default='BLACK', max_length=100)
      category = models.ManyToManyField(Category, related_name='products')

      class Meta:
      ordering = ('-id',)

      def __str__(self):
      return self.title

      @property
      def instock(self):
      return self.quantity > 0


      and my views.py



      class ProductsList(generics.ListAPIView):
      queryset = Product.objects.all().order_by('-id')
      serializer_class = ProductSerializer
      filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
      filter_class = ProductFilter









      share|improve this question














      How can I hide the products from view with quantity == 0?
      This is my models.py



      class Product(models.Model):
      title = models.CharField(max_length=255, db_index=True)
      description = models.TextField()
      price = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
      quantity = models.PositiveIntegerField()
      color = models.CharField(choices=COLOR_CHOICES, default='BLACK', max_length=100)
      category = models.ManyToManyField(Category, related_name='products')

      class Meta:
      ordering = ('-id',)

      def __str__(self):
      return self.title

      @property
      def instock(self):
      return self.quantity > 0


      and my views.py



      class ProductsList(generics.ListAPIView):
      queryset = Product.objects.all().order_by('-id')
      serializer_class = ProductSerializer
      filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
      filter_class = ProductFilter






      django django-rest-framework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 18:36









      Chyngyz AkmatovChyngyz Akmatov

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can exclude objects with exclude(field_name=value_to_exclude), so:



           class ProductsList(generics.ListAPIView):
          queryset = Product.objects.all().exclude(quantity=0).order_by('-id')
          serializer_class = ProductSerializer
          filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
          filter_class = ProductFilter





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050649%2fhiding-the-products-with-quantity-0-from-view-django-rest-framework%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can exclude objects with exclude(field_name=value_to_exclude), so:



             class ProductsList(generics.ListAPIView):
            queryset = Product.objects.all().exclude(quantity=0).order_by('-id')
            serializer_class = ProductSerializer
            filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
            filter_class = ProductFilter





            share|improve this answer



























              0














              You can exclude objects with exclude(field_name=value_to_exclude), so:



               class ProductsList(generics.ListAPIView):
              queryset = Product.objects.all().exclude(quantity=0).order_by('-id')
              serializer_class = ProductSerializer
              filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
              filter_class = ProductFilter





              share|improve this answer

























                0












                0








                0







                You can exclude objects with exclude(field_name=value_to_exclude), so:



                 class ProductsList(generics.ListAPIView):
                queryset = Product.objects.all().exclude(quantity=0).order_by('-id')
                serializer_class = ProductSerializer
                filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
                filter_class = ProductFilter





                share|improve this answer













                You can exclude objects with exclude(field_name=value_to_exclude), so:



                 class ProductsList(generics.ListAPIView):
                queryset = Product.objects.all().exclude(quantity=0).order_by('-id')
                serializer_class = ProductSerializer
                filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
                filter_class = ProductFilter






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 19:01









                markemarke

                1236




                1236





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050649%2fhiding-the-products-with-quantity-0-from-view-django-rest-framework%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229