Skip to content

Commit

Permalink
fix post plant
Browse files Browse the repository at this point in the history
  • Loading branch information
iandday committed Jul 28, 2024
1 parent a8f2726 commit f20f328
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions plant_tracker/tracker/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Meta:
"graveyard",
"death_date",
"notes",
"area"
]
fields_optional = "__all__"
purchase_date: EmptyStrToDefault[date] = None
Expand Down
5 changes: 4 additions & 1 deletion plant_tracker/tracker/api/view_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.http import HttpRequest
from ninja import File, Form, Router
from django.contrib.auth import get_user_model
from tracker.models import Location, Plant
from tracker.models import Area, Location, Plant
from ninja_jwt.authentication import JWTAuth
from ninja_extra import status
from ninja_extra.exceptions import APIException
Expand Down Expand Up @@ -92,6 +92,9 @@ def post_plant(
new_user = get_user_model().objects.get(id=value)
if user != new_user:
plant.user = new_user
elif attr == "area":
new_area = get_object_or_404(Area, id=value)
plant.area = new_area
else:
setattr(plant, attr, value)

Expand Down

0 comments on commit f20f328

Please sign in to comment.