Хочу вывести список, но выдает ошибку
'Type' object has no attribute 'typeram'
Models.py
class Frequency(models.Model):
title = models.IntegerField(verbose_name='Частота ОЗУ',default=3200)
def __str__(self):
return f'{self.title}'
class Meta:
verbose_name = 'Частота ОЗУ'
verbose_name_plural = 'Добавить Частоту ОЗУ'
class Type(models.Model):
title = models.CharField(verbose_name='Тип ОЗУ',max_length=10, default='DDR4')
def __str__(self):
return f'{self.title}'
class Meta:
verbose_name = 'Тип ОЗУ'
verbose_name_plural = 'Добавить ОЗУ'
class Ram(models.Model):
title = models.CharField(verbose_name='Название',max_length=20)
image = models.ImageField(verbose_name='Изображение',upload_to='Image/Ram_Image')
RamIncluded = models.IntegerField(verbose_name='Количество Плашек',default=2)
OneRam = models.IntegerField(verbose_name='Количество Памяти',default=8)
typeram = models.ManyToManyField(Type, verbose_name='Тип ОЗУ')
Ramfrequency = models.ManyToManyField(Frequency,verbose_name='Частота ОЗУ')
def __str__(self):
return f'{self.title}'
class Meta:
verbose_name = 'ОЗУ'
verbose_name_plural = 'Добавить ОЗУ'
serializers.py
class FrequencyListSerializer(serializers.ModelSerializer):
class Meta:
model = Frequency
fields = '__all__'
class TypeListSerializer(serializers.ModelSerializer):
class Meta:
model = Type
fields = '__all__'
class RamListSerializer(serializers.ModelSerializer):
typeram = serializers.SerializerMethodField(source='get_Type')
Ramfrequency = serializers.SerializerMethodField(source='get_Ramfrequency')
class Meta:
model = Ram
fields = '__all__'
def get_Ramfrequency(self, obj):
return FrequencyListSerializer(obj.Ramfrequency, many=True).data
def get_typeram(self, obj):
return TypeListSerializer(obj.typeram, many=True).data