{"id":22940565,"url":"https://github.com/dmptrluke/django-published","last_synced_at":"2026-05-17T06:39:39.158Z","repository":{"id":57421395,"uuid":"230834310","full_name":"dmptrluke/django-published","owner":"dmptrluke","description":"Control public visibility of model instances","archived":false,"fork":false,"pushed_at":"2023-08-31T01:38:46.000Z","size":662,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-25T05:33:16.887Z","etag":null,"topics":["django","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmptrluke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-30T02:37:06.000Z","updated_at":"2023-08-31T01:38:26.000Z","dependencies_parsed_at":"2024-12-22T15:39:07.421Z","dependency_job_id":"20ba9d36-f5d8-427d-bf38-f3c5e903fb70","html_url":"https://github.com/dmptrluke/django-published","commit_stats":{"total_commits":76,"total_committers":3,"mean_commits":"25.333333333333332","dds":"0.26315789473684215","last_synced_commit":"d918f0aa4d30a1c823a062d867fbdc40a86eb51c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/dmptrluke/django-published","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmptrluke%2Fdjango-published","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmptrluke%2Fdjango-published/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmptrluke%2Fdjango-published/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmptrluke%2Fdjango-published/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmptrluke","download_url":"https://codeload.github.com/dmptrluke/django-published/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmptrluke%2Fdjango-published/sbom","scorecard":{"id":348306,"data":{"date":"2025-08-11","repo":{"name":"github.com/dmptrluke/django-published","commit":"53109cb8db9f04497c62c0aa09f396989d107fec"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T07:42:28.497Z","repository_id":57421395,"created_at":"2025-08-18T07:42:28.497Z","updated_at":"2025-08-18T07:42:28.497Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281047796,"owners_count":26435124,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["django","python"],"created_at":"2024-12-14T13:23:20.671Z","updated_at":"2026-05-17T06:39:39.152Z","avatar_url":"https://github.com/dmptrluke.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Published [![PyPI](https://img.shields.io/pypi/v/django-published)](https://pypi.org/project/django-published/)\n\nPublished allows you to control the public visibility of model instances.\nUseful in situations like below!\n\n    You have a model where some number of instances of the model should\n    be \"live\". A good example of this would be an Article model, where\n    you've written some articles that are \"live\", some that might've\n    been taken down, some that are still \"in progress\", and others that\n    are ready to \"go live\", but have a \"go live\" date that's in the\n    future.\n\n\nThis project is based on [django-model-gatekeeper](https://github.com/WGBH/django-model-gatekeeper) by\n[WGBH](https://github.com/WGBH/).\n\n# Getting Started\n\n## Installation\n\n1.  Add \"published\" to your `INSTALLED_APPS`:\n```python\nINSTALLED_APPS = [\n    ...\n    'published',\n]\n```\n\n## Setting Up Models\n\nThe main use for *django-published* is where you have a model with many\ninstances, but you only want some to be \"live\" on the site.\n\nA good example is a generic \"Article\" model:\n\n\u003e   - Some articles are ready-to-go and you want them live to the\n\u003e     public;\n\u003e   - Other articles are still being worked on - you want to be able to\n\u003e     preview them, but not take them live JUST yet;\n\u003e   - Some articles might be pulled (and re-published later)\n\u003e   - Some articles are ready to be published, but you want them to only\n\u003e     go live at a later date.\n\nTo start using this, all you need to do is subclass the\n`PublishedModel` abstract model,\ne.g:\n\n```python\nfrom published.models import PublishedModel\n\nclass Article(PublishedModel):\n    ...\n```\n\nThe superclass creates two fields:\n\n1.  `publish_status` - this has 3 possible values:\n       - **NEVER_AVAILABLE** = \"permanently off\" - hard-wired to NEVER be available to\n         the public\n       - **AVAILABLE_AFTER** = \"use live_as_of\" date to determine if the object is\n         available to the public\n       - **AVAILABLE** = \"always on\" - hard-wired to be always available to the\n         public\n\n\n2.  `live_as_of` - this is the timestamp of when the object should go live, if publish_status\n    is **AVAILABLE_AFTER**\n\n\n\nYou set the `publish_status` and `live_as_of` values through the admin.\n\n# The Frontend\n\n## Generic Model Views\n\nSetting up _django-published_ for generic models views is easy!\n\nUsing the Article model as an example, here is the corresponding\nview code for  listing and detail views.\n\n```python\nfrom django.views.generic import DetailView, ListView\nfrom .models import Article\nfrom published.mixins import PublishedListMixin, PublishedDetailMixin\n\nclass ArticleListView(PublishedListMixin, ListView):\n    model = Article\n    template_name = 'article/article_list.html'\n    context_object_name = 'articles'\n\nclass ArticleDetailView(PublishedDetailMixin, DetailView):\n    model = Article\n    template_name = 'article/article_detail.html'\n    context_object_name = 'article'\n```\n\n\nWhat's happening behind the scenes:\n\n1.  In the ListView, *django-published* is filtering the model with the\n    following rules:\n\n     1.  If the current user has admin access, always include the model instance.\n     2.  If `publish_status = AVAILABLE`, include the model instance.\n     3.  If `publish_status = NEVER_AVAILABLE`, DO NOT the model instance.\n     4.  If `publish_status = AVAILABLE_AFTER`, *and* the current date/time is after\n         `live_as_of`, include the model instance.\n     4.  Return the filtered list of model instances.\n\n2.  In the DetailView, *django-published* follows the same rules but will\n    throw a 404 error if the model instance is not available.\n\n## Custom Code\n\nSay there's a section on your homepage that gives a list of the three\nmost recent articles. If you just create a queryset along the lines of:\n\n    most_recent_articles = Article.objects.order_by(-date_created)[:3]\n\nit will include articles regardless of what their gatekeeping situation\nis.\n\nSo there is a helper function to apply the gatekeeping rules to any\nqueryset you generate.\n\n#### queryset_filter\nThis takes a queryset, applies the rules and returns a filtered queryset.\n\n```python\nfrom published.utils import queryset_filter\n...\nrecent_articles = Article.objects.order_by('-date_created')\nrecent_articles = queryset_filter(recent_articles, is_auth)\n...\n```\n\n\nBy default, `queryset_filter` does not apply the same exceptions as the view\nmixins above. This means that unpublished model instances will be *not* displayed\nif the current user has admin access.\n\nThe optional `user` parameter allows you to enable this special case, as seen below.\n```python\nqueryset_filter(queryset, user=self.request.user)\n```\n\n#### available_to_public\n\n**Note**: This should only be used in templates\n\nIf you need to check if an object is considered \"available\" in a Django template, you can use the\n`available_to_public` model attribute, as below.\n\n```djangotemplate\n{% for article in article_list %}\n    {% if article.available_to_public %}\n        I'm published!\n    {% endif %}\n{% endfor %}\n```\n\n# The Admin Interface\n\n*django-published* has several helper functions to make adding admin controls easier.\nAll of them can be found in the  `django-published.admin` module.\n\n![alt test](https://raw.githubusercontent.com/dmptrluke/django-published/master/screenshots/admin.png)\n\n## Setting Up\nAll of the below functions require the use of the `PublishedAdmin` abstract class instead\nof the default `ModelAdmin` class. You can see examples of this in all of the code below.\n\nAdditionally, `add_to_readonly_fields` also needs to be added to `readonly_fields` to provide some of \nthe fields needed later on.\n\n```python\nfrom published.admin import PublishedAdmin\n\nclass ArticleAdmin(PublishedAdmin):\n    readonly_fields = ['my_field_1', 'my_field_2'] + add_to_readonly_fields()\n    ...\n```\n\n## Adding to List View\n\nTo show the status in an admin list view, `show_publish_status` needs to be added to\n`list_display`\n\nThis can be added automatically with the `add_to_list_display` method, e.g.:\n\n```python\nfrom published.admin import PublishedAdmin, add_to_list_display\n\nclass ArticleAdmin(PublishedAdmin):\n    list_display = ['pk', 'title', ] + add_to_list_display()\n```\n\n## Adding to Edit View\n\nTo add the admin controls to your model, use `add_to_fieldsets`. The `collapse` attribute can be used \nto make the controls hidden by default.\n\n```python\nfrom published.admin import PublishedAdmin, add_to_fieldsets\n\nclass MyModelAdmin(PublishedAdmin):\n    fieldsets = (\n        (None, ...),\n        add_to_fieldsets(section=True, collapse=False)\n    )\n```\n\nIf you don't want to use `add-to_fieldsets`, you can also add the fields manually, with the editable `live_as_of`, `publish_status` fields and the readonly\n`show_publish_status` field.\n\n## License\n\nThis software is released under the MIT license.\n```\nCopyright (c) 2019 WGBH Educational Foundation\nCopyright (c) 2019-2026 Luke Rogers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmptrluke%2Fdjango-published","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmptrluke%2Fdjango-published","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmptrluke%2Fdjango-published/lists"}