Skip to main content

m3-django-composite-foreignkey

Данный пакет - это fork https://github.com/michael-k/django-composite-foreignkey/tree/django32-python39. Создан по причине того, что оригинальный https://github.com/onysos/django-composite-foreignkey не принимает PR https://github.com/onysos/django-composite-foreignkey/pull/18 длительное время. Возможно, первоначальный дистрибутив заброшен и больше не используется. Информация ниже является текстом оригинала и оставлена без изменений.

allow to create a django foreignkey that don’t link with pk of other model, but with multi column matching local model columns or fixed values.

https://img.shields.io/travis/onysos/django-composite-foreignkey/master.svg https://readthedocs.org/projects/django-composite-foreignkey/badge/?version=latest https://img.shields.io/coveralls/onysos/django-composite-foreignkey/master.svg Latest PyPI version Number of PyPI downloads per month

some databases have a composite Primary Key, leading to impossiblity for a django foreign key to be used.

today, Django don’t support Composite Primary Key see ticket and ForeignKey don’t support multicolumn. but fortunaly, the base class of ForeignKey support it well, so this lib just add a little wrapper around ForeignObject to make it more usefull. the real add of this implementation is that is support the customisation of the link with Raw values.

this implementation of CompositeForeignKey skip the complexity of Composite Primary Key by forcing the providing of the corresponding column of the other model, not forcefully a PrimaryKey.

Installation

  1. Install using pip:

    pip install django-composite-foreignkey

  2. Alternatively, you can install download or clone this repo and call

    pip install -e ..

Example

you have this model

class Customer(models.Model):

    company = models.IntegerField()
    customer_id = models.IntegerField()
    name = models.CharField(max_length=255)
    address = CompositeForeignKey(Address, on_delete=CASCADE, to_fields={
        "tiers_id": "customer_id",
        "company": LocalFieldValue("company"),
        "type_tiers": RawFieldValue("C")
    })

    class Meta(object):
        unique_together = [
            ("company", "customer_id"),
        ]


class Contact(models.Model):
    company_code = models.IntegerField()
    customer_code = models.IntegerField()
    surname = models.CharField(max_length=255)
    # virtual field
    customer = CompositeForeignKey(Customer, on_delete=CASCADE, related_name='contacts', to_fields={
        "customer_id": "customer_code",
        "company": "company_code"
    })

you can use Contact.customer like any ForeignKey, but behinde the scene, it will query the Customer Table using company and customer id’s.

Documentation

The full documentation is at http://django-composite-foreignkey.readthedocs.org/en/latest/.

Requirements

  • Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9

  • Django 1.11, 2.0, 2.1, 2.2, 3.1, 3.2

Contributions and pull requests for other Django and Python versions are welcome.

Bugs and requests

If you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.

https://github.com/onysos/django-composite-foreignkey/issues

License

You can use this under GPLv3.

Author

Original author & Development lead: Darius BERNARD.

Thanks

Thanks to django for this amazing framework. And thanks to django-bootstrap3 to the structure of the apps.

Metadata

Release files for m3-django-composite-foreignkey 1.1.0

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

Source distribution (sdist)

Source distribution for m3-django-composite-foreignkey 1.1.0
File Size Uploaded
m3_django_composite_foreignkey-1.1.0.tar.gz 25.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for m3-django-composite-foreignkey 1.1.0
File Interpreter ABI Platform
m3_django_composite_foreignkey-1.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 48.0 kB

Release files / m3_django_composite_foreignkey-1.1.0.tar.gz

Download URL m3_django_composite_foreignkey-1.1.0.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6f1b625168e4c039885f04b29c5f162aee309d5fa07d00bcd9b028164ae72175
BLAKE2b-256 checksum
How to use checksums
0442d425c001e016d3d4bec4fab465a03d7e2f52b8609a78f769f9d523e9576a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / m3_django_composite_foreignkey-1.1.0-py2.py3-none-any.whl

Download URL m3_django_composite_foreignkey-1.1.0-py2.py3-none-any.whl
Size 22.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0db01ede6a4ecac235429e8784eebc4a7e0932045c2a490010fb4fa37ee20cde
BLAKE2b-256 checksum
How to use checksums
03fdac50b0a3e80b3f7cc839cbcfcd35140fb3885d1d9c8b3388c4a61209d165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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