Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Django sum all related objects of a filtered QuerySet

What I would like to do in psuedo code is:

def import_transaction_deposit_crypto(Importer):
    logger = get_nexchange_logger(__name__, True, True)
    existent_addresses = Address.objects.filter(
        currency__is_crypto=True,
        type=Address.DEPOSIT,
        currency__wallet__in=Importer.RELATED_NODES

    ).tx_to_set.count()

Example value of importer:

class LitecoinTxImporter:
    RELATED_NODES = 'ltc_rpc_1'

tx_to is a related_field (reverse relation):

class Address(BtcBase, SoftDeletableModel):
    address_to = models.ForeignKey('core.Address',
                                   related_name='txs_to')

The idea is to count all 'already imported' transactions that belong to a specific RPC node (wallet), in order to feed it to the from parameter of the listtransactions RPC endpoint (generally speaking, for pagination purposes).

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This is documented here with a perfectly matching example:

# Build an annotated queryset
>>> from django.db.models import Count
>>> q = Book.objects.annotate(Count('authors'))
# Interrogate the first object in the queryset
>>> q[0]
<Book: The Definitive Guide to Django>
>>> q[0].authors__count
2
about 4 years ago · Santiago Trujillo Report

0

You could start the filtering from Address:

Adress.objects.filter(address_to__curency__is_crpyto=True, ...).count()

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!