===========================
django-composite-foreignkey
===========================
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.
.. image:: https://img.shields.io/travis/onysos/django-composite-foreignkey/master.svg
:target: https://travis-ci.org/onysos/django-composite-foreignkey
.. image:: https://readthedocs.org/projects/django-composite-foreignkey/badge/?version=latest
:target: http://django-composite-foreignkey.readthedocs.org/en/latest/
.. image:: https://img.shields.io/coveralls/onysos/django-composite-foreignkey/master.svg
:target: https://coveralls.io/r/onysos/django-composite-foreignkey?branch=master
.. image:: https://img.shields.io/pypi/v/django-composite-foreignkey.svg
:target: https://pypi.python.org/pypi/django-composite-foreignkey
:alt: Latest PyPI version
.. image:: https://img.shields.io/pypi/dm/django-composite-foreignkey.svg
:target: https://pypi.python.org/pypi/django-composite-foreignkey
:alt: 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 <https://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys>`_ 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
.. code:: python
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
- Django 1.11, 2.0, 2.1
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 <https://github.com/ornoone>`_.
Thanks
------
Thanks to django for this amazing framework. And thanks to django-bootstrap3 to the structure of the apps.
Raw data
{
"_id": null,
"home_page": "https://github.com/onysos/django-composite-foreignkey",
"name": "django-composite-foreignkey",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django composite foreignkey",
"author": "Darius BERNARD",
"author_email": "contact@xornot.fr",
"download_url": "https://files.pythonhosted.org/packages/42/b0/9d55946d0a40463bd23c3743b8687964993b24a7d4dfdaea4ac7d965a491/django-composite-foreignkey-1.1.0.tar.gz",
"platform": "",
"description": "===========================\ndjango-composite-foreignkey\n===========================\n\n\n\nallow 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.\n\n\n.. image:: https://img.shields.io/travis/onysos/django-composite-foreignkey/master.svg\n :target: https://travis-ci.org/onysos/django-composite-foreignkey\n\n.. image:: https://readthedocs.org/projects/django-composite-foreignkey/badge/?version=latest\n :target: http://django-composite-foreignkey.readthedocs.org/en/latest/\n\n.. image:: https://img.shields.io/coveralls/onysos/django-composite-foreignkey/master.svg\n :target: https://coveralls.io/r/onysos/django-composite-foreignkey?branch=master\n\n.. image:: https://img.shields.io/pypi/v/django-composite-foreignkey.svg\n :target: https://pypi.python.org/pypi/django-composite-foreignkey\n :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/dm/django-composite-foreignkey.svg\n :target: https://pypi.python.org/pypi/django-composite-foreignkey\n :alt: Number of PyPI downloads per month\n\n\nsome databases have a composite Primary Key, leading to impossiblity for a django foreign key to be used.\n\ntoday, Django don't support Composite Primary Key `see ticket <https://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys>`_ and ForeignKey don't support multicolumn.\nbut fortunaly, the base class of ForeignKey support it well, so this lib just add a little wrapper around ForeignObject to make it more usefull.\nthe real add of this implementation is that is support the customisation of the link with Raw values.\n\nthis 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.\n\nInstallation\n------------\n\n1. Install using pip:\n\n ``pip install django-composite-foreignkey``\n\n2. Alternatively, you can install download or clone this repo and call\n\n ``pip install -e .``.\n\n\n\nExample\n-------\n\n\nyou have this model\n\n.. code:: python\n\n class Customer(models.Model):\n\n company = models.IntegerField()\n customer_id = models.IntegerField()\n name = models.CharField(max_length=255)\n address = CompositeForeignKey(Address, on_delete=CASCADE, to_fields={\n \"tiers_id\": \"customer_id\",\n \"company\": LocalFieldValue(\"company\"),\n \"type_tiers\": RawFieldValue(\"C\")\n })\n\n class Meta(object):\n unique_together = [\n (\"company\", \"customer_id\"),\n ]\n\n\n class Contact(models.Model):\n company_code = models.IntegerField()\n customer_code = models.IntegerField()\n surname = models.CharField(max_length=255)\n # virtual field\n customer = CompositeForeignKey(Customer, on_delete=CASCADE, related_name='contacts', to_fields={\n \"customer_id\": \"customer_code\",\n \"company\": \"company_code\"\n })\n\n\nyou can use Contact.customer like any ForeignKey, but behinde the scene, it will query the Customer Table using company and customer id's.\n\n\nDocumentation\n-------------\n\nThe full documentation is at http://django-composite-foreignkey.readthedocs.org/en/latest/.\n\n\nRequirements\n------------\n\n- Python 2.7, 3.4, 3.5, 3.6, 3.7\n- Django 1.11, 2.0, 2.1\n\nContributions and pull requests for other Django and Python versions are welcome.\n\n\nBugs and requests\n-----------------\n\nIf you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.\n\nhttps://github.com/onysos/django-composite-foreignkey/issues\n\n\nLicense\n-------\n\nYou can use this under GPLv3.\n\nAuthor\n------\n\nOriginal author & Development lead: `Darius BERNARD <https://github.com/ornoone>`_.\n\n\nThanks\n------\n\nThanks to django for this amazing framework. And thanks to django-bootstrap3 to the structure of the apps.\n",
"bugtrack_url": null,
"license": "GNU GENERAL PUBLIC LICENSE",
"summary": "composite foreignkey support for django",
"version": "1.1.0",
"split_keywords": [
"django",
"composite",
"foreignkey"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "0f2babaa8f9801770c87f21293319542",
"sha256": "572b0ec22aa3ac15e751d1d2b8acadba372503e8a17d829303af289bd013f41c"
},
"downloads": -1,
"filename": "django-composite-foreignkey-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0f2babaa8f9801770c87f21293319542",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 21130,
"upload_time": "2018-08-13T08:34:09",
"upload_time_iso_8601": "2018-08-13T08:34:09.347021Z",
"url": "https://files.pythonhosted.org/packages/42/b0/9d55946d0a40463bd23c3743b8687964993b24a7d4dfdaea4ac7d965a491/django-composite-foreignkey-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2018-08-13 08:34:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "onysos",
"github_project": "django-composite-foreignkey",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Django",
"specs": [
[
"<",
"2.1"
]
]
},
{
"name": "wheel",
"specs": []
},
{
"name": "sphinx",
"specs": []
},
{
"name": "mock",
"specs": []
}
],
"tox": true,
"lcname": "django-composite-foreignkey"
}