2
0
mirror of https://github.com/inventree/inventree-docs.git synced 2025-04-28 13:46:54 +00:00

Merge pull request #77 from SergeoLacruz/master

Added examples to the python lib docu
This commit is contained in:
Oliver 2021-03-02 07:45:57 +11:00 committed by GitHub
commit f05c29021e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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