Я получаю следующую ошибку и не могу ее выяснить:
TypeError: str вернул не-строку (тип Leads)
class Leads(models.Model):
name = models.CharField(max_length=250, default=0)
contact_person_name = models.CharField(max_length=250, default=0 ,blank=True, null=True)
email = models.EmailField(max_length=250, default=0, blank=True, null=True)
created_by = models.ForeignKey("packsapp.Employee", on_delete=models.CASCADE, related_name='createdby')
def __str__(self):
return self.name
class Pfep(models.Model):
client = models.ForeignKey(Leads, on_delete=models.CASCADE, related_name='vendor_owner')
receiver = models.CharField(max_length=250, default=0 ,blank=True, null=True)
receiver_location = models.CharField(max_length=250, default=0 ,blank=True, null=True)
def __str__(self):
return self.client
class PPboxSol(models.Model):
box_length = models.IntegerField(default=0, blank=True, null=True)
box_breadth = models.IntegerField(default=0, blank=True, null=True)
box_height = models.IntegerField(default=0, blank=True, null=True)
created_on = models.DateField(auto_now_add=True)
pfep = models.ForeignKey(Pfep, on_delete=models.CASCADE, related_name='pfep_box_sol')
created_by = models.ForeignKey("packsapp.Employee", on_delete=models.CASCADE, related_name='ppbox_createdby')
Views.py
class PpboxsolFormView(CreateView):
model = PPboxSol
form_class = Ppboxsolform
template_name = 'pfep/PpboxsolForm.html'
def get_initial(self):
initial = super().get_initial()
initial['pfep'] = Pfep.objects.get(pk=self.kwargs['pk'])
return initial
def form_valid (self, form):
if self.request.user.employee.employee_role == 'admin':
product = form.save(commit=False)
product.created_by = Employee.objects.filter(user=self.request.user.id)[0]
product.save()
messages.success(self.request, 'The PP Box Solution was created with success!')
return redirect('emp:ppbox_table')
else:
messages.success(self.request, "You don't have permission to create Solution!")
return redirect('emp:ppbox_table')
return redirect('emp:pfep_table')
Urls.py
path('ppboxsol/add/<int:pk>/', PpboxsolFormView.as_view(), name='ppbox_form'),
Нужно ли также добавить def __str__(self):
к модели PPboxSol
?
Редактировать:
Я также добавил модель Leads
, но она также возвращает str