Store data from example panel (#5986)

* Fix errors in variable names of examples

* Added drop down example

* Added drop down example

* Fixed picture name

* Fixed context variable in purchase order report

* Store data from example panel

* Store data from example panel

* Store data from example panel
This commit is contained in:
Michael 2023-11-26 23:48:41 +01:00 committed by GitHub
parent 43434fc530
commit e9fe394d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -191,6 +191,7 @@ class ExamplePanel(PanelMixin, InvenTreePlugin, UrlsMixin):
def get_custom_panels(self, view, request):
panels = []
if isinstance(view, BuildDetail):
self.build=view.get_object()
panels.append({
'title': 'Example Info',
'icon': 'fa-industry',
@ -331,6 +332,7 @@ from company.models import Company
def get_custom_panels(self, view, request):
panels = []
if isinstance(view, BuildDetail):
self.build=view.get_object()
self.companies=Company.objects.filter(is_supplier=True)
panels.append({
...
@ -352,3 +354,19 @@ by looping.
The value of the select is the pk of the company. It can simply be added to the
json container and transferred to the plugin.
#### Store the Data
I case you plugin needs to store data permanently, InvenTree has a nice feature called
[metadata](metadata.md). You can easily store your values by adding a few lines
to the do_something function.
code:
```python
def do_something(self, request):
data=json.loads(request.body)
print('Data received:', data)
for key in data:
self.build.metadata[key]=data[key]
self.build.save()
```