Ticket #11357: admindocs-m2m-both-ways-2.patch

File admindocs-m2m-both-ways-2.patch, 1.7 KB (added by benspaulding, 6 years ago)

Added <field>.count, and other consistency changes.

  • django/contrib/admindocs/views.py

    diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
    index f66ea3e..4f22fe0 100644
    a b def model_detail(request, app_label, model_name): 
    214214            'help_text': field.help_text,
    215215        })
    216216
     217    # Gather many-to-many fields.
     218    for field in opts.many_to_many:
     219        data_type = related_object_name = field.rel.to.__name__
     220        app_label = field.rel.to._meta.app_label
     221        verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': app_label, 'object_name': data_type}
     222        fields.append({
     223            'name': "%s.all" % field.name,
     224            "data_type": 'List',
     225            'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name),
     226        })
     227        fields.append({
     228            'name'      : "%s.count" % field.name,
     229            'data_type' : 'Integer',
     230            'verbose'   : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name),
     231        })
     232
    217233    # Gather model methods.
    218234    for func_name, func in model.__dict__.items():
    219235        if (inspect.isfunction(func) and len(inspect.getargspec(func)[0]) == 1):
    def model_detail(request, app_label, model_name): 
    233249            })
    234250
    235251    # Gather related objects
    236     for rel in opts.get_all_related_objects():
     252    for rel in opts.get_all_related_objects() + opts.get_all_related_many_to_many_objects():
    237253        verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': rel.opts.app_label, 'object_name': rel.opts.object_name}
    238254        accessor = rel.get_accessor_name()
    239255        fields.append({
Back to Top