Is there a way to get data count from queryset
up vote
0
down vote
favorite
I made a query that goes like this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE')
Basically, I'm trying to get the quantity per rm_type
that is named LLDPE
. my models look something like this:
class Inventory(models.Model):
RM_TYPES = (
('--', '----------------'),
('LDPE', 'Low-density polyethylene'),
('LLDPE', 'Linear low-density polyethylene'),
('HDPE', 'High-density polyethylene'),
('PP', 'Polypropylene'),
('PET', 'Polyethylene terephthalate')
)
item_type = models.CharField('item_type', choices=ITEM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
rm_type = models.CharField('rm_type', choices=RM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
quantity = models.IntegerField()
python django django-queryset
add a comment |
up vote
0
down vote
favorite
I made a query that goes like this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE')
Basically, I'm trying to get the quantity per rm_type
that is named LLDPE
. my models look something like this:
class Inventory(models.Model):
RM_TYPES = (
('--', '----------------'),
('LDPE', 'Low-density polyethylene'),
('LLDPE', 'Linear low-density polyethylene'),
('HDPE', 'High-density polyethylene'),
('PP', 'Polypropylene'),
('PET', 'Polyethylene terephthalate')
)
item_type = models.CharField('item_type', choices=ITEM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
rm_type = models.CharField('rm_type', choices=RM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
quantity = models.IntegerField()
python django django-queryset
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I made a query that goes like this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE')
Basically, I'm trying to get the quantity per rm_type
that is named LLDPE
. my models look something like this:
class Inventory(models.Model):
RM_TYPES = (
('--', '----------------'),
('LDPE', 'Low-density polyethylene'),
('LLDPE', 'Linear low-density polyethylene'),
('HDPE', 'High-density polyethylene'),
('PP', 'Polypropylene'),
('PET', 'Polyethylene terephthalate')
)
item_type = models.CharField('item_type', choices=ITEM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
rm_type = models.CharField('rm_type', choices=RM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
quantity = models.IntegerField()
python django django-queryset
I made a query that goes like this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE')
Basically, I'm trying to get the quantity per rm_type
that is named LLDPE
. my models look something like this:
class Inventory(models.Model):
RM_TYPES = (
('--', '----------------'),
('LDPE', 'Low-density polyethylene'),
('LLDPE', 'Linear low-density polyethylene'),
('HDPE', 'High-density polyethylene'),
('PP', 'Polypropylene'),
('PET', 'Polyethylene terephthalate')
)
item_type = models.CharField('item_type', choices=ITEM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
rm_type = models.CharField('rm_type', choices=RM_TYPES, max_length=200, default='Not specified', null=True, blank=True)
quantity = models.IntegerField()
python django django-queryset
python django django-queryset
edited Nov 12 at 7:49
asked Nov 11 at 19:27
Martin Crespo
53
53
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Use .count()
method to get the quantity on an specific queryset. Here is the doc
count()
Returns an integer representing the number of objects in the database
matching the QuerySet.
In your example, try this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE').count()
But, if you want to aggregate every rm_type
, you should use django aggregation.
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Use .count()
method to get the quantity on an specific queryset. Here is the doc
count()
Returns an integer representing the number of objects in the database
matching the QuerySet.
In your example, try this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE').count()
But, if you want to aggregate every rm_type
, you should use django aggregation.
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
add a comment |
up vote
0
down vote
accepted
Use .count()
method to get the quantity on an specific queryset. Here is the doc
count()
Returns an integer representing the number of objects in the database
matching the QuerySet.
In your example, try this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE').count()
But, if you want to aggregate every rm_type
, you should use django aggregation.
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Use .count()
method to get the quantity on an specific queryset. Here is the doc
count()
Returns an integer representing the number of objects in the database
matching the QuerySet.
In your example, try this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE').count()
But, if you want to aggregate every rm_type
, you should use django aggregation.
Use .count()
method to get the quantity on an specific queryset. Here is the doc
count()
Returns an integer representing the number of objects in the database
matching the QuerySet.
In your example, try this:
LLDPE = Inventory.objects.filter(rm_type='LLDPE').count()
But, if you want to aggregate every rm_type
, you should use django aggregation.
edited Nov 12 at 1:02
answered Nov 12 at 0:57
Cheche
834218
834218
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
add a comment |
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
I need the get the quantity from the models. From what I know, count() counts the number of instances of the rm_type.
– Martin Crespo
Nov 12 at 7:49
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
Checked the aggregation. Seems like the solution to my question is there. Thank you.
– Martin Crespo
Nov 12 at 8:07
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53252380%2fis-there-a-way-to-get-data-count-from-queryset%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