#36041: related_query_name return wrong related_name
-------------------------------------+-------------------------------------
Reporter: mhmk2002 | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
By default djanog set a related name with this pattern model_name +
"_set".
but in related_query_name in django/db/models/fields/related.py this is
wrong.
Now is this
```
(
self.remote_field.related_query_name
or self.remote_field.related_name
or self.opts.model_name
)
```
```
and most change to this
(
self.remote_field.related_query_name
or self.remote_field.related_name
or f'{self.opts.model_name}_set'
)
```
suppost we have some model like this:
```
class Collection(models.Model):
title = models.CharField(max_length=255)
featured_product = models.ForeignKey('Product',
on_delete=models.SET_NULL, null=True,)
class Product(models.Model):
title = models.CharField(max_length=255)
description = models.TextField
price = models.DecimalField(max_digits=6, decimal_places=2)
inventory = models.IntegerField
last_update = models.DateTimeField(auto_now=True)
collection = models.ForeignKey(Collection, on_delete=models.PROTECT)
```
this related_name is okay but django will get error beacuse this function
is wrong.
--
Ticket URL: <https://code.djangoproject.com/ticket/36041>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/010701940e6fd756-7f6a58b3-4e7c-4e85-abfc-925878204a4c-000000%40eu-central-1.amazonses.com.