[Fixed]-External script can't recognize model fields


This has nothing to do with external scripts. That’s not how you do queries in Django; there are several things wrong, and they’d be just as wrong in your main application.

You need to use the double-underscore syntax to cross relations; also, you can’t use expressions like !=, nor can you use and. Your query should be:

transactions = Transaction.objects.filter(
    Q(paypal_auth__ne=None) & Q(paypal_auth__payer_id__ne=None))

Although note that your second condition implies the first, so you could just do:

transactions = Transaction.objects.filterpaypal_auth__payer_id__ne=None)


You imported the paypal_auth module, but the class is PayPalAuth, which is presumably within the paypal_auth module.

Try paypal_auth.PayPalAuth.payer_id (or refer to a payer_id of a particular instance)

Leave a comment