Changes between Version 4 and Version 5 of Ticket #28563


Ignore:
Timestamp:
Sep 7, 2017, 12:37:19 AM (7 years ago)
Author:
Samuel Spencer
Comment:

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

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28563 – Description

    v4 v5  
    1 I didn't even realise that was possible! Cheers.
     1I 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       
     5class Metadata(models.Model):
     6    name = models.CharField(max_length=255)
     7       
     8class Property(Metadata):
     9    pass
     10       
     11class ObjectClass(Metadata):
     12    pass
     13       
     14class DataElementConcept(Metadata):
     15    object_class = models.ForeignKey(ObjectClass)
     16    property= models.ForeignKey(Property)
     17       
     18}}}
     19       
     20However, the system checker has a problem with this:
     21       
     22{{{
     23SystemCheckError: System check identified some issues:
     24       
     25ERRORS:
     26aristotle_mdr.DataElementConcept.property: (models.E006) The field 'property' clashes with the field 'property' from model 'aristotle_mdr._concept'.
     27}}}
     28       
     29What 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       
     31Since 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       
     35class Metadata(models.Model):
     36    name = models.CharField(max_length=255)
     37       
     38class Property(Metadata):
     39    class Meta:
     40        parent_related_name = "property_subclass"
     41       
     42}}}
     43       
     44and 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}}
Back to Top