2024-10-05 17:30:35 +02:00
|
|
|
# catalog/serializers.py
|
|
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
from .models import Plant
|
|
|
|
|
|
|
|
|
|
class PlantSerializer(serializers.ModelSerializer):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Plant
|
2024-10-28 06:41:12 +01:00
|
|
|
fields = ['id', 'name', 'description', 'image', 'buy_price', 'sell_price', 'stock'] # Include all fields
|
2024-10-05 17:30:35 +02:00
|
|
|
extra_kwargs = {
|
2024-10-28 06:41:12 +01:00
|
|
|
'buy_price': {'required': False, 'allow_null': True}, # Allow null for buy price
|
|
|
|
|
'sell_price': {'required': False, 'allow_null': True}, # Allow null for sell price
|
|
|
|
|
'image': {'required': False, 'allow_null': True}, # Allow image to be optional
|
|
|
|
|
'description': {'required': False, 'allow_null': True}, # Optional description
|
2024-10-05 17:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|