2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-03 13:58:47 +00:00

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,11 +191,12 @@ class ExamplePanel(PanelMixin, InvenTreePlugin, UrlsMixin):
def get_custom_panels(self, view, request): def get_custom_panels(self, view, request):
panels = [] panels = []
if isinstance(view, BuildDetail): if isinstance(view, BuildDetail):
panels.append({ self.build=view.get_object()
'title': 'Example Info', panels.append({
'icon': 'fa-industry', 'title': 'Example Info',
'content_template': 'example_panel/example.html', 'icon': 'fa-industry',
}) 'content_template': 'example_panel/example.html',
})
return panels return panels
def setup_urls(self): def setup_urls(self):
@ -331,6 +332,7 @@ from company.models import Company
def get_custom_panels(self, view, request): def get_custom_panels(self, view, request):
panels = [] panels = []
if isinstance(view, BuildDetail): if isinstance(view, BuildDetail):
self.build=view.get_object()
self.companies=Company.objects.filter(is_supplier=True) self.companies=Company.objects.filter(is_supplier=True)
panels.append({ 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 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. 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()
```