Open afkiwers opened 1 year ago
This is a very advanced topic with good opportunities to wreck a (or if it is released many) InvenTree instances so I am more than hesitant to encourage general usage of this mixin. The samples are for CI testing, not instruction.
For real-world use, you can look at this plugin.
Thanks @matmair
@matmair I just checked you code and can't tell the difference to my testapp structure
I still get that error: Model class testapp.testapp.EnabledCategory doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Any idea why that is?
Had the same issue, still asking me why it works for @matmair without, but to fix this issue you need these lines: https://github.com/wolflu05/inventree-bulk-plugin/blob/main/inventree_bulk/models.py#L24-L25
@afkiwers @wolflu05 most likely a namespace issue. AppMixins get loaded into Django's app and model registry by the package name (or subdirectory name when using the folder based loading mechanism). If you use subfolders after that the applabel will not match and raise that issue. The proposed fix also works.
@wolflu05 thanks a lot for you example.
@wolflu05 @matmair I am still trying to understand the mechanism.
Do I need to define an admin.py file to display the model? does inventree does the starts the makemigration step or do I have to do that manually upfront? When is the database table actually created; before after enabling the plugin?
Cheers
No, your namespace is wrong. Your model is loaded as testapp.testapp.EnabledCategory
so you probably have a double reference somewhere in the packaging. If you can share a link and I will provide you with a patch - that is probably the fastest solution.
It works like any other Django app - the only thing InvenTree does is insert the plugin name into the app registry. From there everything is 100% Django behaviour. Your URL pattern is inserted into a subpath so that you do not need to modify the base urls.py.
@matmair below the link to the repository. I am keen to see what you have to change to make it work.
@matmair I encountered just another error. Any advice? It seems to not be able to locate Django.
[17/Jun/2023 09:49:08] "OPTIONS /api/plugins/install/?context=true HTTP/1.1" 200 793 Running command git clone --filter=blob:none --quiet https://github.com/afkiwers/inventree-kicad-plugin 'C:\Users\Andre Iwers\AppData\Local\Temp\pip-install-w75miu65\inventree-kicad-plugin_92fad9e5a1fb4277b2b7466f547135e0' error: subprocess-exited-with-error
python setup.py egg_info did not run successfully. exit code: 1
[10 lines of output]
Traceback (most recent call last):
File "
The Plugin was installed Collecting inventree-kicad-plugin@ git+https://github.com/afkiwers/inventree-kicad-plugin Cloning https://github.com/afkiwers/inventree-kicad-plugin to /tmp/pip-install-q4ic2mob/inventree-kicad-plugin_c478d10d6ab64b739a846875ee68193b Resolved https://github.com/afkiwers/inventree-kicad-plugin to commit 1ef4c311aef37f258e4a76ef82b5a4183e20989d Preparing metadata (setup.py): started Preparing metadata (setup.py): finished with status 'error'
InvenTree-Version: 0.11.2 Django Version: 3.2.18 Commit Hash: 4868194 Commit Date: 2023-05-25 Database: mysql Debug-Mode: False Deployed using Docker: True Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}]
This issue seems stale. Please react to show this is still important.
Not stale
This issue seems stale. Please react to show this is still important.
not stale
This issue seems stale. Please react to show this is still important.
Not stle
This issue seems stale. Please react to show this is still important.
Still not stale - docs definitely need some work
Maybe with the mkdocstrings integration introduced with #4824 plugin docs can be drastically improved by auto inferring the documentation from the code docstrings.
This issue seems stale. Please react to show this is still important.
not stale
Body of the issue
I would like to add a model to my plugin but in doing so, Inventree complains.
I tried using the normal app structure but without any success. Is there any way to add some more elaborated sample than the sample.py or extend the docs?
Model:
Error Message: Model class testapp.testapp.EnabledCategory doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.