Last active
August 29, 2015 14:06
-
-
Save cansadadeserfeliz/7eb46afbea3346a6c52b to your computer and use it in GitHub Desktop.
Cosa loca de Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
invoice_6_contract_5_items = invoice_6.invoice_items.filter( | |
contract=self.contract5 | |
) | |
print invoice_6_contract_5_items.first().id, invoice_6_contract_5_items.last().id | |
print invoice_6_contract_5_items[0].id, invoice_6_contract_5_items[1].id | |
output >> | |
22 22 | |
22 23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: ii = InvoiceItem.objects.all()[:2] | |
In [2]: i = Invoice.objects.all()[:2] | |
In [3]: i.first().id, i.last().id | |
Out[3]: (23, 17) | |
In [4]: i.values_list('id', flat=True) | |
Out[4]: [23, 22] | |
In [5]: i.first().id, i.last().id | |
Out[5]: (23, 17) | |
In [6]: i | |
Out[6]: [<Invoice: 7>, <Invoice: 6>] | |
In [7]: i[0].id, i[1].id | |
Out[7]: (23, 22) | |
In [8]: Invoice.objects.all().last() | |
Out[8]: <Invoice: 1> | |
In [9]: Invoice.objects.all().last().id | |
Out[9]: 17 | |
In [10]: type(Invoice.objects.all()[:2]) | |
Out[10]: django.db.models.query.QuerySet | |
In [11]: type(Invoice.objects.all()) | |
Out[11]: django.db.models.query.QuerySet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment