mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-28 13:46:54 +00:00
Update python.md
This commit is contained in:
parent
1244203981
commit
b5b8580bc1
@ -88,8 +88,6 @@ 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. Leave the parent empty fpr a top level category
|
## underneath the existing category with pk 7. Leave the parent empty fpr a top level category
|
||||||
@ -111,19 +109,19 @@ couch = Part.create(api, {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
#### Adding parameters to the sofa
|
#### Adding parameters to the sofa
|
||||||
Each can have multiple parameters like added like resistance, voltage or capacitance. For the sofa length and weight make sense. Each parameter has a parameter template that combines the parameter name with a unit. So we first have to create the parameters:
|
Each part can have multiple parameters like resistance, voltage or capacitance. For the sofa length and weight make sense. Each parameter has a parameter template that combines the parameter name with a unit. So we first have to create the parameters and afterwards add the parameter values to the sofa.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from inventree.base import Parameter
|
||||||
|
from inventree.base import ParameterTemplate
|
||||||
|
|
||||||
LengthTemplate = ParameterTemplate.create(api, { 'name' : 'Length', 'units' : 'Meters' })
|
LengthTemplate = ParameterTemplate.create(api, { 'name' : 'Length', 'units' : 'Meters' })
|
||||||
WeightTemplate = ParameterTemplate.create(api, { 'name' : 'Weight', 'units' : 'kg' })
|
WeightTemplate = ParameterTemplate.create(api, { 'name' : 'Weight', 'units' : 'kg' })
|
||||||
```
|
|
||||||
These parameter templates need to be defined only once and can be used for all other parts. Now add parameter values to the sofa
|
|
||||||
|
|
||||||
```python
|
|
||||||
ParameterLength = Parameter.create(api, { 'part': couch.pk, 'template': LengthTemplate.pk, 'data' : 2 })
|
ParameterLength = Parameter.create(api, { 'part': couch.pk, 'template': LengthTemplate.pk, 'data' : 2 })
|
||||||
ParameterWeight = Parameter.create(api, { 'part': couch.pk, 'template': WeightTemplate.pk, 'data' : 60 })
|
ParameterWeight = Parameter.create(api, { 'part': couch.pk, 'template': WeightTemplate.pk, 'data' : 60 })
|
||||||
```
|
```
|
||||||
Lets finally add a picture
|
These parameter templates need to be defined only once and can be used for all other parts. Lets finally add a picture.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
couch.upload_image('my_nice_couch.jpg')
|
couch.upload_image('my_nice_couch.jpg')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user