mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-28 05:36:46 +00:00
Update python.md
Added example for adding parameter templates and parameters
This commit is contained in:
parent
e18e27462b
commit
f96f682073
@ -88,6 +88,8 @@ stock_item.uploadTestResult("Firmware", True, value="0x12345678", attachment="de
|
|||||||
```python
|
```python
|
||||||
from inventree.part import Part, PartCategory
|
from inventree.part import Part, PartCategory
|
||||||
from inventree.stock import StockItem
|
from inventree.stock import StockItem
|
||||||
|
from inventree.base import Parameter
|
||||||
|
from inventree.base import ParameterTemplate
|
||||||
|
|
||||||
## Create a new PartCategory object,
|
## Create a new PartCategory object,
|
||||||
## underneath the existing category with pk 7
|
## underneath the existing category with pk 7
|
||||||
@ -108,6 +110,15 @@ couch = Part.create(api, {
|
|||||||
## Note - You do not have to fill out *all* fields
|
## Note - You do not have to fill out *all* fields
|
||||||
})
|
})
|
||||||
|
|
||||||
|
## Before we can add parameters to the couch, we neeed to create the parameter templates
|
||||||
|
## These parameter templates need to be defined only once and can be used for all other parts.
|
||||||
|
LengthTemplate = ParameterTemplate.create(api, { 'name' : 'Length', 'units' : 'Meters' })
|
||||||
|
WeightTemplate = ParameterTemplate.create(api, { 'name' : 'Weight', 'units' : 'kg' })
|
||||||
|
|
||||||
|
## Now we create the parameters
|
||||||
|
ParameterLength = Parameter.create(api, { 'part': couch.pk, 'template': LengthTemplate.pk, 'data' : 2 })
|
||||||
|
ParameterWeight = Parameter.create(api, { 'part': couch.pk, 'template': WeightTemplate.pk, 'data' : 60 })
|
||||||
|
|
||||||
## Create a new StockItem
|
## Create a new StockItem
|
||||||
item = StockItem.create(api, {
|
item = StockItem.create(api, {
|
||||||
'part': couch.pk,
|
'part': couch.pk,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user