Hello, 

I wanted to know that how for the model below,  how can I get a queryset 
with  all the fields excluding the `user` and including the  output of 
get_output_field? Please avoid hardcoding.
One way is

`TransactionEntry
.objects.defer("users").annotate(total_price=F("num_shares")*F("price_per_share"))`

but that is undesirable. I just want to use that function on the model and 
not hard code the formula.
Thanks,



class TransactionEntry(models.Model):
    """Model to save data of users who want to buy/sell shares"""

    user = models.ForeignKey(
        to=Relative,
        on_delete=models.CASCADE,
        related_name="transaction_entry",
    )

    num_shares = models.PositiveIntegerField(null=False, blank=False)
    date_of_trade = models.DateField(null=False, blank=False)
    transaction_type = models.CharField(
        max_length=1,
        choices=TransactionType.choices,
        default=TransactionType.SELL,
        null=False,
    )
    price_per_share = models.FloatField(null=False, blank=False)

    def get_total_price(self):
        return self.num_shares * self.price_per_share

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20b0067b-cbfc-49c5-90ef-c302504cac7bn%40googlegroups.com.

Reply via email to