Opened 14 years ago
Last modified 12 years ago
#18098 new Bug
order_with_respect_to should construct set_RELATED_order() method name from related_name
| Reported by: | Daniel Swarbrick | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
If two identically named models in separate apps refer to a parent to the same parent model in their order_with_respect_to, only one set_RELATED_order() method is created on the parent model.
Attachments (1)
Change History (6)
by , 14 years ago
| Attachment: | order_wrt.diff added |
|---|
comment:1 by , 14 years ago
comment:2 by , 13 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
The problem is valid. However the proposed solution doesn't guarantee backwards compatibility. I'm not sure of what we should do.
comment:3 by , 13 years ago
How about making the order_with_respect_to attribute either a model name string for backwards compatibility, or a two-tuple, containing the parent model, and a name to assign the relationship? It's perhaps not the most elegant, but would satisfy both requirements.
comment:4 by , 13 years ago
| Triage Stage: | Design decision needed → Accepted |
|---|
We're getting rid of the DDN state, and this is a valid problem.
comment:5 by , 12 years ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
This following situation would cause this problem to surface:
class Device(models.Model): name = CharField(max_length=60, unique=True) ... # foo/models.py class ExpansionModule(models.Model): device = models.ForeignKey(Device, related_name='foo_expansionmodule_set') module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES) ... # additional fields specific to foo class Meta: order_with_respect_to = 'device' # bar/models.py class ExpansionModule(models.Model): device = models.ForeignKey(Device, related_name='bar_expansionmodule_set') module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES) ... # additional fields specific to bar class Meta: order_with_respect_to = 'device'"Device" objects would only have the one
set_expansionmodule_order()method.