Skip to content

Commit

Permalink
Merge pull request #303 from crucialfelix/feature/fixes-and-updates
Browse files Browse the repository at this point in the history
feature/fixes and updates
  • Loading branch information
crucialfelix committed Dec 6, 2023
2 parents 9bf8df4 + b48c8ae commit fe6cc15
Show file tree
Hide file tree
Showing 51 changed files with 35,131 additions and 574 deletions.
31 changes: 17 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Tests
on:
# Triggers the workflow on push or pull request events but only for the develop branch
push:
branches: [ develop ]
branches: [develop]
pull_request:
branches: [ develop ]
branches: [develop]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -22,18 +22,21 @@ jobs:

strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ["3.10", "3.11", "3.12"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check with ruff
uses: jpetrucciani/ruff-check@main
with:
path: "ajax_select"
- name: Install dependencies
run: |
python -m pip install ruff tox tox-gh-actions
- name: Test with tox
run: tox
44 changes: 0 additions & 44 deletions Makefile

This file was deleted.

53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

[![Build Status](https://travis-ci.org/crucialfelix/django-ajax-selects.svg?branch=master)](https://travis-ci.org/crucialfelix/django-ajax-selects) [![PyPI version](https://badge.fury.io/py/django-ajax-selects.svg)](https://badge.fury.io/py/django-ajax-selects)

This Django app glues Django Admin, jQuery UI together to enable searching and managing ForeignKey and ManyToMany relationships.

At the time it was created Django did not have any way to do this, and this solution glued together some technologies of the day.

If you are building a new project then you should not use this.

Django has built in support now:
https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields


---

![selecting](/docs/source/_static/kiss.png?raw=true)
Expand Down Expand Up @@ -31,7 +41,9 @@ Include the urls in your project:

```py
# urls.py
from django.conf.urls import url, include
from django.urls import path
from django.conf.urls import include

from django.conf.urls.static import static
from django.contrib import admin
from django.conf import settings
Expand All @@ -40,11 +52,10 @@ from ajax_select import urls as ajax_select_urls
admin.autodiscover()

urlpatterns = [

# place it at whatever base url you like
url(r'^ajax_select/', include(ajax_select_urls)),

url(r'^admin/', include(admin.site.urls)),
# This is the api endpoint that django-ajax-selects will call
# to lookup your model ids by name
path("admin/lookups/", include(ajax_select_urls)),
path("admin/", admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
```

Expand Down Expand Up @@ -107,14 +118,34 @@ Read the full documention here: [outside of the admin](http://django-ajax-select

## Assets included by default

* //ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'
* //code.jquery.com/ui/1.12.1/jquery-ui.js
* //code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css
https://jquery.com/ 3.7.1
https://jqueryui.com/ 1.13.2

## Customize jquery

To use a custom jQuery UI theme you can set:

```python
# settings.py
AJAX_SELECT_JQUERYUI_THEME = "/static/path-to-your-theme/jquery-ui-min.css"
```

https://jqueryui.com/themeroller/

If you need to use a different jQuery or jQuery UI then turn off the default assets:

```python
# settings.py
AJAX_SELECT_BOOTSTRAP = False
```

and include jquery and jquery-ui yourself, making sure they are loaded before the Django admin loads.


## Compatibility

* Django >=2.2
* Python >=3.6
* Django >=3.2
* Python >=3.10

## Contributors

Expand Down
11 changes: 7 additions & 4 deletions ajax_select/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class AjaxSelectAdmin(admin.ModelAdmin):
""" in order to get + popup functions subclass this or do the same hook inside of your get_form """
"""in order to get + popup functions subclass this or do the same hook inside of your get_form"""

def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
Expand All @@ -14,16 +14,19 @@ def get_form(self, request, obj=None, **kwargs):


class AjaxSelectAdminInlineFormsetMixin:

def get_formset(self, request, obj=None, **kwargs):
fs = super().get_formset(request, obj, **kwargs)
autoselect_fields_check_can_add(fs.form, self.model, request.user)
return fs


class AjaxSelectAdminTabularInline(AjaxSelectAdminInlineFormsetMixin, admin.TabularInline):
class AjaxSelectAdminTabularInline(
AjaxSelectAdminInlineFormsetMixin, admin.TabularInline
):
pass


class AjaxSelectAdminStackedInline(AjaxSelectAdminInlineFormsetMixin, admin.StackedInline):
class AjaxSelectAdminStackedInline(
AjaxSelectAdminInlineFormsetMixin, admin.StackedInline
):
pass

0 comments on commit fe6cc15

Please sign in to comment.