I’ve been stumped for days; hoping one of you wizards can get me out of this pickle…
I have a model called ExtraSlot
class ExtraSlot(models.Model): ....... employee = models.ForeignKey(Employee, on_delete = models.CASCADE, related_name="employee")
this is the serializer
class ExtraSlotSerializer(serializers.ModelSerializer): employee = EmployeeSerializer(many=True) <-- If I add this it tries to iterate through and errors out class Meta: model = ExtraSlot fields = (..... 'employee') fields = ('__all__') <- also used this to no avail depth = 3
I’m trying to add an Employee to the model; in the admin panel it is fine. The employee object can be selected. The DRF api doesn’t show anything; I’ve read HTML list input isn’t supported which is fine but the employee field as an input (even in raw format) doesn’t show at all.
Employee extends User (AbstractBaseUser) - here is the list error if I try many=true and passing the entire serializer.
Hope I’m clear enough - I just want to be able to pass an Employee to the other model/create the relationship =’( it’s been so long by brain is fried!
TypeError: ‘Employee’ object is not iterable (if I try pass EmployeeSerializer with many true; which makes sense.
employee = EmployeeSerialzer() - passes the entire object as if I want to create a new one?!