InvenTree icon indicating copy to clipboard operation
InvenTree copied to clipboard

AppMixin documentation needs some touch up

Open afkiwers opened this issue 2 years ago • 20 comments

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?

class TestPlugin(InvenTreePlugin, AppMixin):
    AUTHOR = "Author"

    DESCRIPTION = "Test app"

    VERSION = PLUGIN_VERSION

    NAME = "Test Plugin"class TestPlugin(InvenTreePlugin, AppMixin):
    AUTHOR = "Author"

    DESCRIPTION = "Test app"

    VERSION = PLUGIN_VERSION

    NAME = "Test Plugin"
    SLUG = "testapp"
    TITLE = "Test Plugin"
    PUBLISH_DATE = datetime.date(2023, 6, 9)
    WEBSITE = "https://www.test.com"

    MIN_VERSION = '0.11.0'

Model:

 class EnabledCategory(models.Model):
        category = models.ForeignKey(PartCategory, related_name='get_all', on_delete=models.CASCADE)

Error Message: Model class testapp.testapp.EnabledCategory doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

afkiwers avatar Jun 14 '23 23:06 afkiwers

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.

matmair avatar Jun 15 '23 00:06 matmair

Thanks @matmair

afkiwers avatar Jun 15 '23 00:06 afkiwers

@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?

afkiwers avatar Jun 15 '23 02:06 afkiwers

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

wolflu05 avatar Jun 15 '23 05:06 wolflu05

@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.

matmair avatar Jun 15 '23 05:06 matmair

@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

afkiwers avatar Jun 15 '23 21:06 afkiwers

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 avatar Jun 15 '23 22:06 matmair

@matmair below the link to the repository. I am keen to see what you have to change to make it work.

https://github.com/afkiwers/inventree-kicad-plugin

afkiwers avatar Jun 15 '23 23:06 afkiwers

@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 "", line 2, in File "", line 34, in File "C:\Users\Andre Iwers\AppData\Local\Temp\pip-install-w75miu65\inventree-kicad-plugin_92fad9e5a1fb4277b2b7466f547135e0\setup.py", line 5, in from inventree_kicad.version import PLUGIN_VERSION File "C:\Users\Andre Iwers\AppData\Local\Temp\pip-install-w75miu65\inventree-kicad-plugin_92fad9e5a1fb4277b2b7466f547135e0\inventree_kicad_init_.py", line 3, in from .KiCadLibraryPlugin import KiCadLibraryPlugin File "C:\Users\Andre Iwers\AppData\Local\Temp\pip-install-w75miu65\inventree-kicad-plugin_92fad9e5a1fb4277b2b7466f547135e0\inventree_kicad\KiCadLibraryPlugin.py", line 11, in from django.conf.urls import url ModuleNotFoundError: No module named 'django' [end of output]

##Inventree Response after install 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'

image

Version Information:

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'}]

afkiwers avatar Jun 16 '23 23:06 afkiwers

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Aug 16 '23 11:08 github-actions[bot]

Not stale

afkiwers avatar Aug 16 '23 13:08 afkiwers

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Oct 17 '23 11:10 github-actions[bot]

not stale

SchrodingersGat avatar Oct 17 '23 11:10 SchrodingersGat

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Dec 18 '23 11:12 github-actions[bot]

Not stle

SchrodingersGat avatar Dec 18 '23 11:12 SchrodingersGat

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Feb 18 '24 11:02 github-actions[bot]

Still not stale - docs definitely need some work

SchrodingersGat avatar Feb 18 '24 11:02 SchrodingersGat

Maybe with the mkdocstrings integration introduced with #4824 plugin docs can be drastically improved by auto inferring the documentation from the code docstrings.

wolflu05 avatar Feb 18 '24 14:02 wolflu05

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Apr 19 '24 11:04 github-actions[bot]

not stale

SchrodingersGat avatar Apr 19 '24 11:04 SchrodingersGat