Remove product resolution from /order endpoint

This commit is contained in:
fnux 2020-02-27 20:37:19 +01:00
commit b1649a6228
3 changed files with 2 additions and 38 deletions

View file

@ -23,42 +23,13 @@ class PaymentMethodSerializer(serializers.ModelSerializer):
fields = ['owner', 'primary', 'source', 'description']
class ProductSerializer(serializers.Serializer):
vms = VMProductSerializer(many=True, required=False)
def create(self, validated_data):
owner = validated_data.pop('owner')
order = validated_data.pop('order')
vms = validated_data.pop('vms')
for vm in vms:
VMProduct.objects.create(owner=owner, order=order, **vm)
return True # FIXME: shoudl return created objects
vms = VMProductSerializer(many=True, read_only=True)
class OrderSerializer(serializers.ModelSerializer):
products = ProductSerializer()
class Meta:
model = Order
fields = '__all__'
def create(self, validated_data):
products_data = validated_data.pop('products')
validated_data['owner'] = self.context["request"].user
# FIXME: find something to do with this:
validated_data['recurring_price'] = 0
validated_data['one_time_price'] = 0
order = Order.objects.create(**validated_data)
# Forward product creation to ProductSerializer.
products = ProductSerializer(data=products_data)
products.is_valid(raise_exception=True)
products.save(order=order,owner=order.owner)
return order
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()