@@ -220,7 +220,7 @@ class Renderer {
220220
221221 if ( app == undefined ) return
222222
223- const models = this . get_models ( app_id )
223+ const models = this . get_concrete_models ( app_id )
224224
225225 let model_templates = [ ]
226226
@@ -455,6 +455,12 @@ class Renderer {
455455 return this . store . getters . ordered_models ( appid )
456456 }
457457
458+ // Only return non-abstract models, so Django won't try to use
459+ // abstract models in admin panel (admin.py), serialize.py, etc.
460+ get_concrete_models ( appid ) {
461+ return this . get_models ( appid ) . filter ( model => ! model . abstract )
462+ }
463+
458464 get_fields ( model ) {
459465 return keys ( model . fields ) . map ( ( field ) => {
460466 return this . store . getters . fields ( ) [ field ] ? this . store . getters . fields ( ) [ field ] . data ( ) : [ ] ;
@@ -615,7 +621,7 @@ CHANNEL_LAYERS = {
615621
616622 apps . forEach ( ( app ) => {
617623 output += `\n<div class="m-2"><h4>${ app . name } </h4></div>`
618- this . get_models ( app . id ) . forEach ( ( model ) => {
624+ this . get_concrete_models ( app . id ) . forEach ( ( model ) => {
619625 output += `\n<div class="m-2"><a class="btn btn-light" href="{% url '${ app . name } _${ model . name } _list' %}">${ model . name } Listing</a></div>`
620626 } )
621627 } )
@@ -639,7 +645,7 @@ CHANNEL_LAYERS = {
639645 const apps = this . get_apps ( projectid ) ;
640646 let htmx_body = ""
641647 apps . forEach ( ( app ) => {
642- const models = this . get_models ( app . id )
648+ const models = this . get_concrete_models ( app . id )
643649 models . forEach ( ( model ) => {
644650 htmx_body += `
645651 <div class="col col-lg-6">
@@ -907,7 +913,7 @@ CHANNEL_LAYERS = {
907913 urls += '\n\n'
908914 urls += 'router = routers.DefaultRouter()\n'
909915
910- const models = this . get_models ( appid )
916+ const models = this . get_concrete_models ( appid )
911917
912918 models . forEach ( ( model ) => {
913919 urls += 'router.register("' + model . name + '", api.' + model . name + 'ViewSet)\n'
@@ -965,7 +971,8 @@ CHANNEL_LAYERS = {
965971 api += 'from . import serializers\n'
966972 api += 'from . import models\n'
967973
968- const models = this . get_models ( appid )
974+ const models = this . get_concrete_models ( appid )
975+
969976
970977 models . forEach ( ( model ) => {
971978 api += '\n\n'
@@ -984,7 +991,7 @@ CHANNEL_LAYERS = {
984991 serializers += '\n'
985992 serializers += 'from . import models\n'
986993
987- const models = this . get_models ( appid )
994+ const models = this . get_concrete_models ( appid )
988995
989996 models . forEach ( ( model ) => {
990997 const fields = this . get_fields ( model )
@@ -1014,7 +1021,7 @@ CHANNEL_LAYERS = {
10141021 admin += 'from . import models\n'
10151022 admin += '\n\n'
10161023
1017- const models = this . get_models ( appid )
1024+ const models = this . get_concrete_models ( appid )
10181025
10191026 models . forEach ( ( model ) => {
10201027 admin += 'class ' + model . name + 'AdminForm(forms.ModelForm):\n'
@@ -1188,10 +1195,8 @@ CHANNEL_LAYERS = {
11881195 }
11891196
11901197 views_py ( projectid , appid ) {
1191- const models = this . get_models ( appid ) . filter ( ( modelData ) => {
1192- // Do not include abstract models in form views
1193- return ! modelData . abstract
1194- } )
1198+ // Do not include abstract models in form views
1199+ const models = this . get_concrete_models ( appid )
11951200
11961201 const appData = this . store . getters . appData ( appid )
11971202
@@ -1228,10 +1233,8 @@ CHANNEL_LAYERS = {
12281233 htmx_py ( projectid , appid ) {
12291234 const appData = this . store . getters . appData ( appid )
12301235
1231- const models = this . get_models ( appid ) . filter ( ( modelData ) => {
1232- // Do not include abstract models in form views
1233- return ! modelData . abstract
1234- } )
1236+ // Do not include abstract models in form views
1237+ const models = this . get_concrete_models ( appid )
12351238
12361239 let htmx_views = 'from django.views import generic\n'
12371240 htmx_views += 'from django.urls import reverse_lazy\n'
@@ -1268,10 +1271,8 @@ CHANNEL_LAYERS = {
12681271 }
12691272
12701273 forms_py ( projectid , appid ) {
1271- const models = this . get_models ( appid ) . filter ( ( modelData ) => {
1272- // Do not include abstract models in forms
1273- return ! modelData . abstract
1274- } )
1274+ // Do not include abstract models in forms
1275+ const models = this . get_concrete_models ( appid )
12751276
12761277 let forms = 'from django import forms'
12771278
@@ -1372,9 +1373,7 @@ CHANNEL_LAYERS = {
13721373 const extra_imports = new Set ( )
13731374
13741375 apps . forEach ( ( app ) => {
1375- const models = this . get_models ( app . id ) . filter ( ( modelData ) => {
1376- return ! modelData . abstract
1377- } )
1376+ const models = this . get_concrete_models ( app . id )
13781377 models . forEach ( ( model ) => {
13791378 const parent_user_models = [ ]
13801379 const parent_django_models = [ ]
@@ -1457,9 +1456,8 @@ CHANNEL_LAYERS = {
14571456 tests += '\n\n'
14581457 tests += 'pytestmark = [pytest.mark.django_db]\n'
14591458
1460- const models = this . get_models ( appid ) . filter ( ( modelData ) => {
1461- return ! modelData . abstract
1462- } )
1459+ const models = this . get_concrete_models ( appid )
1460+
14631461 models . forEach ( ( model ) => {
14641462 tests += '\n\n'
14651463
0 commit comments