0
models.pydjango的其餘框架用戶前綴
address_choices = (("home":"Home"),("shop", "Shop"))
class Address(models.Model):
address_type = models.CharField(max_length=128, choices=address_choices)
location = models.CharField(max_length=128)
forms.py
class AddressForm(forms.ModelForm):
class Meta:
model = Address
views.py
home_address = AddressForm(prefix="shop")
shop_address = AddressForm(prefix="home")
可以i的序列化器使用前綴只是喜歡,我使用的形式以上
串行器。 py
class AddressSerializers(serializers.ModelSerializer):
class Meta:
model = Address
views.py
home_serializer = AddressSerializers(prefix="home")
shop_serializer = AddressSerializers(prefix="shop")
有沒有辦法做到這一點 – tstudent
看看這個[django rest框架批量](https://github.com/miki725/django-rest-framework-bulk) –
@你可以看看這個https ://stackoverflow.com/questions/45319469/django-rest-framwork-iterate-throug-fields-in-model-serializer – tstudent