Hello!
How to disable list of ForeignKey model field objects in OPTION method?
f.e.
Model:
class Model(models.Manager):
address = models.ForeignKey(Address)
class ModelSerializer(serializers.ModelSerializer):
class Meta:
model = Model
fields = 'address'
Then we use
class ModelList(generics.GenericAPIView,
mixins.CreateModelMixin,
mixins.ListModelMixin)
in a view.
When we have Meta, than we have access to OPTIONS HTTP method.
When we request OPTIONS we got like a
"address": {
....
"choices": [{
"id": "1",
}, {
"id": "2",
}, {
"id": "3",
} etc ]...
}
So, it Address.objects.all() in choices, but i don't want show address list at all. And i want to set any address (we know id, for example), when i save (create, update) Model instance.
Should i use:
class ModelSerializer(serializers.ModelSerializer):
address_pk = serializers.IntegerField(source='address')
class Meta:
model = Model
fields = 'address_pk'
instead? But what about ManyToManyField in this case?