분류 전체보기 썸네일형 리스트형 [Android Resources] Android Drawable android:state_pressed="true"> android:shape="rectangle"> android:color="#FF0000"/> android:width="2dp" android:color="#4b4c4c"/> android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp" android:topLeftRadius="12dp" android:topRightRadius="12dp"/> MAKE LIKE API /images/3/like/ 0. create the url and the view take the id from the url to find and image with id to create a like for image to check a like already exist 0. create the url and the view(views.py) 1 2 3 class LikeImage(APIView) : def get(self, request, format=None) : return Response(status=200) cs 1. take the id from the url (urls.py) 1 2 3 urlpatterns = [ path('/like/', view=views.LikeImage.as_v.. Feed API Feed User Serializer ============================== serializers.py class FeedUserSerializer(serializers.ModelSerializer) : class Meta : model = user_models.User fields = ( 'username', 'profile_image' ) ======================================= @property 1. Field of Model, but doesn't go database 2. is function ============================= modes.py def count_likes(self) : return self.likes.all().c.. REST FRAMEWORK - API View 1. http request function 2. Structure : 1. get = get method 2. self = pre defined varibles 3. request = request obj from the client 4. format = None(json), XML, json ... 3. Flow : 1. request datas with model 2. serialize data 3. return data 4. Serialize 5. return Response(data=serializer.data) ============ views.py ============ from rest_framework.views import APIView from rest_framework.respons.. REST FRAMEWORK - serializers >> python object json object ============ serializers.py ============ from rest_framework import serializers from . import models class ImageSerializer(serializers.ModelSerializser) : class Meta : model = models.Image fields = '__all__' class CommentSerializer(serializers.ModelSerializer) : class Meta : model = models.Comment fields = '__all__' class LikeSerializer(serializers.ModelSerializer) :.. REST FRAMEWORK - MAKE API "REST = Representational State Transfer" "EAST WAY TO MAKE API" HTTP "Hypertext Transfer Protocol" - Client(Request) Server(Response) - CRUD - Request (header, body) - Response (header, body) - Method 1. Get = READ (SELECT) 2. Post = CREATE (INSERT) 3. Put = UPDATE 4. Delete = DELETE Install 1. terminal > pipenv shell 2. terminal > pipenv install djangorestframework 3. check 'config > settings >.. Admin Panel ============ admin.py ============ > from django.contrib import admin from . import models @admin.register(models.Image) class ImageAdmin(admin.ModelAdmin): #add links list_display_links = ( 'location', 'caption' ) #add search var search_fields = ( 'location', ) #add filter list_filter = ( 'location', 'created_at', ) #set display columns list_display = ( 'file', 'location', 'caption', 'created_a.. Model Relationships 1. models.ForeignKey( ) - 1 to many - many to 1 2. models.ManyToManyField( ) many to many 이전 1 ··· 4 5 6 7 8 9 다음