diff --git a/.gitignore b/.gitignore index 4ad4d96..97ee1ab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,13 @@ venv/ # Ignore Django migrations **/migrations/ +# Ignore media files +**/media/ + +# Ignore pycache +**/__pycache__/ + +# Ignore static files +**/static/ + + diff --git a/plant_catalog/catalog/__pycache__/api_views.cpython-311.pyc b/plant_catalog/catalog/__pycache__/api_views.cpython-311.pyc deleted file mode 100644 index e131d30..0000000 Binary files a/plant_catalog/catalog/__pycache__/api_views.cpython-311.pyc and /dev/null differ diff --git a/plant_catalog/catalog/__pycache__/models.cpython-311.pyc b/plant_catalog/catalog/__pycache__/models.cpython-311.pyc deleted file mode 100644 index 7107b4d..0000000 Binary files a/plant_catalog/catalog/__pycache__/models.cpython-311.pyc and /dev/null differ diff --git a/plant_catalog/catalog/__pycache__/serializers.cpython-311.pyc b/plant_catalog/catalog/__pycache__/serializers.cpython-311.pyc deleted file mode 100644 index c324271..0000000 Binary files a/plant_catalog/catalog/__pycache__/serializers.cpython-311.pyc and /dev/null differ diff --git a/plant_catalog/catalog/api_views.py b/plant_catalog/catalog/api_views.py index e79db80..99b8be0 100644 --- a/plant_catalog/catalog/api_views.py +++ b/plant_catalog/catalog/api_views.py @@ -18,3 +18,4 @@ class PlantListCreateAPIView(generics.ListCreateAPIView): class PlantRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView): queryset = Plant.objects.all() serializer_class = PlantSerializer + parser_classes = [MultiPartParser, FormParser] # Allow file uploads and form data \ No newline at end of file diff --git a/plant_catalog/catalog/models.py b/plant_catalog/catalog/models.py index 0f36f88..bc757ea 100644 --- a/plant_catalog/catalog/models.py +++ b/plant_catalog/catalog/models.py @@ -4,12 +4,11 @@ from django.db import models class Plant(models.Model): name = models.CharField(max_length=100) - description = models.TextField(null=True) - image = models.ImageField(upload_to='plants/', null=True, blank=True) # Allow null values - buy_price = models.FloatField(null=True) - sell_price = models.FloatField(null=True) - stock = models.IntegerField(default=0) - + description = models.TextField(null=True, blank=True) # Allow null and blank + image = models.ImageField(upload_to='plants/', null=True, blank=True) # Optional image + buy_price = models.FloatField(null=True, blank=True) # Allow null for buy price + sell_price = models.FloatField(null=True, blank=True) # Allow null for sell price + stock = models.IntegerField(default=0) # Default to 0 def __str__(self): return self.name diff --git a/plant_catalog/catalog/serializers.py b/plant_catalog/catalog/serializers.py index a34300e..20dfb76 100644 --- a/plant_catalog/catalog/serializers.py +++ b/plant_catalog/catalog/serializers.py @@ -6,9 +6,12 @@ from .models import Plant class PlantSerializer(serializers.ModelSerializer): class Meta: model = Plant - fields = ['id', 'name', 'description', 'image'] # Relevant fields + fields = ['id', 'name', 'description', 'image', 'buy_price', 'sell_price', 'stock'] # Include all fields extra_kwargs = { - 'image': {'required': False, 'allow_null': True} # Optional field + '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 } \ No newline at end of file