I would like to be able to instantiate my Job
entities via the browsable API (of django-rest-framework), however my employer field has the field editable=False
. Therefore the employer entry box does not appear.
This is what I see when editable=False (code further below):
(Image) POST form without employer entry box
This is what I see when I remove editable=False (code further below):
(Image) POST form with employer entry box
How can I get employer box to show whilst not allowing the employer field not to be changed after it is first set? (So that it will look like the second image)
models.py
from django.db import models
from users.models import Proof_User
class Job(models.Model):
title = models.CharField(max_length=254, blank=False, null=False)
description = models.TextField(blank=True)
employer = models.ForeignKey(Proof_User, editable=False, related_name='jobs', blank=False, null=False)
serializers.py
class Job_Serializer(serializers.ModelSerializer):
class Meta:
model = Job
fields = ('id', 'title', 'description', 'employer',)
views.py
class Job_Viewset(viewsets.ModelViewSet):
queryset = Job.objects.all()
serializer_class = Job_Serializer