Junior — Middle
Have you worked with class-based models in Django?
sobes.tech AI
Answer from AI
In Django, models are usually defined as classes inheriting from django.db.models.Model. This allows describing the database table structure through class attributes, which correspond to table fields.
Example of a simple model:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
This approach makes it convenient to work with data via ORM, create migrations, and manage the database schema without writing SQL.