├── .gitignore ├── .idea ├── $CACHE_FILE$ └── .gitignore ├── README.rst ├── demo ├── app │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── fixtures │ │ └── demo.json │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── serializers.py │ ├── tests.py │ └── views.py ├── demo │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── django_react_admin ├── manage.py ├── requirements.txt ├── run.sh └── static │ └── __git__ ├── django_react_admin ├── __init__.py ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── build_react_admin.py ├── metadata.py ├── migrations │ └── __init__.py ├── models.py ├── src │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── serviceWorker.js │ │ └── users.js │ ├── webpack.config.js │ └── yarn.lock ├── static │ ├── __git__ │ └── __init__.py ├── templates │ └── django_react_admin │ │ └── index.html ├── tests.py ├── urls.py ├── utils.py └── views.py ├── poetry.lock ├── pyproject.toml ├── requirements.txt ├── setup.py └── tests ├── __init__.py └── test_django_vue_admin.py /.gitignore: -------------------------------------------------------------------------------- 1 | /old/ 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /.idea/$CACHE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Add django_react_admin to your INSTALLED_APPS 2 | 3 | Add path('react_admin/', include(django_react_admin.urls.urlpatterns)) to your urls 4 | 5 | APIs would be exposed at /react_admin/api/ and /react_admin/ would be html with react-admin 6 | 7 | Run ./manage.py build_react_admin 8 | 9 | Your STATIC_URL should be /static/ -------------------------------------------------------------------------------- /demo/app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/demo/app/__init__.py -------------------------------------------------------------------------------- /demo/app/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import * 3 | 4 | admin.site.register(Book) 5 | admin.site.register(Publisher) 6 | admin.site.register(Author) 7 | -------------------------------------------------------------------------------- /demo/app/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AppConfig(AppConfig): 5 | name = 'app' 6 | -------------------------------------------------------------------------------- /demo/app/fixtures/demo.json: -------------------------------------------------------------------------------- 1 | [{"model": "app.publisher", "pk": 1, "fields": {"name": "pub", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.publisher", "pk": 2, "fields": {"name": "pub 0", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.publisher", "pk": 3, "fields": {"name": "pub 1", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.publisher", "pk": 4, "fields": {"name": "pub 2", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.publisher", "pk": 5, "fields": {"name": "pub 3", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.publisher", "pk": 6, "fields": {"name": "pub 4", "info": null, "address": "", "city": "", "state_province": "", "country": "", "website": ""}}, {"model": "app.author", "pk": 1, "fields": {"salutation": "", "name": "foo", "email": "", "headshot": ""}}, {"model": "app.author", "pk": 2, "fields": {"salutation": "", "name": "author 0", "email": "", "headshot": ""}}, {"model": "app.author", "pk": 3, "fields": {"salutation": "", "name": "author 1", "email": "", "headshot": ""}}, {"model": "app.author", "pk": 4, "fields": {"salutation": "", "name": "author 2", "email": "", "headshot": ""}}, {"model": "app.author", "pk": 5, "fields": {"salutation": "", "name": "author 3", "email": "", "headshot": ""}}, {"model": "app.author", "pk": 6, "fields": {"salutation": "", "name": "author 4", "email": "", "headshot": ""}}, {"model": "app.book", "pk": 1, "fields": {"title": "book1", "description": null, "summary": null, "publisher": 1, "publication_date": "2019-12-05", "state": "published", "isbn": "", "price": "666.00", "pages": 200, "stock_count": 30, "authors": [], "tags": []}}, {"model": "app.book", "pk": 2, "fields": {"title": "Book 0", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "af", "price": "373.00", "pages": 200, "stock_count": 30, "authors": [3, 6], "tags": []}}, {"model": "app.book", "pk": 3, "fields": {"title": "Book 0", "description": null, "summary": null, "publisher": 2, "publication_date": "2019-12-05", "state": "published", "isbn": "20769504", "price": "124.00", "pages": 200, "stock_count": 30, "authors": [3, 4, 5], "tags": []}}, {"model": "app.book", "pk": 4, "fields": {"title": "Book 1", "description": null, "summary": null, "publisher": 5, "publication_date": "2019-12-05", "state": "published", "isbn": "13420336", "price": "73.00", "pages": 200, "stock_count": 30, "authors": [2, 4], "tags": []}}, {"model": "app.book", "pk": 5, "fields": {"title": "Book 2", "description": null, "summary": null, "publisher": 6, "publication_date": "2019-12-05", "state": "published", "isbn": "12497262", "price": "604.00", "pages": 200, "stock_count": 30, "authors": [2, 4, 5], "tags": []}}, {"model": "app.book", "pk": 6, "fields": {"title": "Book 3", "description": null, "summary": null, "publisher": 3, "publication_date": "2019-12-05", "state": "published", "isbn": "22093667", "price": "83.00", "pages": 200, "stock_count": 30, "authors": [5], "tags": []}}, {"model": "app.book", "pk": 7, "fields": {"title": "Book 4", "description": null, "summary": null, "publisher": 6, "publication_date": "2019-12-05", "state": "published", "isbn": "5315195", "price": "130.00", "pages": 200, "stock_count": 30, "authors": [2, 3], "tags": []}}, {"model": "app.book", "pk": 8, "fields": {"title": "Book 5", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "22520749", "price": "16.00", "pages": 200, "stock_count": 30, "authors": [4], "tags": []}}, {"model": "app.book", "pk": 9, "fields": {"title": "Book 6", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "2326217", "price": "2.00", "pages": 200, "stock_count": 30, "authors": [2], "tags": []}}, {"model": "app.book", "pk": 10, "fields": {"title": "Book 7", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "8079172", "price": "514.00", "pages": 200, "stock_count": 30, "authors": [3, 4, 5], "tags": []}}, {"model": "app.book", "pk": 11, "fields": {"title": "Book 8", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "14415379", "price": "396.00", "pages": 200, "stock_count": 30, "authors": [4], "tags": []}}, {"model": "app.book", "pk": 12, "fields": {"title": "Book 9", "description": null, "summary": null, "publisher": 2, "publication_date": "2019-12-05", "state": "published", "isbn": "5419671", "price": "568.00", "pages": 200, "stock_count": 30, "authors": [2, 6], "tags": []}}, {"model": "app.book", "pk": 13, "fields": {"title": "Book 10", "description": null, "summary": null, "publisher": 3, "publication_date": "2019-12-05", "state": "published", "isbn": "2307138", "price": "345.00", "pages": 200, "stock_count": 30, "authors": [5, 6], "tags": []}}, {"model": "app.book", "pk": 14, "fields": {"title": "Book 11", "description": null, "summary": null, "publisher": 3, "publication_date": "2019-12-05", "state": "published", "isbn": "19851838", "price": "280.00", "pages": 200, "stock_count": 30, "authors": [2, 3], "tags": []}}, {"model": "app.book", "pk": 15, "fields": {"title": "Book 12", "description": null, "summary": null, "publisher": 3, "publication_date": "2019-12-05", "state": "published", "isbn": "8354189", "price": "237.00", "pages": 200, "stock_count": 30, "authors": [6], "tags": []}}, {"model": "app.book", "pk": 16, "fields": {"title": "Book 13", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "19188079", "price": "126.00", "pages": 200, "stock_count": 30, "authors": [2], "tags": []}}, {"model": "app.book", "pk": 17, "fields": {"title": "Book 14", "description": null, "summary": null, "publisher": 4, "publication_date": "2019-12-05", "state": "published", "isbn": "10109671", "price": "515.00", "pages": 200, "stock_count": 30, "authors": [4, 6], "tags": []}}, {"model": "app.book", "pk": 18, "fields": {"title": "Book 15", "description": null, "summary": null, "publisher": 5, "publication_date": "2019-12-05", "state": "published", "isbn": "436908", "price": "538.00", "pages": 200, "stock_count": 30, "authors": [4, 5, 6], "tags": []}}, {"model": "app.book", "pk": 19, "fields": {"title": "Book 16", "description": null, "summary": null, "publisher": 6, "publication_date": "2019-12-05", "state": "published", "isbn": "16138034", "price": "451.00", "pages": 200, "stock_count": 30, "authors": [2, 3, 6], "tags": []}}, {"model": "app.book", "pk": 20, "fields": {"title": "Book 17", "description": null, "summary": null, "publisher": 5, "publication_date": "2019-12-05", "state": "published", "isbn": "23158642", "price": "546.00", "pages": 200, "stock_count": 30, "authors": [2, 3, 5], "tags": []}}, {"model": "app.book", "pk": 21, "fields": {"title": "Book 18", "description": null, "summary": null, "publisher": 2, "publication_date": "2019-12-05", "state": "published", "isbn": "14273532", "price": "520.00", "pages": 200, "stock_count": 30, "authors": [3, 5], "tags": []}}, {"model": "app.book", "pk": 22, "fields": {"title": "Book 19", "description": null, "summary": null, "publisher": 3, "publication_date": "2019-12-05", "state": "published", "isbn": "9147370", "price": "63.00", "pages": 200, "stock_count": 30, "authors": [3], "tags": []}}] -------------------------------------------------------------------------------- /demo/app/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.2.8 on 2019-12-05 16:09 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Author', 17 | fields=[ 18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('salutation', models.CharField(max_length=10)), 20 | ('name', models.CharField(max_length=200)), 21 | ('email', models.EmailField(max_length=254)), 22 | ('headshot', models.ImageField(blank=True, null=True, upload_to='authors')), 23 | ], 24 | options={ 25 | 'ordering': ['id'], 26 | }, 27 | ), 28 | migrations.CreateModel( 29 | name='Publisher', 30 | fields=[ 31 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 32 | ('name', models.CharField(max_length=30)), 33 | ('info', models.TextField(blank=True, null=True)), 34 | ('address', models.CharField(max_length=50)), 35 | ('city', models.CharField(max_length=60)), 36 | ('state_province', models.CharField(max_length=30)), 37 | ('country', models.CharField(max_length=50)), 38 | ('website', models.URLField()), 39 | ], 40 | options={ 41 | 'ordering': ['id'], 42 | }, 43 | ), 44 | migrations.CreateModel( 45 | name='Tag', 46 | fields=[ 47 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 48 | ('title', models.CharField(max_length=255, unique=True)), 49 | ], 50 | options={ 51 | 'verbose_name': 'Tag', 52 | 'verbose_name_plural': 'Tags', 53 | }, 54 | ), 55 | migrations.CreateModel( 56 | name='Book', 57 | fields=[ 58 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 59 | ('title', models.CharField(max_length=100)), 60 | ('description', models.TextField(blank=True, null=True)), 61 | ('summary', models.TextField(blank=True, null=True)), 62 | ('publication_date', models.DateField()), 63 | ('state', models.CharField(choices=[('published', 'Published'), ('not_published', 'Not published'), ('in_progress', 'In progress'), ('cancelled', 'Cancelled'), ('rejected', 'Rejected')], default='published', max_length=100)), 64 | ('isbn', models.CharField(max_length=100, unique=True)), 65 | ('price', models.DecimalField(decimal_places=2, max_digits=10)), 66 | ('pages', models.PositiveIntegerField(default=200)), 67 | ('stock_count', models.PositiveIntegerField(default=30)), 68 | ('authors', models.ManyToManyField(related_name='books', to='app.Author')), 69 | ('publisher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='books', to='app.Publisher')), 70 | ('tags', models.ManyToManyField(blank=True, related_name='books', to='app.Tag')), 71 | ], 72 | options={ 73 | 'ordering': ['isbn'], 74 | }, 75 | ), 76 | ] 77 | -------------------------------------------------------------------------------- /demo/app/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/demo/app/migrations/__init__.py -------------------------------------------------------------------------------- /demo/app/models.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | from django.utils.translation import ugettext, ugettext_lazy as _ 4 | 5 | 6 | BOOK_PUBLISHING_STATUS_PUBLISHED = 'published' 7 | BOOK_PUBLISHING_STATUS_NOT_PUBLISHED = 'not_published' 8 | BOOK_PUBLISHING_STATUS_IN_PROGRESS = 'in_progress' 9 | BOOK_PUBLISHING_STATUS_CANCELLED = 'cancelled' 10 | BOOK_PUBLISHING_STATUS_REJECTED = 'rejected' 11 | BOOK_PUBLISHING_STATUS_CHOICES = ( 12 | (BOOK_PUBLISHING_STATUS_PUBLISHED, "Published"), 13 | (BOOK_PUBLISHING_STATUS_NOT_PUBLISHED, "Not published"), 14 | (BOOK_PUBLISHING_STATUS_IN_PROGRESS, "In progress"), 15 | (BOOK_PUBLISHING_STATUS_CANCELLED, "Cancelled"), 16 | (BOOK_PUBLISHING_STATUS_REJECTED, "Rejected"), 17 | ) 18 | BOOK_PUBLISHING_STATUS_DEFAULT = BOOK_PUBLISHING_STATUS_PUBLISHED 19 | 20 | 21 | class Publisher(models.Model): 22 | """Publisher.""" 23 | 24 | name = models.CharField(max_length=30) 25 | info = models.TextField(null=True, blank=True) 26 | address = models.CharField(max_length=50) 27 | city = models.CharField(max_length=60) 28 | state_province = models.CharField(max_length=30) 29 | country = models.CharField(max_length=50) 30 | website = models.URLField() 31 | 32 | class Meta(object): 33 | """Meta options.""" 34 | 35 | ordering = ["id"] 36 | 37 | def __str__(self): 38 | return self.name 39 | 40 | 41 | class Author(models.Model): 42 | """Author.""" 43 | 44 | salutation = models.CharField(max_length=10) 45 | name = models.CharField(max_length=200) 46 | email = models.EmailField() 47 | headshot = models.ImageField(upload_to='authors', null=True, blank=True) 48 | 49 | class Meta(object): 50 | """Meta options.""" 51 | 52 | ordering = ["id"] 53 | 54 | def __str__(self): 55 | return self.name 56 | 57 | 58 | class Tag(models.Model): 59 | """Simple tag model.""" 60 | 61 | title = models.CharField(max_length=255, unique=True) 62 | 63 | class Meta(object): 64 | """Meta options.""" 65 | 66 | verbose_name = _("Tag") 67 | verbose_name_plural = _("Tags") 68 | 69 | def __str__(self): 70 | return self.title 71 | 72 | 73 | class Book(models.Model): 74 | """Book.""" 75 | 76 | title = models.CharField(max_length=100) 77 | description = models.TextField(null=True, blank=True) 78 | summary = models.TextField(null=True, blank=True) 79 | authors = models.ManyToManyField('app.Author', related_name='books') 80 | publisher = models.ForeignKey(Publisher, related_name='books', on_delete=models.CASCADE) 81 | publication_date = models.DateField() 82 | state = models.CharField(max_length=100, 83 | choices=BOOK_PUBLISHING_STATUS_CHOICES, 84 | default=BOOK_PUBLISHING_STATUS_DEFAULT) 85 | isbn = models.CharField(max_length=100, unique=True) 86 | price = models.DecimalField(max_digits=10, decimal_places=2) 87 | pages = models.PositiveIntegerField(default=200) 88 | stock_count = models.PositiveIntegerField(default=30) 89 | tags = models.ManyToManyField('app.Tag', 90 | related_name='books', 91 | blank=True) 92 | 93 | class Meta(object): 94 | """Meta options.""" 95 | 96 | ordering = ["isbn"] 97 | 98 | def __str__(self): 99 | return self.title 100 | 101 | @property 102 | def publisher_indexing(self): 103 | """Publisher for indexing. 104 | 105 | Used in Elasticsearch indexing. 106 | """ 107 | if self.publisher is not None: 108 | return self.publisher.name 109 | 110 | -------------------------------------------------------------------------------- /demo/app/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Book, Author, Publisher 3 | 4 | 5 | def get_serializer_class(model, fields="__all__", **kwargs): 6 | return type( 7 | f"{model.__name__}Serializer", 8 | (serializers.ModelSerializer,), 9 | dict(**kwargs, **{"Meta": type("Meta", (), {"model": model, "fields": fields})}), 10 | ) 11 | 12 | AuthorSerializer = get_serializer_class(Author, ['id', 'name', 'email'], depth=2) 13 | AuthorSerializer.Meta.fields = ['id', 'name', 'email'] 14 | PublisherSerializer = get_serializer_class(Publisher) 15 | BookSerializer = get_serializer_class(Book, ['authors'], authors=AuthorSerializer(Author.objects.all(), many=True), publisher=PublisherSerializer(), depth=2) 16 | BookSerializer.Meta.fields = ['id', 'title', 'authors', 'publisher'] 17 | -------------------------------------------------------------------------------- /demo/app/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /demo/app/views.py: -------------------------------------------------------------------------------- 1 | from rest_framework import viewsets 2 | from .models import * 3 | from .serializers import get_serializer_class 4 | from django_filters.rest_framework import DjangoFilterBackend, OrderingFilter 5 | 6 | 7 | class BookViewSet(viewsets.ModelViewSet): 8 | queryset = Book.objects.all() 9 | serializer_class = get_serializer_class(Book) 10 | 11 | 12 | class AuthorViewSet(viewsets.ModelViewSet): 13 | queryset = Author.objects.all() 14 | serializer_class = get_serializer_class(Author) 15 | filter_backends = [DjangoFilterBackend] 16 | filterset_fields = ['book_set'] 17 | 18 | class PublisherViewSet(viewsets.ModelViewSet): 19 | queryset = Publisher.objects.all() 20 | serializer_class = get_serializer_class(Publisher) 21 | 22 | -------------------------------------------------------------------------------- /demo/demo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/demo/demo/__init__.py -------------------------------------------------------------------------------- /demo/demo/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for demo project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.2/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'svqee=-&*v-jzci0l+blvw@kvtkn$9pui+7y6mqcw^s_xv@*i)' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'rest_framework', 41 | 'django_filters', 42 | 'django_react_admin', 43 | 'app', 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'demo.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'demo.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators 90 | 91 | AUTH_PASSWORD_VALIDATORS = [ 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 103 | }, 104 | ] 105 | 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/2.2/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_L10N = True 117 | 118 | USE_TZ = True 119 | 120 | 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/2.2/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | STATIC_ROOT = 'static/' 126 | 127 | # REST_FRAMEWORK = { 128 | # 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 129 | # 'PAGE_SIZE': 10 130 | # } -------------------------------------------------------------------------------- /demo/demo/urls.py: -------------------------------------------------------------------------------- 1 | """demo URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | from django_react_admin import urls 19 | from django.conf.urls.static import static 20 | from rest_framework.routers import DefaultRouter 21 | from app.views import * 22 | 23 | router = DefaultRouter() 24 | router.register('books', BookViewSet, 'books') 25 | router.register('authors', AuthorViewSet) 26 | router.register('publishers', PublisherViewSet) 27 | 28 | urlpatterns = [ 29 | path('admin/', admin.site.urls), 30 | path('react_admin/', include(urls.urlpatterns)), 31 | ] + router.urls 32 | -------------------------------------------------------------------------------- /demo/demo/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for demo project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /demo/django_react_admin: -------------------------------------------------------------------------------- 1 | ../django_react_admin/ -------------------------------------------------------------------------------- /demo/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /demo/requirements.txt: -------------------------------------------------------------------------------- 1 | django==2.*,>=2.2.0 2 | django-filters==0.*,>=0.2.1 3 | djangorestframework==3.*,>=3.10.0 4 | pytest==3.*,>=3.0.0 5 | Pillow 6 | -------------------------------------------------------------------------------- /demo/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | python -m venv venv 3 | source venv/bin/activate 4 | pip install -r requirements.txt 5 | python manage.py migrate 6 | python manage.py build_react_admin 7 | python manage.py loaddata demo 8 | python manage.py runserver 9 | -------------------------------------------------------------------------------- /demo/static/__git__: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/demo/static/__git__ -------------------------------------------------------------------------------- /django_react_admin/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/__init__.py -------------------------------------------------------------------------------- /django_react_admin/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/management/__init__.py -------------------------------------------------------------------------------- /django_react_admin/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/management/commands/__init__.py -------------------------------------------------------------------------------- /django_react_admin/management/commands/build_react_admin.py: -------------------------------------------------------------------------------- 1 | import subprocess, os, sys 2 | 3 | from django.core.management.base import BaseCommand 4 | from django.core import management 5 | 6 | 7 | class Command(BaseCommand): 8 | help = 'Build react-admin' 9 | 10 | def handle(self, *args, **options): 11 | cwd = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../src') 12 | ps = subprocess.Popen("yarn install", shell=True, cwd=cwd) 13 | ps.wait() and sys.exit(1) 14 | ps = subprocess.Popen("yarn build", shell=True, cwd=cwd) 15 | ps.wait() and sys.exit(1) 16 | management.call_command('collectstatic') 17 | -------------------------------------------------------------------------------- /django_react_admin/metadata.py: -------------------------------------------------------------------------------- 1 | from rest_framework.metadata import SimpleMetadata 2 | from rest_framework.schemas.openapi import AutoSchema 3 | 4 | 5 | class APIMetadata(SimpleMetadata): 6 | """Extended metadata generator.""" 7 | def get_field_info(self, field): 8 | field_info = super().get_field_info(field) 9 | 10 | # Add extra validators using the OpenAPI schema generator 11 | validators = {} 12 | AutoSchema()._map_field_validators(field, validators) 13 | extra_validators = ['format', 'pattern'] 14 | for validator in extra_validators: 15 | if validators.get(validator, None): 16 | field_info[validator] = validators[validator] 17 | 18 | # Add additional data from serializer 19 | field_info['initial'] = field.initial 20 | field_info['field_name'] = field.field_name 21 | field_info['write_only'] = field.write_only 22 | 23 | return field_info 24 | 25 | # >> > import json 26 | # >> > from your_app.serializers import UserSerializer 27 | # >> > metadata_generator = APIMetadata() 28 | # >> > metadata = metadata_generator.get_serializer_info(UserSerializer()) 29 | # >> > with open('User.json', 'w') as json_file: 30 | # ... 31 | # json.dump(metadata, json_file, indent=2, sort_keys=True) -------------------------------------------------------------------------------- /django_react_admin/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/migrations/__init__.py -------------------------------------------------------------------------------- /django_react_admin/models.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/models.py -------------------------------------------------------------------------------- /django_react_admin/src/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /django_react_admin/src/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /django_react_admin/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "/static/django_react_admin/", 6 | "dependencies": { 7 | "@material-ui/core": "^4.7.1", 8 | "babel-loader": "^8.0.6", 9 | "material-ui": "^0.20.2", 10 | "ra-data-drf": "^2.0.0", 11 | "react": "^16.12.0", 12 | "react-admin": "^3.0.2", 13 | "react-dom": "^16.12.0", 14 | "react-scripts": "^3.2.0" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build && (rm -rf ../static/django_react_admin || true) && sed 's/=\\//=\\/static\\//g' build/index.html > ../templates/django_react_admin/index.html && mv build/ ../static/django_react_admin", 19 | 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": "react-app" 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | }, 38 | "devDependencies": {} 39 | } 40 | -------------------------------------------------------------------------------- /django_react_admin/src/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/src/public/favicon.ico -------------------------------------------------------------------------------- /django_react_admin/src/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /django_react_admin/src/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/src/public/logo192.png -------------------------------------------------------------------------------- /django_react_admin/src/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/src/public/logo512.png -------------------------------------------------------------------------------- /django_react_admin/src/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /django_react_admin/src/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /django_react_admin/src/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | } 8 | 9 | .App-header { 10 | background-color: #282c34; 11 | min-height: 100vh; 12 | display: flex; 13 | flex-direction: column; 14 | align-items: center; 15 | justify-content: center; 16 | font-size: calc(10px + 2vmin); 17 | color: white; 18 | } 19 | 20 | .App-link { 21 | color: #09d3ac; 22 | } 23 | -------------------------------------------------------------------------------- /django_react_admin/src/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Admin, Resource, ListGuesser, EditGuesser, ShowGuesser } from 'react-admin'; 3 | import drfProvider from 'ra-data-drf'; 4 | const apiUrl = "api"; 5 | const dataProvider = 6 | drfProvider(apiUrl); 7 | 8 | class App extends Component { 9 | render() { 10 | let res = this.state.resources.map((i) => {return ;}); 11 | 12 | return ( 13 | 14 | {res} 15 | 16 | ); 17 | } 18 | componentDidMount() { 19 | fetch(apiUrl+'/').then(response => response.json()).then(response => { 20 | let res = response.reduce((a, cur) => { 21 | let b=cur.models.map((m) => {return m.admin_url.replace(/\/$/, "");}); 22 | return [...a, ...b]; 23 | } 24 | ,[]); 25 | this.setState({'resources': res}); 26 | } 27 | ); 28 | document.title = "Django Admin"; 29 | } 30 | constructor(props) { 31 | super(props); 32 | this.state = { 33 | resources: [] 34 | }; 35 | } 36 | 37 | } 38 | 39 | export default App; 40 | 41 | -------------------------------------------------------------------------------- /django_react_admin/src/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /django_react_admin/src/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /django_react_admin/src/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /django_react_admin/src/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_react_admin/src/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /django_react_admin/src/src/users.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useMediaQuery } from '@material-ui/core'; 3 | import { SimpleList, List, Datagrid, EmailField, TextField } from 'react-admin'; 4 | 5 | export const UserList = props => { 6 | const isSmall = useMediaQuery(theme => theme.breakpoints.down('sm')); 7 | 8 | return ( 9 | 10 | {isSmall ? ( 11 | record.name} 13 | secondaryText={record => record.username} 14 | tertiaryText={record => record.email} 15 | /> 16 | ) : ( 17 | 18 | 19 | 20 | 21 | 22 | 23 | )} 24 | 25 | ); 26 | }; 27 | -------------------------------------------------------------------------------- /django_react_admin/src/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | module: { 3 | rules: [ 4 | { 5 | test: /\.js$/, 6 | exclude: /node_modules/, 7 | use: { 8 | loader: "babel-loader" 9 | } 10 | } 11 | ] 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /django_react_admin/static/__git__: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/static/__git__ -------------------------------------------------------------------------------- /django_react_admin/static/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/static/__init__.py -------------------------------------------------------------------------------- /django_react_admin/templates/django_react_admin/index.html: -------------------------------------------------------------------------------- 1 | Pls run ./manage.py build_react_admin -------------------------------------------------------------------------------- /django_react_admin/tests.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/django_react_admin/tests.py -------------------------------------------------------------------------------- /django_react_admin/urls.py: -------------------------------------------------------------------------------- 1 | from django_react_admin import views 2 | from django.urls import path, include 3 | from django.views.generic import TemplateView 4 | 5 | urlpatterns = [ 6 | path('api/', include(views.urlpatterns)), 7 | path('', TemplateView.as_view(template_name='django_react_admin/index.html'), name='react_admin_index_html') 8 | ] 9 | -------------------------------------------------------------------------------- /django_react_admin/utils.py: -------------------------------------------------------------------------------- 1 | from subprocess import Popen, PIPE 2 | import os 3 | 4 | 5 | def vuetify(src): 6 | try: 7 | ps = Popen(['vue-beautify'], stdin=PIPE, stdout=PIPE) 8 | stdout, stderr = ps.communicate(src.encode('utf-8')) 9 | if ps.wait() == 0: 10 | return stdout.decode('utf-8') 11 | else: 12 | raise FileNotFoundError 13 | except FileNotFoundError: 14 | return src 15 | 16 | 17 | def run(cmd): 18 | return os.system(cmd) == 0 19 | 20 | 21 | def fail(cmd, msg=None): 22 | if not run(cmd): 23 | raise OSError('Failed to run {}'.format(cmd) if msg is None else msg) 24 | return True 25 | -------------------------------------------------------------------------------- /django_react_admin/views.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from django.contrib import admin 3 | from django.http import HttpRequest, HttpResponse 4 | from django.urls import path, reverse 5 | from django.views.generic import TemplateView 6 | from rest_framework import viewsets, permissions, views, pagination 7 | from django_filters.rest_framework.backends import DjangoFilterBackend 8 | from rest_framework.decorators import action, MethodMapper 9 | from rest_framework.filters import OrderingFilter 10 | from rest_framework.request import Request 11 | from rest_framework.response import Response 12 | from rest_framework.pagination import PageNumberPagination 13 | from rest_framework.reverse import reverse_lazy 14 | from rest_framework.routers import DefaultRouter 15 | from rest_framework.serializers import ModelSerializer 16 | 17 | router = DefaultRouter() 18 | 19 | 20 | class CustomPageNumberPagination(PageNumberPagination): 21 | page_size_query_param = 'page_size' # items per page 22 | 23 | def get_serializer_class(model): 24 | return type( 25 | f"{model.__name__}Serializer", 26 | (ModelSerializer,), 27 | {"Meta": type("Meta", (), {"model": model, "fields": "__all__"})}, 28 | ) 29 | 30 | from django.contrib.auth import get_user_model 31 | 32 | r = Request(HttpRequest()) 33 | r.user = get_user_model()(is_superuser=True) 34 | 35 | for model, model_admin in admin.site._registry.items(): 36 | 37 | def get_info(model_admin): 38 | def info(*args): 39 | basic_params = { 40 | "fields": list(model_admin.get_fields(r)), 41 | "list_display": list(model_admin.get_list_display(r)), 42 | "ordering_fields": list(model_admin.get_sortable_by(r)), 43 | "filterset_fields": list(model_admin.get_list_filter(r)), 44 | } 45 | form = [ 46 | dict(name=name, **field.widget.__dict__) 47 | for name, field in model_admin.get_form(r)().fields.items() 48 | if not hasattr(field.widget, "widget") 49 | ] 50 | return Response( 51 | dict(form=form, **basic_params) 52 | ) 53 | return info 54 | 55 | params = { 56 | "queryset": model.objects.all(), 57 | "filter_backends": [DjangoFilterBackend, OrderingFilter], 58 | "info": action(methods=["get"], detail=False)(get_info(model_admin)), 59 | "serializer_class": get_serializer_class(model), 60 | "basename": model._meta.model_name, 61 | "request": r, 62 | "fields": list(model_admin.get_fields(r)), 63 | "list_display": list(model_admin.get_list_display(r)), 64 | "ordering_fields": list(model_admin.get_sortable_by(r)), 65 | "filterset_fields": list(model_admin.get_list_filter(r)), 66 | "permission_classes": [permissions.IsAdminUser, permissions.DjangoModelPermissions], 67 | "pagination_class": CustomPageNumberPagination 68 | } 69 | viewset = type(f"{model.__name__}ViewSet", (viewsets.ModelViewSet,), params) 70 | router.register( 71 | f"{model._meta.app_label}/{model._meta.model_name}", viewset 72 | ) 73 | viewpath = f"{model._meta.app_label}/{model._meta.model_name}" 74 | # urlpatterns.append( 75 | # path( 76 | # r"html/{}/".format(viewpath), 77 | # TemplateView.as_view( 78 | # template_name="django_react_admin/list.html", 79 | # extra_context={ 80 | # "app": model._meta.app_label, 81 | # "model": model._meta.model_name, 82 | # "path": reverse_lazy(model._meta.model_name+"-list"), 83 | # }, 84 | # ), 85 | # ) 86 | # ) 87 | # urlpatterns.append( 88 | # path( 89 | # r"html/{}/add/".format(viewpath), 90 | # TemplateView.as_view( 91 | # template_name="django_react_admin/edit.html", 92 | # extra_context={ 93 | # "create": True, 94 | # "app": model._meta.app_label, 95 | # "model": model._meta.model_name, 96 | # "path": reverse_lazy(model._meta.model_name + "-list"), 97 | # }, 98 | # ), 99 | # ) 100 | # ) 101 | # urlpatterns.append( 102 | # path( 103 | # r"html/{}//".format(viewpath), 104 | # TemplateView.as_view( 105 | # template_name="django_react_admin/edit.html", 106 | # extra_context={ 107 | # "create": False, 108 | # "app": model._meta.app_label, 109 | # "model": model._meta.model_name, 110 | # "path": reverse_lazy(model._meta.model_name + "-list"), 111 | # }, 112 | # ), 113 | # ) 114 | # ) 115 | 116 | 117 | class Index(views.APIView): 118 | def get(self, request): 119 | res = admin.site.get_app_list(request) 120 | # return Response([m['admin_url'].replace(reverse('admin:index'), '') for app in res for m in app['models']]) 121 | for app in res: 122 | app['app_url'] = app['app_url'].replace(reverse('admin:index'), '') 123 | for m in app['models']: 124 | for k in ['add_url', 'admin_url']: 125 | m[k] = m[k].replace(reverse('admin:index'), '') 126 | return Response(res) 127 | 128 | 129 | urlpatterns = [path('', Index.as_view(), name='react_admin_index')] + router.urls 130 | -------------------------------------------------------------------------------- /poetry.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | category = "dev" 3 | description = "Atomic file writes." 4 | name = "atomicwrites" 5 | optional = false 6 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 7 | version = "1.3.0" 8 | 9 | [[package]] 10 | category = "dev" 11 | description = "Classes Without Boilerplate" 12 | name = "attrs" 13 | optional = false 14 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 15 | version = "19.3.0" 16 | 17 | [[package]] 18 | category = "dev" 19 | description = "Cross-platform colored terminal text." 20 | marker = "sys_platform == \"win32\"" 21 | name = "colorama" 22 | optional = false 23 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 24 | version = "0.4.1" 25 | 26 | [[package]] 27 | category = "main" 28 | description = "A high-level Python Web framework that encourages rapid development and clean, pragmatic design." 29 | name = "django" 30 | optional = false 31 | python-versions = ">=3.5" 32 | version = "2.2.8" 33 | 34 | [package.dependencies] 35 | pytz = "*" 36 | sqlparse = "*" 37 | 38 | [[package]] 39 | category = "main" 40 | description = "Django-filter is a reusable Django application for allowing users to filter querysets dynamically." 41 | name = "django-filter" 42 | optional = false 43 | python-versions = ">=3.4" 44 | version = "2.2.0" 45 | 46 | [package.dependencies] 47 | Django = ">=1.11" 48 | 49 | [[package]] 50 | category = "main" 51 | description = "Web APIs for Django, made easy." 52 | name = "djangorestframework" 53 | optional = false 54 | python-versions = ">=3.5" 55 | version = "3.10.3" 56 | 57 | [[package]] 58 | category = "dev" 59 | description = "More routines for operating on iterables, beyond itertools" 60 | name = "more-itertools" 61 | optional = false 62 | python-versions = ">=3.5" 63 | version = "8.0.0" 64 | 65 | [[package]] 66 | category = "dev" 67 | description = "plugin and hook calling mechanisms for python" 68 | name = "pluggy" 69 | optional = false 70 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 71 | version = "0.13.1" 72 | 73 | [[package]] 74 | category = "dev" 75 | description = "library with cross-python path, ini-parsing, io, code, log facilities" 76 | name = "py" 77 | optional = false 78 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 79 | version = "1.8.0" 80 | 81 | [[package]] 82 | category = "dev" 83 | description = "pytest: simple powerful testing with Python" 84 | name = "pytest" 85 | optional = false 86 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 87 | version = "3.10.1" 88 | 89 | [package.dependencies] 90 | atomicwrites = ">=1.0" 91 | attrs = ">=17.4.0" 92 | colorama = "*" 93 | more-itertools = ">=4.0.0" 94 | pluggy = ">=0.7" 95 | py = ">=1.5.0" 96 | setuptools = "*" 97 | six = ">=1.10.0" 98 | 99 | [[package]] 100 | category = "main" 101 | description = "World timezone definitions, modern and historical" 102 | name = "pytz" 103 | optional = false 104 | python-versions = "*" 105 | version = "2019.3" 106 | 107 | [[package]] 108 | category = "dev" 109 | description = "Python 2 and 3 compatibility utilities" 110 | name = "six" 111 | optional = false 112 | python-versions = ">=2.6, !=3.0.*, !=3.1.*" 113 | version = "1.13.0" 114 | 115 | [[package]] 116 | category = "main" 117 | description = "Non-validating SQL parser" 118 | name = "sqlparse" 119 | optional = false 120 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 121 | version = "0.3.0" 122 | 123 | [metadata] 124 | content-hash = "16f310c20f5e41070f3c0c7259bf7e53b28c5a9364b46d71b83440eabfca91bc" 125 | python-versions = "^3.8" 126 | 127 | [metadata.hashes] 128 | atomicwrites = ["03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4", "75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6"] 129 | attrs = ["08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", "f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"] 130 | colorama = ["05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", "f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48"] 131 | django = ["a4ad4f6f9c6a4b7af7e2deec8d0cbff28501852e5010d6c2dc695d3d1fae7ca0", "fa98ec9cc9bf5d72a08ebf3654a9452e761fbb8566e3f80de199cbc15477e891"] 132 | django-filter = ["558c727bce3ffa89c4a7a0b13bc8976745d63e5fd576b3a9a851650ef11c401b", "c3deb57f0dd7ff94d7dce52a047516822013e2b441bed472b722a317658cfd14"] 133 | djangorestframework = ["5488aed8f8df5ec1d70f04b2114abc52ae6729748a176c453313834a9ee179c8", "dc81cbf9775c6898a580f6f1f387c4777d12bd87abf0f5406018d32ccae71090"] 134 | more-itertools = ["53ff73f186307d9c8ef17a9600309154a6ae27f25579e80af4db8f047ba14bc2", "a0ea684c39bc4315ba7aae406596ef191fd84f873d2d2751f84d64e81a7a2d45"] 135 | pluggy = ["15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0", "966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"] 136 | py = ["64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa", "dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53"] 137 | pytest = ["3f193df1cfe1d1609d4c583838bea3d532b18d6160fd3f55c9447fdca30848ec", "e246cf173c01169b9617fc07264b7b1316e78d7a650055235d6d897bc80d9660"] 138 | pytz = ["1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", "b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"] 139 | six = ["1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", "30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"] 140 | sqlparse = ["40afe6b8d4b1117e7dff5504d7a8ce07d9a1b15aeeade8a2d10f130a834f8177", "7c3dca29c022744e95b547e867cee89f4fce4373f3549ccd8797d8eb52cdb873"] 141 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "django_react_admin" 3 | version = "0.1.1" 4 | description = "Creates viewsets and serializers for models in your admin site to use with react-admin" 5 | authors = ["ph "] 6 | homepage = "https://github.com/pawnhearts/django_react_admin" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.8" 10 | djangorestframework = "^3.10" 11 | django = "^3.0" 12 | django-filter = "^2.2" 13 | 14 | [tool.poetry.dev-dependencies] 15 | pytest = "^3.0" 16 | 17 | [build-system] 18 | requires = ["poetry>=0.12"] 19 | build-backend = "poetry.masonry.api" 20 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | django==2.*,>=2.2.0 2 | django-filter==2.*,>=2.2.0 3 | djangorestframework==3.*,>=3.10.0 4 | pytest==3.*,>=3.0.0 5 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | 2 | # -*- coding: utf-8 -*- 3 | 4 | # DO NOT EDIT THIS FILE! 5 | # This file has been autogenerated by dephell <3 6 | # https://github.com/dephell/dephell 7 | 8 | try: 9 | from setuptools import setup 10 | except ImportError: 11 | from distutils.core import setup 12 | 13 | readme = '' 14 | 15 | setup( 16 | long_description=readme, 17 | name='django_react_admin', 18 | version='0.1.1', 19 | description='Creates viewsets and serializers for models in your admin site to use with react-admin', 20 | python_requires='==3.*,>=3.8.0', 21 | project_urls={ 22 | "homepage": "https://github.com/pawnhearts/django_react_admin"}, 23 | author='ph', 24 | author_email='robotnaoborot@gmail.com', 25 | packages=['django_react_admin', 'django_react_admin.management', 26 | 'django_react_admin.management.commands', 'django_react_admin.migrations', 'django_react_admin.static'], 27 | package_dir={"": "."}, 28 | package_data={"django_react_admin": ["src/*.js", "src/*.json", "src/*.lock", "src/*.md", "src/public/*.html", "src/public/*.ico", "src/public/*.json", 29 | "src/public/*.png", "src/public/*.txt", "src/src/*.css", "src/src/*.js", "src/src/*.svg", "templates/django_react_admin/*.html"]}, 30 | install_requires=['django==3.*,>=3.0.0', 31 | 'django-filter==2.*,>=2.2.0', 'djangorestframework==3.*,>=3.10.0'], 32 | extras_require={"dev": ["pytest==3.*,>=3.0.0"]}, 33 | ) 34 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawnhearts/django_react_admin/f52ee64ae490b2cfae4202447367136d9f03ed31/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_django_vue_admin.py: -------------------------------------------------------------------------------- 1 | from django_react_admin import __version__ 2 | 3 | 4 | def test_version(): 5 | assert __version__ == '0.1.0' 6 | --------------------------------------------------------------------------------