Skip to main content

django-nonrelated-inlines

Django admin inlines for unrelated models

CircleCI PyPI

Getting started

This app allows you to create admin inlines for models that don't have an explicit foreign key relationship.

To use, subclass your inline from either NonrelatedStackedInline or NonrelatedTabularInline and add get_form_queryset and save_new_instance methods.

  • get_form_queryset(self, obj) returns all objects that should be shown in the inline formset.
  • save_new_instance(self, parent, instance) given a parent object and a new child object instance should associate the child object with the parent.

For example, let's assume we have Customer and Invoice models. Invoice objects are associated with a Customer if they share the same email address.

from nonrelated_inlines.admin import NonrelatedStackedInline


class CustomerInvoiceStackedInline(NonrelatedStackedInline):
    model = Invoice
    fields = [
        'id',
        'amount'
    ]

    def get_form_queryset(self, obj):
        return self.model.objects.filter(email=obj.email)

    def save_new_instance(self, parent, instance):
        instance.email = parent.email

When viewing an Customer instance, we fetch a queryset of all Invoice instances sharing the same email address. Similarly, when saving a new Invoice instance we make sure to set its email attribute to the same value as its parent Customer.

Release files for django-nonrelated-inlines 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-nonrelated-inlines 0.2
File Size Uploaded
django-nonrelated-inlines-0.2.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-nonrelated-inlines 0.2
File Interpreter ABI Platform
django_nonrelated_inlines-0.2-py3-none-any.whl Python 3 none any Details

Total release size:15.8 kB

Release files / django-nonrelated-inlines-0.2.tar.gz

Download URL django-nonrelated-inlines-0.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e123010a3ad18b049781d6688b3ff45b2441e69fd63802bec94c37cd36c83611
BLAKE2b-256 checksum
How to use checksums
a9634287295cdbd9e0c8b9e4b1e7c488c99f1a3553cab22040ffae7cd9329a5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Release files / django_nonrelated_inlines-0.2-py3-none-any.whl

Download URL django_nonrelated_inlines-0.2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
216a4513971c58568f450a2339064746624de718a946088534e86011b400ccc3
BLAKE2b-256 checksum
How to use checksums
9a103c71009ced6df7e88a838645149dccd28481c760e210cb9c7a78263d5f95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page