# Why does model.\_meta.get\_fields() doesn't return reverse relation with \_set suffixed

**URL:** <https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064>\
**Category:** ORM\
**Created:** [June 1, 2022, 10:14am UTC](https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064 "2022-06-01T10:14:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NwawelAIroume](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/nwawelairoume/32/8458_2.png) [@NwawelAIroume](https://forum.djangoproject.com/u/NwawelAIroume)\
**Post date:** [June 1, 2022, 10:14am UTC](https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064/1 "2022-06-01T10:14:25Z")

</div>

I want to get all fields of a model including reverse fields using \_meta.get\_fields() but i noticed that some Fields returned are missing the ‘\_set’ for reverse relation  
Here is an example of 2 models linked with ForeignKey

```auto
class Version(models.Model):
    revision = models.ForeignKey(
        Revision,
        on_delete=models.CASCADE,
        help_text="The revision that contains this version.",
        # related_name="version"
    )

class Revision(models.Model):
    date_created = models.DateTimeField(
        db_index=True,
        verbose_name=_("date created"),
        help_text="The date and time this revision was created.",
    )

    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        verbose_name=_("user"),
        help_text="The user who created this revision.",
    )

    comment = models.TextField(
        blank=True,
        verbose_name=_("comment"),
        help_text="A text comment on this revision.",
    )

```

So when i use  
`Revision._meta.get_fields()`  
output:

```auto
(<ManyToOneRel: reversion.version>,
 <django.db.models.fields.AutoField: id>,
 <django.db.models.fields.DateTimeField: date_created>,
 <django.db.models.fields.related.ForeignKey: user>,
 <django.db.models.fields.TextField: comment>)

```

`Revision._meta.get_fields()[0].name`  
Out: ‘version’  
**i think it should be ‘version\_set’ because there is no related\_name in the ForeignKey**

when i do Revision.version i get AttributeError

What is wrong with Revision.\_meta.get\_fields()[0].name? am i missing something

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 2, 2022, 1:42pm UTC](https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064/2 "2022-06-02T13:42:51Z")

</div>

If my understanding is correct, “version” is the related name. For example, that’s what you use as a field reference in a query.

The name “version\_set” is a [_manager_](https://docs.djangoproject.com/en/4.0/ref/models/relations/#django.db.models.fields.related.RelatedManager) that is created for accessing the collection of items referencing the base object, it’s not a field.

You don’t generally reference a `version_set` object directly - you use it as a manager with a chained function such as `.all()` to access the members of that list.

---

<div class="post-metadata">

**Author:** ![NwawelAIroume](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/nwawelairoume/32/8458_2.png) [@NwawelAIroume](https://forum.djangoproject.com/u/NwawelAIroume)\
**Post date:** [June 2, 2022, 2:10pm UTC](https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064/3 "2022-06-02T14:10:46Z")

</div>

> [@NwawelAIroume](#):
>
> ```auto
> # related_name="version"
> 
> ```

In this example “version” is not the related\_name. looks, it is commented. as in the original code it was not specified Revision.\_meta.get\_fields()[0].name still return version. so for both cases (related\_name set vs related\_name not set) get\_fields()[0].name is still the same

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 2, 2022, 2:14pm UTC](https://forum.djangoproject.com/t/why-does-model-meta-get-fields-doesnt-return-reverse-relation-with-set-suffixed/14064/4 "2022-06-02T14:14:45Z")

</div>

> [@NwawelAIroume](#):
>
> In this example “version” is not the related\_name.

Sorry, typo on my part - it’s the [`related_query_name`](https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.ForeignKey.related_query_name).

But aside from that, the key point here is that the `_set` suffixed name is _not_ a field, it’s a manager. They’re two different things.
