inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 780 forks source link

AppMixin documentation needs some touch up #5046

Open afkiwers opened 1 year ago

afkiwers commented 1 year ago

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.

matmair commented 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.

afkiwers commented 1 year ago

Thanks @matmair

afkiwers commented 1 year ago

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

wolflu05 commented 1 year ago

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

matmair commented 1 year ago

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

afkiwers commented 1 year ago

@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

matmair commented 1 year ago

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.

afkiwers commented 1 year ago

@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 commented 1 year ago

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

github-actions[bot] commented 1 year ago

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

afkiwers commented 1 year ago

Not stale

github-actions[bot] commented 1 year ago

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

SchrodingersGat commented 1 year ago

not stale

github-actions[bot] commented 11 months ago

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

SchrodingersGat commented 11 months ago

Not stle

github-actions[bot] commented 9 months ago

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

SchrodingersGat commented 9 months ago

Still not stale - docs definitely need some work

wolflu05 commented 9 months ago

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

github-actions[bot] commented 6 months ago

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

SchrodingersGat commented 6 months ago

not stale