class PostListSerializer(ModelSerializer): url = HyperlinkedIdentityField( view_name='post-api:detail', lookup_field='slug') class Meta: model = Post fields = ['title', 'user', 'slug', 'content', 'url']
class NestedBGPPeerGroupSerializer(WritableNestedSerializer): url = HyperlinkedIdentityField(view_name='plugins:netbox_bgp:peergroup') class Meta: model = BGPPeerGroup fields = ['id', 'url', 'name', 'description'] validators = []
class BillSerializer(serializers.HyperlinkedModelSerializer): detail = HyperlinkedIdentityField(view_name='bill-detail') class Meta: model = Bill fields = ('BID', 'name', 'description', 'date_introduced', 'status', 'voted_on', 'chamber', 'date_voted', 'url', 'detail')
class RatingSerializer(ModelSerializer): href = HyperlinkedIdentityField(view_name='api_v2:videos-rating') likes_count = serializers.SerializerMethodField() likes = serializers.SerializerMethodField() def __init__(self, obj, *args, **kwargs): request = kwargs.pop('request') super(RatingSerializer, self).__init__(obj, *args, **kwargs) self.context['request'] = request def get_likes_count(self, obj): return obj.likes def get_likes(self, obj): return ContextUtils(self.context)\ .build_absolute_uri(reverse('api_v2:video-likes-list', [obj.video.id])) class Meta: model = Rating fields = ( 'video', 'href', 'likes_count', 'likes', ) read_only_fields = ( 'video', 'href', 'likes_count', 'likes', )
class UserSerializer(serializers.HyperlinkedModelSerializer): href = HyperlinkedIdentityField(view_name='api_v2:users-detail') class Meta: model = User fields = ('id', 'href', 'username', 'first_name', 'last_name', 'date_joined', 'last_login', 'is_staff', 'is_active')
class SimplePublisherSerializer(DynamicFieldsModelSerializer): id = HiddenField(default=None) url = HyperlinkedIdentityField(view_name='publishers:publisher-detail') class Meta: model = Publisher fields = ('id', 'url', 'publisher_iati_id', 'display_name', 'name')
class CommentListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='comments-api:thread') reply_count = SerializerMethodField() user = serializers.CharField(source='user.username') # timestamp = serializers.DateTimeField(format="%s") timestamp = serializers.DateTimeField(format="%Y-%m-%d / %H:%M:%S") class Meta: model = Comment fields = [ 'url', 'id', # 'content_type', # 'object_id', # 'parent', 'content', 'reply_count', 'timestamp', 'user' ] def get_reply_count(self, obj): if obj.is_parent: return obj.children().count() return 0
class SimplePublisherSerializer(DynamicFieldsModelSerializer): url = HyperlinkedIdentityField(view_name='publishers:publisher-detail') class Meta: model = Publisher fields = ('id', 'url', 'org_id', 'org_abbreviate', 'org_name')
class LaptopsRegisterListSerializer(ModelSerializer): url = new_detail_url user = UserDetailSerializer(read_only=True) delete_url = HyperlinkedIdentityField( view_name='laptopreg-api:delete', lookup_field='pk' #or primary key <pk> ) class Meta: model = LaptopsRegister fields = [ 'url', 'id', 'user', 'color', 'serialnumber', 'make', 'macaddress', 'ownership', 'model', 'barcode' 'updated', 'timestamp', 'delete_url', ]
class SensorModelSerializer(HyperlinkedModelSerializer): """ Class SensorModelSerializer - serializer for Sensor model Fields: 'id', 'sensor_title', 'sensor_data_type', 'sensor_device', 'sensor_serial_number', """ sensor_collected_data_url = HyperlinkedIdentityField(view_name='sensor-collected-data') class Meta: model = Sensor fields = ( 'id', 'url', 'sensor_title', 'sensor_data_type', 'sensor_device', 'sensor_serial_number', 'sensor_collected_data_url' )
class PostDetailSerializer(ModelSerializer): url = HyperlinkedIdentityField( view_name='posts-api:post_detail', lookup_field='id', ) user = SerializerMethodField() image = SerializerMethodField() class Meta: model = Post fields = [ 'user', 'url', 'id', 'title', 'content', 'publish', 'image', ] def get_user(self, obj): return str(obj.user.username) def get_image(self, obj): try: image = obj.image.url except: image = None return image
class HubModelSerializer(HyperlinkedModelSerializer): """ Class HubModelSerializer - serializer for Hub model @param owner - Related object field of the UserBaseSerializer requierd=False kwarg setted for creation mathod. Owner relates automaticaly on create. Fields: 'id', 'hub_title', 'hub_serial_number', 'owner' """ devices_url = HyperlinkedIdentityField(view_name='hub-devices') owner = UserBaseSerializer(required=False) class Meta: model = Hub fields = ( 'id', 'url', 'hub_title', 'hub_serial_number', 'owner', 'devices_data_fetch_time', 'hub_data_update_time', 'devices_url' )
class PostListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='posts-api:detail', lookup_field='slug') user = SerializerMethodField() likes = SerializerMethodField() image = SerializerMethodField() class Meta: model = Post fields = ( 'url', 'id', 'user', 'title', 'slug', 'publish', 'likes', 'image', ) def get_user(self, obj): return str(obj.user.username) def get_likes(self, obj): return obj.likes.count() def get_image(self, obj): try: image = obj.image.url except: image = None return image
class PostRetrieveSerializer(ModelSerializer): delete_url = HyperlinkedIdentityField(view_name='posts_api:delete', lookup_field='slug') user = SerializerMethodField() image = SerializerMethodField() markdown_html = SerializerMethodField() class Meta: model = Post fields = [ 'user', 'id', 'title', 'slug', 'content', 'markdown_html', 'publish', 'delete_url', ] def get_markdown_html(self, obj): return obj.get_markdown() def get_user(self, obj): user = obj.user.get_full_name() if not user: user = obj.user.username return str(user) def get_image(self, obj): try: image = obj.image.url except Exception: image = None return image
class CommentListSerializer(ModelSerializer): url = HyperlinkedIdentityField( view_name="api:comments:thread", read_only=True, lookup_field="uuid", ) user = SerializerMethodField() reply_count = SerializerMethodField() class Meta: model = Comment fields = [ "id", "user", "parent", "body", "created_on", "reply_count", "url", ] def get_user(self, obj): user_obj = obj return str(user_obj.user.username) def get_reply_count(self, obj): if obj.is_parent: return obj.children().count() return 0
class CommentListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='comments-api:thread', ) user = UserDetailSerializer(read_only=True) reply_count = SerializerMethodField() class Meta: model = Comment fields = [ 'id', 'url', 'user', # 'content_type', # 'object_id', # 'parent', 'timestamp', 'content', 'reply_count', ] def get_reply_count(self, obj): if obj.is_parent: return obj.children().count() return 0
class CreditListSerializer(serializers.ModelSerializer): url = HyperlinkedIdentityField(view_name='product-api:sales-details') credititems = ItemsSerializer(many=True) cashier = SerializerMethodField() class Meta: model = Credit fields = ( 'id', 'user', 'invoice_number', 'total_net', 'sub_total', 'url', 'balance', 'terminal', 'amount_paid', 'credititems', 'customer', 'mobile', 'customer_name', 'cashier', 'status', 'total_tax', 'discount_amount', 'due_date', 'debt', ) def get_cashier(self, obj): name = User.objects.get(pk=obj.user.id) return name.name
class PhotoListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='api_photos:read', lookup_field='pk') album_title = SerializerMethodField() space_id = SerializerMethodField() space_name = SerializerMethodField() uploaded_by_name = SerializerMethodField() class Meta: model = Photo fields = [ 'url', 'id', 'album', 'album_title', 'space_id', 'space_name', 'title', 'slug', 'uploaded_by', 'uploaded_by_name', 'summary', 'picture', 'picture_height', 'picture_width', 'updated_dateTime', 'created_dateTime' ] def get_album_title(request, obj): return str(obj.album.title) def get_space_id(request, obj): return str(obj.album.space.id) def get_space_name(request, obj): return str(obj.album.space.title) def get_uploaded_by_name(request, obj): return str(obj.author.first_name) + " " + str(obj.author.last_name)
class SimpleDatasetSerializer(DynamicFieldsModelSerializer): id = HiddenField(default=None) url = HyperlinkedIdentityField(view_name='datasets:dataset-detail') publisher = HyperlinkedRelatedField( view_name='publishers:publisher-detail', read_only=True) type = SerializerMethodField() class Meta: model = Dataset fields = ( 'id', 'iati_id', 'type', 'url', 'name', 'title', 'filetype', 'publisher', 'source_url', 'iati_version', 'added_manually', ) def get_type(self, obj): return obj.get_filetype_display()
class CommentListSerializer(ModelSerializer): user = SerializerMethodField() try: comment_detail_url = HyperlinkedIdentityField( view_name='comments_api:thread', lookup_field='id', ) except: comment_detail_url = None reply_count = SerializerMethodField() class Meta: model = Comment fields = [ 'user', 'id', 'comment_detail_url', 'object_id', 'content_type', 'parent', 'content', 'timestamp', 'reply_count' ] def get_user(self, obj): return str(obj.user.username) def get_reply_count(self, obj): if obj.is_parent: return obj.children().count() return None
class CommentListSerializer(ModelSerializer): """ 评论列表 """ url = HyperlinkedIdentityField(view_name='comment:detail', ) post = HyperlinkedRelatedField( view_name='post:detail', read_only=True, ) user = HyperlinkedRelatedField( view_name='userprofile:detail', read_only=True, ) post_title = SerializerMethodField() user_name = SerializerMethodField() created = TimestampField() class Meta: model = Comment fields = [ 'url', 'post', 'user', 'post_title', 'user_name', 'content', 'created', ] def get_post_title(self, instance): return instance.post.title def get_user_name(self, instance): return instance.user.username
class CustomerListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='expert_api:customer_list_detail', lookup_field='pk') delete_url = HyperlinkedIdentityField( view_name='expert_api:customer_list_delete', lookup_field='pk') user = SerializerMethodField() class Meta: model = Customer fields = [ 'url', 'id', 'company_name', 'contact_name', 'contact_email', 'user', 'delete_url' ] def get_user(self, obj): return str(obj.user.name)
class HomesListSerializer(ModelSerializer): url = new_detail_url user = UserDetailSerializer(read_only=True) delete_url = HyperlinkedIdentityField( view_name='home-api:delete', lookup_field='pk' #or primary key <pk> ) class Meta: model = Home fields = [ 'url', 'id', 'user', 'title', 'content', 'banner', 'banner1', 'banner2', 'banner3', 'link_url', 'updated', 'timestamp', 'delete_url', ]
class MarkerListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='expert_api:marker_list_detail', lookup_field='pk') delete_url = HyperlinkedIdentityField( view_name='expert_api:marker_list_delete', lookup_field='pk') chamber = SerializerMethodField() class Meta: model = Marker fields = [ 'url', 'id', 'time', 'chamber', 'marker_name', 'marker_string', 'delete_url' ] def get_chamber(self, obj): return str(obj.chamber.chamber_name)
class EmployeeSerializer(ModelSerializer): profile = HyperlinkedIdentityField(view_name='department:emp-detail', source='Employee') class Meta: model = Employee fields = ['emp_name', 'profile']
class ArticleListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='api_article:detail', ) column = SerializerMethodField() comic = SerializerMethodField() # comment_counts = SerializerMethodField() class Meta: model = ArticlesPost fields = [ 'url', 'id', 'title', 'column', 'comic', # 'comment_counts', 'total_views', ] def get_column(self, obj): if obj.column: return str(obj.column) else: return None def get_comic(self, obj): if obj.comic: return str(obj.comic) else: return None
class MemberListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='api_members:read', lookup_field='pk') username = SerializerMethodField() first_name = SerializerMethodField() last_name = SerializerMethodField() class Meta: model = Member fields = [ 'url', 'username', 'first_name', 'last_name', 'status', 'is_soronian_sister', 'is_independent', 'is_site_visitor', 'about_me', 'picture', 'pledge_class', 'graduation_year', 'birth_date', 'house_positions', \ 'profiled', 'profiled_dateTime', \ 'validated', 'validated_by', 'validated_dateTime', \ 'activated', 'activated_by', 'activated_dateTime', \ 'updated_dateTime', 'created_dateTime' ] def get_username(self, obj): return obj.user.username def get_first_name(self, obj): return obj.user.first_name def get_last_name(self, obj): return obj.user.last_name
class PostListSerializer(ModelSerializer): url = HyperlinkedIdentityField(view_name='posts-detail', lookup_field='id') user = UserDetailSerializer(read_only=True) class Meta: model = Post fields = ['id', 'url', 'user', 'title', 'content', 'publish']
class LegislatorSerializer(serializers.HyperlinkedModelSerializer): detail = HyperlinkedIdentityField(view_name='legislator-detail') class Meta: model = Legislator fields = ('LID', 'fullname', 'district', 'state', 'senator', 'affiliation', 'dwnominate', 'url', 'detail')
class PatientListSerializer(ModelSerializer): url = patient_detail_url user = UserDetailSerializer(read_only=True) delete_url = HyperlinkedIdentityField( view_name='patients-api:delete', lookup_field='id'#or primary key <pk> ) class Meta: model = Patient fields = [ 'url', 'user', 'id', 'delete_url', 'patient_name', 'patient_id', 'heart_rate', 'patient_history', 'recommended_diagnosis', 'respiratory_rate', 'temperature', 'blood_pressure', 'active', 'updated', 'timestamp' ] # def get_user(self, obj): # return str(obj.user.username)