How do I add a link from the Django admin page of one object to the admin page of a related object?

Use readonly_fields: class MyInline(admin.TabularInline): model = MyModel readonly_fields = [‘link’] def link(self, obj): url = reverse(…) return mark_safe(“<a href=”https://stackoverflow.com/questions/9919780/%s”>edit</a>” % url) # the following is necessary if ‘link’ method is also used in list_display link.allow_tags = True

Calling block inside an if condition: django template

You haven’t made a mistake – template blocks are included regardless of any conditionals around them. You can see this from this line of the ExtendsNode class of django/template/loader_tags.py in the Django source code: self.blocks = {n.name: n for n in nodelist.get_nodes_by_type(BlockNode)]} When the {% extends %} is being rendered, it fetches all block nodes … Read more

Django templates: Get current URL in another language

I’m not using language prefixes, but translated urls instead. However, this template tag should also help you: # This Python file uses the following encoding: utf-8 from django import template from django.core.urlresolvers import reverse # from django.urls for Django >= 2.0 from django.core.urlresolvers import resolve # from django.urls for Django >= 2.0 from django.utils import … Read more

Django {{ MEDIA_URL }} blank @DEPRECATED

You need to add the RequestContext in your render_to_response for the context processors to be processed. In your case: from django.template.context import RequestContext context = {‘latest’: p} render_to_response(‘Question/latest.html’, context_instance=RequestContext(request, context)) From the docs: context_instance The context instance to render the template with. By default, the template will be rendered with a Context instance (filled with … Read more

Django: Select option in template

You’ll want to pass the currently selected org into the view, maybe as current_org so that when you’re iterating through the orgs you can compare with the current one to determine whether or not to select it, like: {% for org in organisation %} <option value=”{{org.id}}” {% if org == current_org %}selected=”selected”{% endif %}> {{org.name|capfirst}} … Read more