fix setting new related model just from dict with pkname

This commit is contained in:
collerek
2020-08-23 13:15:04 +02:00
parent 53384879a9
commit 806fe9b63e
4 changed files with 7 additions and 3 deletions

View File

@ -133,6 +133,8 @@ async def test_model_crud():
assert album1.pk == 1
assert album1.tracks is None
await Track.objects.create(album={"id": track.album.pk}, title="The Bird2", position=4)
@pytest.mark.asyncio
async def test_select_related():

View File

@ -61,13 +61,13 @@ def create_test_database():
@app.get("/items/", response_model=List[Item])
async def get_items():
items = await Item.objects.select_related("category").all()
return [item.dict() for item in items]
return items
@app.post("/items/", response_model=Item)
async def create_item(item: Item):
item = await Item.objects.create(**item.dict())
return item.dict()
await item.save()
return item
@app.post("/categories/", response_model=Category)