开发者

How/When does Django calculate the ForeignKey object

开发者 https://www.devze.com 2022-12-16 11:01 出处:网络
I have a models开发者_运维百科 class class A(models.Model): user = models.ForeignKey(User) Now if I do a a = A.objects.get(pk = something_existing); print a.__dict__, user is not in __dict__. a.user

I have a models开发者_运维百科 class class A(models.Model): user = models.ForeignKey(User)

Now if I do a a = A.objects.get(pk = something_existing); print a.__dict__, user is not in __dict__. a.user however doesnot give an attribute error.

So when is the actual user being calculated? I looked in django.db.models.base.Model and django.db.models.base.ModelBase classes and they do not override __getattr__, (which I guessed might be being done), so where is this calculated/populated.


Django relation fields are implemented as descriptors.

0

精彩评论

暂无评论...
验证码 换一张
取 消