django rest从angular2前端创建模型实例

时间:2016-12-28 18:33:30

标签: django django-rest-framework

我有一个django休息后端有几个模型如下:

class Hall(Product):
    product = models.OneToOneField(Product, parent_link=True, )
    localities = ChainedForeignKey(
        Localities, 
        chained_field="city",
        chained_model_field="city", 
        show_all=False, 
        auto_choose=True,
        sort=True
    )

    landmarks = models.CharField(max_length=50, blank=False, verbose_name="Landmarks of the Marriage Hall", )
    seating_capacity = models.IntegerField(null=False, verbose_name="Seating capacity of the Marriage Hall",)
    ac = models.BooleanField(null=False, verbose_name="Is the Marriage Hall AC?",)
    garden_lounge = models.BooleanField(null=False, verbose_name="Is the Marriage Hall garden_lounge?",)
    comments = models.CharField(max_length=50, blank=False, verbose_name="Customer comments for this Marriage Hall", )
    gallery = models.ForeignKey(Gallery, related_name='halls')

如果我必须从我的angular2前端创建/更新/删除模型实例(这是完全独立的),我需要遵循哪些步骤?

现在,除了以下模型之外,我还有序列化器:

class HallSerializer(serializers.ModelSerializer):
    category = serializers.ReadOnlyField()
    class Meta:
            model = Hall
            fields = '__all__'

另外,正如您所看到的,此特定模型的其他模型为 OneToOne ChainedForeignKey ,如何处理?

1 个答案:

答案 0 :(得分:-1)

冒着不直接回答问题的风险:我们使用Django Rest Framework提供我们基于角度的前端与之交互的REST API。