You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

222 lines
5.2 KiB

from generic_relations.relations import GenericRelatedField
from rest_framework.serializers import ModelSerializer, ImageField, FileField, SerializerMethodField, PrimaryKeyRelatedField
from .models import Project, Realty, BuildingClassfication, ConstructionType, Order, Stage, Portfolio, PortfolioPhoto, Answer, AnswerFile
from common.serializers import LocationSerializer
from specializations.serializers import SpecializationSerializer
from users.models import User, Team
from users.serializers import UserSerializer, TeamSerializer
class BuildingClassficationSerializer(ModelSerializer):
class Meta:
model = BuildingClassfication
fields = (
'id',
'name',
)
class ConstructionTypeSerializer(ModelSerializer):
class Meta:
model = ConstructionType
fields = (
'id',
'name',
)
class RealtySerializer(ModelSerializer):
building_classification = BuildingClassficationSerializer()
construction_type = ConstructionTypeSerializer()
location = LocationSerializer()
user = UserSerializer()
class Meta:
model = Realty
fields = (
'building_classification',
'construction_type',
'id',
'location',
'name',
'user',
)
class StageSerializer(ModelSerializer):
# order = OrderSerializer()
class Meta:
model = Stage
fields = (
'id',
'cost',
'cost_type',
'term',
'term_type',
'name',
'order',
'result',
'pos',
'status',
'is_paid',
'close_contractor',
'close_customer',
)
# def update(self, inst, validated_data):
# import code; code.interact(local=dict(globals(), **locals()))
# inst.id = validated_data.get('id',inst.id)
# inst.name = validated_data.get('name', inst.name)
# inst.cost = validated_data.get('cost', inst.cost)
# inst.order = validated_data.get('order', inst.order)
# inst.result = validated_data.get('result', inst.result)
# inst.save()
# return inst
class OrderSerializer(ModelSerializer):
stages = StageSerializer(many=True, read_only=True)
class Meta:
model = Order
fields = (
'id',
'contractor',
'team',
'created',
'project',
'secure',
'status',
'stages',
)
class ProjectSerializer(ModelSerializer):
customer = UserSerializer()
specialization = SpecializationSerializer()
realty = RealtySerializer()
class Meta:
model = Project
fields = (
'budget',
'budget_by_agreement',
'created',
'cro',
'currency',
'customer',
'deal_type',
'id',
'name',
'price_and_term_required',
'realty',
'specialization',
'state',
'term',
'term_type',
'text',
'work_type',
)
class PortfolioPhotoSerializer(ModelSerializer):
img = ImageField()
portfolio_id = PrimaryKeyRelatedField(read_only=True, source='portfolio')
class Meta:
model = PortfolioPhoto
fields = (
'id',
'img',
'portfolio_id',
)
class PortfolioSerializer(ModelSerializer):
# answers = AnswerSerializer(many=True)
building_classification = BuildingClassficationSerializer()
construction_type = ConstructionTypeSerializer()
location = LocationSerializer()
photos = PortfolioPhotoSerializer(many=True)
specialization = SpecializationSerializer()
user = UserSerializer()
class Meta:
model = Portfolio
fields = (
# 'answers',
'budget',
'building_classification',
'construction_type',
'currency',
'description',
'id',
'location',
'name',
'photos',
'specialization',
'term',
'term_type',
'user',
'worksell',
)
class AnswerFileSerializer(ModelSerializer):
file = FileField()
class Meta:
model = AnswerFile
fields = (
'file',
'id',
'name',
# 'answer',
)
class AnswerSerializer(ModelSerializer):
files = AnswerFileSerializer(many=True)
portfolios = PortfolioSerializer(many=True)
project = ProjectSerializer
author = GenericRelatedField({
User: UserSerializer(),
Team: TeamSerializer()
})
class Meta:
model = Answer
fields = (
'budget',
'created',
'currency',
'id',
'secure_deal_only',
'term',
'term_type',
'text',
'files',
'portfolios',
'project',
'author', # Generic related field
# 'candidates',
)