All Projects → gitaarik → Django Admin Relation Links

gitaarik / Django Admin Relation Links

Licence: lgpl-3.0
An easy way to add links to relations in the Django Admin site.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Admin Relation Links

Django Admin Bootstrap
Responsive Theme for Django Admin With Sidebar Menu
Stars: ✭ 787 (+804.6%)
Mutual labels:  django, django-admin
Requery
Store e run queries on database to help system manager of a Django website
Stars: ✭ 12 (-86.21%)
Mutual labels:  django, django-admin
Django Phantom Theme
Phantom is theme for django admin with many widgets, based on Twitter bootstrap 3.x.
Stars: ✭ 18 (-79.31%)
Mutual labels:  django, django-admin
Django Ordered Model
Get your Django models in order
Stars: ✭ 476 (+447.13%)
Mutual labels:  django, django-admin
Django Polymorphic
Improved Django model inheritance with automatic downcasting
Stars: ✭ 1,135 (+1204.6%)
Mutual labels:  django, django-admin
Django Pagedown
A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
Stars: ✭ 500 (+474.71%)
Mutual labels:  django, django-admin
Django Oml
Object Moderation Layer
Stars: ✭ 12 (-86.21%)
Mutual labels:  django, django-admin
Django Cruds Adminlte
django-cruds is simple drop-in django app that creates CRUD for faster prototyping
Stars: ✭ 373 (+328.74%)
Mutual labels:  django, django-admin
Django Admin Numeric Filter
Numeric filters for Django admin
Stars: ✭ 46 (-47.13%)
Mutual labels:  django, django-admin
E Commerce 2 django
Guest register, user register, user login, user logout, account home page, product view history, change password, reset password, change name, send activation email when register, resend activation email, add shipping address, add billing address, add nickname to the addresses, edit shipping address, edit billing address, view list of your addresses, reuse shipping addresses when order products, reuse billing addresses when ordeer products, show sales analytics if staff or admin only using -chart.js-, get analytics data with Ajax, receive marketing email, change if user will receive marketing email or not by admin, send contact message with Ajax, products list, product detail, download product detail as a PDF file, download digital product files -if the user purchased that digital product only-, orders list, list of digital products files, order detail, download order detail as a PDF file, verify order ownership with Ajax -to secure order detail page-, show cart products, add or remove product from cart, checkout page, thanks page when order placed successfully, add or reuse payment method, add or reuse payment method with Ajax, search products by title, search products by description, search products by price, search products by tag title, write tags for products -by admin only-, auto fill contact email, full name if user logged in.
Stars: ✭ 20 (-77.01%)
Mutual labels:  django, django-admin
Django Nested Admin
Django admin classes that allow for nested inlines
Stars: ✭ 463 (+432.18%)
Mutual labels:  django, django-admin
Django Admin Material
A Django Admin interface based on Material Design by Google
Stars: ✭ 74 (-14.94%)
Mutual labels:  django, django-admin
Django Flat Theme
A flat theme for Django admin interface. Modern, fresh, simple.
Stars: ✭ 415 (+377.01%)
Mutual labels:  django, django-admin
Awesome Django
The Best Django Resource, Awesome Django for mature packages.
Stars: ✭ 591 (+579.31%)
Mutual labels:  django, django-admin
Django Object Actions
A Django app for easily adding object tools in the Django admin
Stars: ✭ 374 (+329.89%)
Mutual labels:  django, django-admin
Django Blogging System
This is blog system created using Django 1.11.4 and Python3
Stars: ✭ 11 (-87.36%)
Mutual labels:  django, django-admin
Djangocms Admin Style
django CMS Admin Style is a Django Theme tailored to the needs of django CMS.
Stars: ✭ 282 (+224.14%)
Mutual labels:  django, django-admin
Awesome Django Admin
Curated List of Awesome Django Admin Panel Articles, Libraries/Packages, Books, Themes, Videos, Resources.
Stars: ✭ 356 (+309.2%)
Mutual labels:  django, django-admin
Django Suit Daterange Filter
Filter for django-admin allowing lookups by date range
Stars: ✭ 13 (-85.06%)
Mutual labels:  django, django-admin
Awesome Django Cn
Django 优秀资源大全。
Stars: ✭ 1,153 (+1225.29%)
Mutual labels:  django, django-admin

Django Admin relation links

An easy way to add links to relations in the Django Admin site.

Preview

Imagine you have admin pages for 2 models: Member and Group. Member has a ForeignKey relation to Group.

  • When you look at a member, you want to easily navigate to its group.
  • When you look at a group, you want to easily navigate to a list of the members in that group.

With the help of this app you can easily create these links:

Member list page:

Member list page

Member change page:

Member change page

Group list page:

Member list page

Group change page:

Member change page

Install

pip install django-admin-relation-links

How to use

The links are placed on the change page of the model and go to the change list page or the change page of the related model, depending on whether the related model has a ForeignKey to this model or this model has a ForeignKey to the related model, or if it's a OneToOneField.

So for example, if you have these models:

from django.db import models


class Group(models.Model):
    name = models.CharField(max_length=200)


class Member(models.Model):
    name = models.CharField(max_length=200)
    group = models.ForeignKey(Group, related_name='members')

Then in the admin you can add links on the Group change page to the Member change list page (all the members of that group) and on the Member change page a link to the Group change page (the group of that member). Use the changelist_links and change_links fields:

from django.contrib import admin
from django_admin_relation_links import AdminChangeLinksMixin


@admin.register(Group)
class GroupAdmin(AdminChangeLinksMixin, admin.ModelAdmin):

    list_display = ['name']

    # Use the `related_name` of the `Member.group` field.
    # If you have no `related_name` specified on your model, use the default
    # `related_name` assigned by Django.
    changelist_links = ['members']

@admin.register(Member)
class MemberAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
    list_display = ['name']

    # Here we just specify the name of the `ForeignKey` field.
    change_links = ['group']

List page links

It is possible to show links on admin list page as well, using the field {field_name}_link:

@admin.register(Member)
class MemberAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
    list_display = ['name', 'group_link']  # Show link to group *change page* on member *list page*
    change_links = ['group']

Link label

By default, the label of the link is the string representation of the model instance. You can change the label by creating a method named {field_name}_link_label() like this:

    def group_link_label(self, group):
        return '{} ({} members)'.format(
            group.name,
            group.members.count()
        )

Extra options

You can also set extra options like label, model and lookup_filter like this:

@admin.register(Group)
class GroupAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
    list_display = ['name']
    changelist_links = [
        ('members', {
            'label': 'All members',  # Used as label for the link
            'model': 'Member',  # Specify a different model, you can also specify an app using `app.Member`
            'lookup_filter': 'user_group'  # Specify the GET parameter used for filtering the queryset
        })
    ]

List page ordering

When showing links on the list page, when you use that field for ordering, the default ordering field is the first field in the ordering option on the Meta class of the model of the related field. You can specify an alternative ordering like this:

@admin.register(Group)
class MemberAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
    list_display = ['name', 'group_link']
    change_links = [
        ('group', {
            'admin_order_field': 'group__name',  # Allow to sort members by `group_link` column
        })
    ]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].