Changes between Initial Version and Version 4 of Ticket #27259


Ignore:
Timestamp:
Sep 26, 2016, 6:36:48 AM (8 years ago)
Author:
Maxim Syabro
Comment:

Okay, I missed this error

ERRORS:
testmodels.RelatedModel.main: (fields.E303) Reverse query name for 'RelatedModel.main' clashes with field name 'MainModel.relatedmodel'.
	HINT: Rename field 'MainModel.relatedmodel', or add/change a related_name argument to the definition for field 'RelatedModel.main'.

And I still have this questions:

  1. Why does it clash?
  2. Why related model have two names: 'relatedmodel' and 'relatedmodel_set' if we can use only second one?
  3. Why name property can't return 'relatedmodel_set' to avoid stuff above?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27259

    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #27259 – Description

    initial v4  
    1 F.e.
    2 {{{#!python
    3 class MainModel(models.Model):
    4     pass
    5 
    6 class RelatedModel(models.Model):
    7     main = models.ForeignKey(MainModel)
    8 }}}
    9 
    10 {{{ManyToOneRel.name}}} should be {{{relatedmodel_set}}}, not {{{relatedmodel}}}
    11 
    12 {{{#!python
    13 >>> from testmodels.models import MainModel
    14 >>> fieldname = MainModel._meta.get_fields()[0].name
    15 >>> print getattr(MainModel, fieldname, None)
    16 None
    17 >>> print getattr(MainModel, fieldname + '_set', None)
    18 <django.db.models.fields.related_descriptors.ReverseManyToOneDescriptor object at 0x103dc1510>}}}
Back to Top