complete initial developer features for plant catalog
This commit is contained in:
parent
04ce180ac1
commit
ae040b2d29
7 changed files with 21 additions and 8 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -4,3 +4,13 @@ venv/
|
|||
# Ignore Django migrations
|
||||
**/migrations/
|
||||
|
||||
# Ignore media files
|
||||
**/media/
|
||||
|
||||
# Ignore pycache
|
||||
**/__pycache__/
|
||||
|
||||
# Ignore static files
|
||||
**/static/
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue