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
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
add a comment |
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
add a comment |
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
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
django django-rest-framework
asked Mar 7 at 18:36
Chyngyz AkmatovChyngyz Akmatov
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 7 at 19:01
markemarke
1236
1236
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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