📄️ Model Fields And Validations
So far we have only worked with two field types in relation to models
📄️ Filters
Using a model's filter() function you can query to the database with certain conditions. For example, to retrieve all courses with more than ten enrolled students you can write:
📄️ Models And Forms
In the forms chapter we saw how to generate this form:
📄️ Adding Fields to Models With Pre-existing Data
When you add a field to a model that already has stored data, Django must populate that field with some value for the pre-existing data. For example, consider the following model:
📄️ Fields With Reference to Other Models
It's time to move forward with our course management tool. We need to create a model to save teacher information, so we can have each course assigned to a teacher. Let's start with the model definition by adding in models.py: