I have a small problem that I can not figure out.
I
class UserWhale (models.Model): currencyPair = models.ForeignKey ( 'currencies.CurrencyPair', verbose_name = 'currency pair') currency = models.ForeignKey ( "got the following models currencies .Currency ', verbose_name =' source currency ') currencyTarget = models.ForeignKey (' currencies.Currency ', related_name =' whale_currency_target_rel ', verbose_name =' target currency ') userBankAccount = models.ForeignKey ( UserBankAccount, verbose_name = 'deposit account') whale_fee_percentage = models.DecimalField (max_digits = 11, decimal_places = 2) whale_amount = models.DecimalField (max_digits = 11, decimal_places = 2) whale_matched = models.DecimalField (max_digits = 11, decimal_places = 2) Priority = models.IntegerField () user = models .ForeignKey ( 'auth.User', related_name = 'whale_relation_user', editable = false) created_by = models.ForeignKey ( 'auth.User', editable = false) created = models.Dat eTimeField (auto_now_add = true, editable = false) modified = models.DateTimeField (auto_now = true, editable = false) history = audit.AuditTrail () when I produced the following:
{{request.user.userwhale_set.count}} it is always output as zero, even though the current user's data to the table. Fields "user" and "created_by" are always different, so I am thinking that the code above is using the "created" relationship rather than the "user" relationship. If so, how do I specify which one will use?
Many Thanks Ben
You specified related_name user Foreignkey, then you should call that name :. request.user.whale_relation_user.count
Comments
Post a Comment