Ticket #22428: 22428-1.diff

File 22428-1.diff, 2.8 KB (added by Claude Paroz, 6 years ago)
  • django/contrib/admindocs/views.py

    diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
    index ef9b781..eb3eacc 100644
    a b class ModelDetailView(BaseAdminDocsView): 
    262262                'data_type': 'Integer',
    263263                'verbose': utils.parse_rst(_("number of %s") % verbose, 'model', _('model:') + opts.model_name),
    264264            })
     265
     266        verbose = utils.parse_rst(utils.trim_docstring(model.__doc__), 'model', _('model:') + opts.model_name)
    265267        kwargs.update({
    266268            'name': '%s.%s' % (opts.app_label, opts.object_name),
    267269            # Translators: %s is an object type name
    268270            'summary': _("Attributes on %s objects") % opts.object_name,
    269             'description': model.__doc__,
     271            'description': verbose,
    270272            'fields': fields,
    271273        })
    272274        return super(ModelDetailView, self).get_context_data(**kwargs)
  • tests/admin_docs/models.py

    diff --git a/tests/admin_docs/models.py b/tests/admin_docs/models.py
    index 9b8f388..f07cde4 100644
    a b class Family(models.Model): 
    1818
    1919
    2020class Person(models.Model):
     21    """
     22    Similar as :model:`auth.User`.
     23    """
    2124    first_name = models.CharField(max_length=200, help_text="The person's first name")
    2225    last_name = models.CharField(max_length=200, help_text="The person's last name")
    2326    company = models.ForeignKey(Company, help_text="place of work")
  • tests/admin_docs/tests.py

    diff --git a/tests/admin_docs/tests.py b/tests/admin_docs/tests.py
    index 6eecb6a..75e905b 100644
    a b class TestModelDetailView(TestCase): 
    236236
    237237    def test_descriptions_render_correctly(self):
    238238        """
    239         The ``description`` field should render correctly for each type of field
     239        The ``description`` field should render correctly for the model itself
     240        and for each type of field.
    240241        """
     242        link = '<a class="reference external" href="/admindocs/models/%s/">%s</a>'
     243        markup = '<p>the related %s object</p>'
     244
     245        # model docstring
     246        auth_markup = link % ("auth.user", "auth.User")
     247        self.assertContains(self.response, auth_markup)
     248
    241249        # help text in fields
    242250        self.assertContains(self.response, "<td>first name - The person's first name</td>")
    243251        self.assertContains(self.response, "<td>last name - The person's last name</td>")
    class TestModelDetailView(TestCase): 
    245253        # method docstrings
    246254        self.assertContains(self.response, "<p>Get the full name of the person</p>")
    247255
    248         link = '<a class="reference external" href="/admindocs/models/%s/">%s</a>'
    249         markup = '<p>the related %s object</p>'
    250256        company_markup = markup % (link % ("admin_docs.company", "admin_docs.Company"))
    251257
    252258        # foreign keys
Back to Top