Skip to main content

composite foreignkey support for django

Project description

Данный пакет - это 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

m3_django_composite_foreignkey-1.0.4.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

m3_django_composite_foreignkey-1.0.4-py2.py3-none-any.whl (22.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file m3_django_composite_foreignkey-1.0.4.tar.gz.

File metadata

File hashes

Hashes for m3_django_composite_foreignkey-1.0.4.tar.gz
Algorithm Hash digest
SHA256 cbe497545448e2106125c23a7b6d05bf11d2156ff17a3600d4be89e98ad9e0cd
MD5 1f43a186b9c7602896d9d1e61ab20bb7
BLAKE2b-256 21941de622d9b7dd17b68971d2855cb4e8b10b36278eb0f894a573c345e2a021

See more details on using hashes here.

File details

Details for the file m3_django_composite_foreignkey-1.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for m3_django_composite_foreignkey-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5019e67edefee12e1d27197a202abb71f1d4715bfd6997eefe35a2b050d2049f
MD5 15a74bfac6c9afb003b5d85aea3e8f75
BLAKE2b-256 3cde756b623301ee79b7a021f82f2c0be6efdc11a02b583409b1b424bc8a5ba2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page