#14018: Introduce class_plural %-substitution placeholder for related_name of
ForeignKey/ManyToManyField
---------------------------------------------------+------------------------
          Reporter:  puxlit                        |         Owner:  nobody     
                                                   
            Status:  new                           |     Milestone:  1.3        
                                                   
         Component:  Database layer (models, ORM)  |       Version:  SVN        
                                                   
        Resolution:                                |      Keywords:  
related_name, ManyToManyField, ForeignKey, abstract base class
             Stage:  Design decision needed        |     Has_patch:  1          
                                                   
        Needs_docs:  0                             |   Needs_tests:  0          
                                                   
Needs_better_patch:  1                             |  
---------------------------------------------------+------------------------
Changes (by lrekucki):

  * needs_better_patch:  0 => 1
  * stage:  Unreviewed => Design decision needed

Comment:

 The patch "as is" surely needs improvement. A simple solution that comes
 to mind would be adding {{{name_plural}}} to Meta. Then
 {{{%(class_plural)}}} could be replaced with that value or with class'
 name with an "s" added. The example above would then look something like
 this:
 {{{

 class Tag(models.Model):
     slug = models.SlugField(max_length=63, unique=True)

 class Post(models.Model):
     slug = models.SlugField(max_length=127, unique=True)
     tags = models.ManyToManyField(Tag,
 related_name='tagged_%(class_plural)s')

     class Meta:
         abstract = True

 class Entry(Post):
     title = models.CharField(max_length=255)
     content = models.TextField()

     class Meta:
         name_plural = "entries" # related attribute will be
 "tagged_entries"
         verbose_name_plural = _("Journal entries")

 class Event(Post):
     summary = models.CharField(max_length=255)
     start_date = models.DateTimeField()
     # related attribute will be "tagged_events"
 }}}

 I don't think much people care about this that much, so it's mostly a
 "nice to have" feature.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14018#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to