Answer the question
In order to leave comments, you need to log in
How to write a serializer?
Hello. I don't know much about drf. There are three models
# Create your models here.
class Years(models.Model):
decadence = models.IntegerField(verbose_name="Десятилетие", primary_key=True)
def __str__(self):
"""Возвращает строковое представление модели"""
return str(self.decadence)
class Year(models.Model):
year = models.IntegerField(verbose_name="Год выпуска", primary_key=True)
photo = models.ImageField(verbose_name="Фотография года")
decadence = models.ForeignKey(Years, on_delete=models.CASCADE)
def __str__(self):
"""Возвращает строковое представление модели"""
return str(self.year)
class Person(models.Model):
name = models.CharField(max_length=50, verbose_name="Имя и фамилия")
x_position = models.DecimalField(verbose_name="Отступ слева", default=0, decimal_places=5, max_digits=10)
y_position = models.DecimalField(verbose_name="Отступ сверху", default=0, decimal_places=5, max_digits=10)
year = models.ForeignKey(Year, on_delete=models.CASCADE)
def __str__(self):
return self.name
{
"2010": {
"2011": {
"photo": "img",
"persons": {
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
}
},
"2015": {
"photo": "img",
"persons": {
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
}
},
},
"2020": {
"2022": {
"photo": "img",
"persons": {
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
}
},
"2023": {
"photo": "img",
"persons": {
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
{
"name": "имя",
"x_position": "12"
"y_position": "34
},
}
},
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question