Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from rest_framework import serializers
- from django.contrib.auth.models import User
- from .models import Company, Category, Product, Offer, Attribute
- class UserSerializer(serializers.ModelSerializer):
- class Meta:
- model = User
- fields = [
- 'username',
- 'first_name',
- 'last_name',
- 'email'
- ]
- class CompanySerializer(serializers.ModelSerializer):
- class Meta:
- model = Company
- fields = [
- 'id',
- 'user',
- 'name',
- 'inn',
- 'address',
- 'phone',
- 'mail',
- 'logo',
- 'balance',
- 'date',
- 'slug',
- 'active'
- ]
- class CategorySerializer(serializers.ModelSerializer):
- class Meta:
- model = Category
- fields = [
- 'id',
- 'name',
- 'slug',
- 'image'
- ]
- lookup_field = 'slug'
- extra_kwargs = {
- 'url': {'lookup_field': 'slug'}
- }
- class ProductSerializer(serializers.ModelSerializer):
- class Meta:
- model = Product
- fields = [
- 'id',
- 'name',
- 'number',
- 'slug',
- 'image',
- 'category'
- ]
- class OfferSerializer(serializers.ModelSerializer):
- class Meta:
- model = Offer
- fields = [
- 'product',
- 'company',
- 'price',
- 'active'
- ]
- class AttributeSrializer(serializers.ModelSerializer):
- class Meta:
- model = Attribute
- feilds = [
- 'key',
- 'value',
- 'product'
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement