1 | | 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. |
2 | | |
3 | | {{{ |
4 | | |
5 | | class Metadata(models.Model): |
6 | | name = models.CharField(max_length=255) |
7 | | |
8 | | class Property(Metadata): |
9 | | pass |
10 | | |
11 | | class ObjectClass(Metadata): |
12 | | pass |
13 | | |
14 | | class DataElementConcept(Metadata): |
15 | | object_class = models.ForeignKey(ObjectClass) |
16 | | property= models.ForeignKey(Property) |
17 | | |
18 | | }}} |
19 | | |
20 | | However, the system checker has a problem with this: |
21 | | |
22 | | {{{ |
23 | | SystemCheckError: System check identified some issues: |
24 | | |
25 | | ERRORS: |
26 | | aristotle_mdr.DataElementConcept.property: (models.E006) The field 'property' clashes with the field 'property' from model 'aristotle_mdr._concept'. |
27 | | }}} |
28 | | |
29 | | 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). |
30 | | |
31 | | 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: |
32 | | |
33 | | {{{ |
34 | | |
35 | | class Metadata(models.Model): |
36 | | name = models.CharField(max_length=255) |
37 | | |
38 | | class Property(Metadata): |
39 | | class Meta: |
40 | | parent_related_name = "property_subclass" |
41 | | |
42 | | }}} |
43 | | |
44 | | and the ModelBase coude would be similar to: |
45 | | |
46 | | {{{ |
47 | | field = OneToOneField( |
48 | | base, |
49 | | on_delete=CASCADE, |
50 | | name=attr_name, |
51 | | auto_created=True, |
52 | | parent_link=True, |
53 | | related_name=base._meta.parent_related_name |
54 | | ) |
55 | | }}} |
| 1 | I didn't even realise that was possible! Cheers. |