práctica de ttps
python3 -m venv .venv
source .venv/bin/activate pip install django
cd ttps_test ttps_test$ python3 manage.py runserver
python3 manage.py startapp persons
buen ejemplo del tema de uuids como claves primarias. https://tech.serhatteker.com/post/2020-01/uuid-primary-key/
generar las tablas para el modelo de una app.
(.venv) pablo@xiaomi:/src/github/facu-infor/ttps/ttps_test$ python3 manage.py makemigrations persons Migrations for 'persons': persons/migrations/0001_initial.py
muy buena referencia a como manejar las relaciones en las consultas. https://stackoverflow.com/questions/7495126/django-model-foreignkeys-question
dado: class Employees(models.Model): ...
class Expenses(models.Model): ... employee = models.ForeignKey(Employees)
1 - employee = Employee.objects.get(name='John Doe') employee_expenses = employee.expenses.all()
2- employee_expenses = Employee.objects.get(name='John Doe').expenses.all()
3- employee_expenses = Expense.objects.filter(employee__name="John Doe")
el __ desreferencia el objeto employee
https://docs.djangoproject.com/en/3.2/topics/db/queries/#backwards-related-objects