{"id":20797679,"url":"https://github.com/beachmachine/django-userforeignkey","last_synced_at":"2025-05-06T18:43:44.620Z","repository":{"id":46125271,"uuid":"56316563","full_name":"beachmachine/django-userforeignkey","owner":"beachmachine","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-25T14:47:03.000Z","size":56,"stargazers_count":22,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T20:19:52.284Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beachmachine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-15T11:54:06.000Z","updated_at":"2024-10-25T04:19:37.000Z","dependencies_parsed_at":"2022-07-26T08:17:01.809Z","dependency_job_id":null,"html_url":"https://github.com/beachmachine/django-userforeignkey","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fdjango-userforeignkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fdjango-userforeignkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fdjango-userforeignkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beachmachine%2Fdjango-userforeignkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beachmachine","download_url":"https://codeload.github.com/beachmachine/django-userforeignkey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252747313,"owners_count":21798127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-11-17T16:34:54.086Z","updated_at":"2025-05-06T18:43:44.574Z","avatar_url":"https://github.com/beachmachine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Django UserForeignKey\n=====================\n\n[![PyPI version](https://img.shields.io/pypi/v/django-userforeignkey.svg?maxAge=2592000)](https://pypi.org/project/django-userforeignkey/)\n[![Linter and tests](https://github.com/beachmachine/django-userforeignkey/workflows/Module%20tests/badge.svg)](https://github.com/beachmachine/django-userforeignkey/actions)\n[![Codecov](https://img.shields.io/codecov/c/gh/beachmachine/django-userforeignkey)](https://codecov.io/gh/beachmachine/django-userforeignkey)\n\nDjango UserForeignKey is a simple Django app that will give you a `UserForeignKey` model field for Django models.\nThis field extends a regular ForeignKey model field, and has the option to automatically set the currently logged in \nuser on insert and/or update.\n\nCurrently, Django 3.2 (Python 3.7+) and Django 4.0 \u0026 4.1 (Python 3.8+) are supported.\n\nIf you need support for the insecure and deprecated Python 3.6, please fall back to version 0.4.0.\n\nIf you need support for the insecure and deprecated Django 1.11 and/or Python2, please fall back to version 0.3.0.\n\nIf you need support for the insecure and deprecated Django 1.8 (and possibly 1.9 and 1.10), please fall back to \nversion 0.2.1.\n\nThere also is a [video tutorial on YouTube](https://www.youtube.com/watch?v=iJCbYMgUDW8\u003e) that shows you basic \nfunctionality of this package.\n\n## Quickstart\n\n1. Install the package from pypi using pip:\n```bash\npip install django-userforeignkey\n```\n\n2. Add `django_userforeignkey` to your `INSTALLED_APPS` within your Django settings file:\n```python\nINSTALLED_APPS = [\n    ...\n    'django_userforeignkey',\n]\n```\n\n3. Add `django_userforeignkey.middleware.UserForeignKeyMiddleware` to your `MIDDLEWARE` settings like this:\n\n```python\nMIDDLEWARE = [\n    ...\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    ...\n    'django_userforeignkey.middleware.UserForeignKeyMiddleware',\n]\n```\n\nMake sure to insert the `UserForeignKeyMiddleware` middleware **after** `AuthenticationMiddleware`.\n\n## Example usage\n\nJust add `UserForeignKey` to your model like you would with any other foreign key.\n\n\n```python\nfrom django.db import models\nfrom django_userforeignkey.models.fields import UserForeignKey\n\nclass MyModel(models.Model):\n    my_data = models.CharField(max_length=64, verbose_name=\"Very important data that are somehow related to a user\")\n    user = UserForeignKey(auto_user_add=True, verbose_name=\"The user that is automatically assigned\", related_name=\"mymodels\")\n```\n\nThe `UserForeignKey` behaves just like a normal foreign key to the user model (using `settings.AUTH_USER_MODEL`), and \nthus also has properties such as ``related_name``. However, whenever an object is created by calling an authenticated \nview (admin, REST API, ...) which contains a ``request.user`` object, the ``request.user`` object is automatically \nassociated.\n\n\n## Configuration options\n\nThe configuration options are similar to Django's [DateField](https://docs.djangoproject.com/en/4.1/ref/models/fields/#datefield).\n\n* `auto_user`: Automatically sets the current user everytime the object is saved (e.g., created or updated). This is \n  useful for **last modified by** information.\n* `auto_user_add`: Automatically sets the current user when the object is first created. This is useful \n  for **created by** information.\n\n\n## Development and tests\n\n```bash\ngit clone --recursive https://github.com/beachmachine/django-userforeignkey\ncd django-userforeignkey\npython -m venv ./venv\nsource venv/bin/activate\npip install -e .\npip install Django\ncd tests/user_foreign_key_testapp\npython manage.py test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeachmachine%2Fdjango-userforeignkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeachmachine%2Fdjango-userforeignkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeachmachine%2Fdjango-userforeignkey/lists"}