models.py
class Testimonials(models.Model):
client = 'client'
employee = 'employee'
general = 'general'
Testimonial_Choices = (
('client', 'client'),
('employee', 'employee'),
('general', 'general'),
)
testimonial_type=models.CharField(max_length=25, choices=Testimonial_Choices, default=client)
if testimonial_type=='client':
client_name= models.ForeignKey(Client, on_delete=models.CASCADE)
content= models.TextField(max_length=500, blank=False)
posted_date= models.DateField(auto_now_add=True)
def __str__(self):
return self.client_name
admin.py
class TestimonialAdmin(admin.ModelAdmin):
list_display = ('testimonial_type', 'posted_date')
list_filter = ('testimonial_type', 'posted_date')
search_fields = ['testimonial_type', 'posted_date']
empty_value_display = '-- NA --'
list_per_page = 10
admin.site.register(Testimonials, TestimonialAdmin)
Сначала я пытаюсь добавить поле выбора, и если тип выбора - клиент, я хочу получить имя клиента и изображение
ошибка
AttributeError: 'Testimonials' object has no attribute 'client_name'