Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

74
Vistas
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).

8 months ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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
8 months ago · Santiago Trujillo Denunciar

0

You could start the filtering from Address:

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

8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.