1

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
Def_Os
  • 5,301
  • 5
  • 34
  • 63
Stefan Collier
  • 4,314
  • 2
  • 23
  • 33
  • 1
    See the answer [here](http://stackoverflow.com/a/34528153/1571826) for a good explanation of why you don't see the field, and how you could display it. – Def_Os Nov 10 '16 at 00:45

0 Answers0