[Django] #28563: Allow parent relations to specify the related_name of a class property

19 views
Skip to first unread message

Django

unread,
Sep 3, 2017, 8:15:10 PM9/3/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
------------------------------------------+------------------------
Reporter: Samuel Spencer | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------+------------------------
I can't come up with an appropriate example, so I'll use a cut back
version of actual code. I'm trying to implement an ISO standard, and am
using a concrete base class, with a number of relations between objects,
as shown below. Unfortunately, the names of these objects and relations
are defined by the spec and can't be changed without a lot of hassle.

{{{

class Metadata(models.Model):
name = models.CharField(max_length=255)

class Property(Metadata):
pass

class ObjectClass(Metadata):
pass

class DataElementConcept(Metadata):
object_class = models.ForeignKey(ObjectClass)
property= models.ForeignKey(Property)

}}}

However, the system checker has a problem with this:

{{{
SystemCheckError: System check identified some issues:

ERRORS:
aristotle_mdr.DataElementConcept.property: (models.E006) The field
'property' clashes with the field 'property' from model
'aristotle_mdr._concept'.
}}}

What appears to happen is that DataElementConcept.property (a relation
between two pieces of metadata) is clashing with MetadataItem.property (a
relation from parent class to child class).

Since a parent-child relationship using inheritance is just a
OneToOneField thats made by
[https://github.com/django/django/blob/5cc746206726c538c36a2830e7c068f1c8a0e7c8/django/db/models/base.py#L234
django.db.models.base.ModelBase] it'd be nice to be able to add some
details to a classes Meta field to change the related_name of the
generated field, for example:

{{{

class Metadata(models.Model):
name = models.CharField(max_length=255)

class Property(Metadata):
class Meta:
parent_related_name = "property_subclass"

}}}

and the ModelBase coude would be similar to:

{{{
field = OneToOneField(
base,
on_delete=CASCADE,
name=attr_name,
auto_created=True,
parent_link=True,
related_name=base._meta.parent_related_name
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28563>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 4, 2017, 11:17:11 AM9/4/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
--------------------------------+--------------------------------------

Reporter: Samuel Spencer | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Charette):

I'm not convinced it's worth adding a `Meta` option for the rare cases
when this is required. Explicitly defining your parent link as you've
pointed out should do.

{{{#!python
class Property(Metadata):
metadata_ptr = OneToOneField(
Metadata,
on_delete=CASCADE,
parent_link=True,
related_name='property_subclass',
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28563#comment:1>

Django

unread,
Sep 4, 2017, 11:15:38 PM9/4/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
--------------------------------+--------------------------------------
Reporter: Samuel Spencer | Owner: tothegump
Type: New feature | Status: assigned
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by tothegump):

* owner: nobody => tothegump
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28563#comment:2>

Django

unread,
Sep 5, 2017, 7:59:32 AM9/5/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
--------------------------------+--------------------------------------
Reporter: Samuel Spencer | Owner: tothegump
Type: New feature | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: assigned => closed
* resolution: => wontfix


Comment:

Agreed, I think defining fields is a more clear solution than a `Meta`
option.

--
Ticket URL: <https://code.djangoproject.com/ticket/28563#comment:3>

Django

unread,
Sep 7, 2017, 1:36:20 AM9/7/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
--------------------------------+--------------------------------------
Reporter: Samuel Spencer | Owner: tothegump
Type: New feature | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Description changed by Samuel Spencer:

Old description:

New description:

I didn't even realise that was possible! Cheers.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28563#comment:4>

Django

unread,
Sep 7, 2017, 1:37:21 AM9/7/17
to django-...@googlegroups.com
#28563: Allow parent relations to specify the related_name of a class property
--------------------------------+--------------------------------------
Reporter: Samuel Spencer | Owner: tothegump
Type: New feature | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------

Old description:

> I didn't even realise that was possible! Cheers.

New description:

{{{

class Property(Metadata):
pass

class ObjectClass(Metadata):
pass

}}}

{{{

}}}

--

Comment (by Samuel Spencer):

I didn't even realise that was possible! Cheers.

--
Ticket URL: <https://code.djangoproject.com/ticket/28563#comment:5>

Reply all
Reply to author
Forward
0 new messages