Tīmeklisscore:90. Accepted answer. related_name will be the attribute of the related object that allows you to go 'backwards' to the model with the foreign key on it. For example, if ModelA has a field like: model_b = ForeignKeyField (ModelB, related_name='model_as'), this would enable you to access the ModelA instances … TīmeklisWhat is related_name used for? The related_name attribute specifies the name of the reverse relation from the User model back to your model.. If you don't specify a related_name, Django automatically creates one using the name of your model with the suffix _set, for instance User.map_set.all().. If you do specify, e.g. …
How to get all related_name fields in django with serializers?
http://www.iotword.com/6403.html Tīmeklis2024. gada 23. okt. · related_name是ForeignKey外键桥梁,用来反向查询 我先定义两个模型,一个是作者,一个是作者出版的书籍,算是一对多的类型。 class Person (models. Model ); name = models.CharField (verbose_name='作者姓名', max_length=10) age = models.IntegerField (verbose_name='作者年龄') 1 2 3 class Book (models.Model): philip marshall qc serle court
using related_name in Django - DEV Community
Tīmeklis在外键( ForeignKey )的定义中,我们可以通过设置 related_name 参数来覆盖名字entry_set(相当于别名的作用)以起到相同的作用。 示例如下: blog = ForeignKey (Blog, on_delete=models.CASCADE, related_name='entries') 然后我们如下使用: TīmeklisNow, book_set is an attribute that django constructed for us and gave it this name by default. Using the related_name attribute of foreign key you can give this attribute whatever name you want (for example if I had definited category as this category = models.ForeignKey ('Category', related_name='book_collection') then instead of … Tīmeklis2024. gada 19. janv. · In Django1.5 documentation , there is a section about related_name. the last paragraph is "If you’d prefer Django not to create a … philip marshall serle court