Ruby on Rails uses "correct" plural forms in code. But in order to do this
it contains a special library to pluralize words correctly, e.g. octopus ->
octopuses. And naturally that strategy requires per-language and per-word
knowledge, and can go wrong when trying to use non-english words.

Rather than use such "magic", Django takes a simple, pragmatic, predictable
approach of just appending "_set". Similarly Meta.verbose_name_plural
simply appends an "s". If these behaviours aren't suitable for you, you're
free to override them for your project.

You can use "s" instead of "_set" for all your foreign keys with the
interpolation feature of ForeignKey (
https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.ForeignKey.related_name
) plus a partial (
https://adamj.eu/tech/2021/05/05/3-uses-for-functools-partial-in-django/ ) :

from functools import partial
from django.db import models

ForeignKey = partial(models.ForeignKey, related_name="%(class)ss")


class Author(models.Model):
    ...


class Book(models.Model):
    author = ForeignKey(Author, on_delete=models.CASCADE)
    ...

On Thu, 5 Aug 2021 at 17:38, 김정훈 <jh....@birdview.kr> wrote:

>
> Hi,
>
> Django's default reverse relationship name is a model name followed by a
> _set suffix. In terms of readability, depending on the type of
> relationship used, I think it would be good to make the default reverse
> relationship name in the singular or plural form of the model name.
>
> Is there any reason to set the default reverse relationship name in the
> current format?
>
> Regards,
> Jeonghun Kim
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/2407b63e-0f51-4cf8-8308-c3a72716ace2n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/2407b63e-0f51-4cf8-8308-c3a72716ace2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM02q4hCjCgzdiS%2BgLGdMWZBSBmqDuFvOD3jfuK6BLiUsw%40mail.gmail.com.
  • Is ... 김정훈
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... 김정훈

Reply via email to