Login and get coding
In order to measure daily food intake as a user our current
Foodmodel is not enough. We also need
FoodEntrymodels, so let's create them!
FoodEntryis a many-to-many relation between
Food. Users would add many foods and foods will be added by many users.
For this learning path, we'll work with these Pydantic models in memory to keep things simpler. In the SQLModel learning path we'll use a database.
FoodEntrymodels based on what you learned in the second FastAPI Bite in this series.
Required attributes and their types:
str(needed for authentication later)
passwordoverride the constructor (
__init__.py) to hash the password upon creation of the module. You can use the provided
get_password_hash()function for this.
int(what in a DB would be the primary key)
User(here we see that Pydantic models can be nested)
Food(from previous Bite and provided in the template)
float(fitness nerds can be quite exact about this)
* Additionally add a property to calculate the total calories of a food entry (
number_servings * food.kcal_per_serving) and call it
Good luck and in the next Bite we'll expand our API to work with these new objects.