Skip to content
Snippets Groups Projects
Commit e51adc09 authored by 김시환's avatar 김시환
Browse files

add ã… user and univ search

parent 70467292
No related branches found
No related tags found
1 merge request!1Mymy
from django.urls import path
from .views import UploadFeed, LikeFeed, DeleteFeed
from .views import UploadFeed, LikeFeed, DeleteFeed, searchUniv, searchUser
urlpatterns = [
path('upload', UploadFeed.as_view(), name='upload_feed'),
path('delete', DeleteFeed.as_view(), name='delete_feed'),
path('like', LikeFeed.as_view(), name='like'),
path('searchUniv', searchUniv.as_view(), name='seacrh_univ'),
path('searchUser', searchUser.as_view(), name='search_user'),
]
......@@ -91,3 +91,28 @@ class DeleteFeed(APIView):
return render(request, "jinstagram/main.html") #프로필페이지
else:
return Response(status=500, data=dict(message='삭제 실패'))
class searchUniv(APIView):
def get(self, request):
# search_word = request.data.get('univ')
search_word = '대학'
univ_list = Univ.objects.filter(univ__contains=search_word).values('univ')
if univ_list.count() == 0:
return Response(status=404, data=dict(message='대학이 없습니다.'))
else:
return Response(status=200, data=dict(univ=univ_list))
class searchUser(APIView):
def get(self, request):
# search_word = request.data.get('user')
search_word = 's1'
user_list = Feed.objects.filter(user_id__contains=search_word) # .values() 뭐 필요?
print(user_list)
if user_list.count() == 0:
return Response(status=404, data=dict(message='유저가 없습니다.'))
else:
return Response(status=200, data=dict(user=user_list))
\ No newline at end of file
......@@ -41,12 +41,14 @@ class Ranking(APIView):
def get(self, request):
univ_list = Feed.objects.values('univ')\
.annotate(score=Count('univ') + Sum('views') + Sum('like_count'))
.annotate(score=Count('univ') + Sum('views') + Sum('like_count'))\
.order_by('-score')
print(univ_list)
for i in range(len(univ_list)):
print(i, univ_list[i]['univ'])
return render(request,
'jinstagram/main.html',
'jinstagram/ranking.html',
context=dict(univ_list=univ_list))
......@@ -67,7 +69,6 @@ class Profile(APIView):
for feed in feed_object_list:
like_count = FeedLike.objects.filter(feed_id=feed.id, is_like=True).count()
is_like = FeedLike.objects.filter(feed_id=feed.id, is_like=True, email=email).exists()
reply_count = Reply.objects.filter(feed_id=feed.id).count()
row_feed_list.append(dict(
id=feed.id,
profile_image=feed.profile_image,
......@@ -76,7 +77,6 @@ class Profile(APIView):
content=feed.content,
like_count=like_count,
is_like=is_like,
reply_count=reply_count
))
if len(row_feed_list) == 3:
......@@ -86,42 +86,9 @@ class Profile(APIView):
if len(row_feed_list) > 0:
feed_list.append(dict(row_feed_list=row_feed_list))
following_count = Follow.objects.filter(follower=email, is_live=True).count()
follower_count = Follow.objects.filter(following=email, is_live=True).count()
bookmark_list = Bookmark.objects.filter(email=email, is_bookmarked=True).order_by('-id')
bookmark_feed_list = []
row_bookmark_feed_list = []
for bookmark in bookmark_list:
feed = Feed.objects.filter(id=bookmark.feed_id).first()
if feed is None:
continue
like_count = FeedLike.objects.filter(feed_id=feed.id, is_like=True).count()
is_like = FeedLike.objects.filter(feed_id=feed.id, is_like=True, email=email).exists()
reply_count = Reply.objects.filter(feed_id=feed.id).count()
row_bookmark_feed_list.append(dict(
id=feed.id,
profile_image=feed.profile_image,
user_id=feed.user_id,
image=feed.image,
content=feed.content,
like_count=like_count,
is_like=is_like,
reply_count=reply_count
))
if len(row_bookmark_feed_list) == 3:
bookmark_feed_list.append(dict(row_bookmark_feed_list=row_bookmark_feed_list))
row_bookmark_feed_list = []
if len(row_bookmark_feed_list) > 0:
bookmark_feed_list.append(dict(row_bookmark_feed_list=row_bookmark_feed_list))
return render(request,
'jinstagram/profile.html',
context=dict(feed_list=feed_list,
bookmark_feed_list=bookmark_feed_list,
feed_count=feed_count,
following_count=following_count,
follower_count=follower_count,
user=user))
......@@ -44,48 +44,17 @@
<thead>
<tr>
<th scope="col">순위</th>
<th scope="col">이미지</th>
<th scope="col">학교</th>
<th scope="col">등록자</th>
<th scope="col">조회수</th>
<th scope="col">점수</th>
</tr>
</thead>
<tbody>
{% for univ in univ_list %}
<tr>
<th scope="row">1</th>
<td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td>
<td class="align-middle">아주대학교</td>
<td class="align-middle">아주대사랑꾼</td>
<td class="align-middle">123</td>
</tr>
<tr>
<th scope="row">2</th>
<td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td>
<td class="align-middle">아주대학교</td>
<td class="align-middle">아주대사랑꾼</td>
<td class="align-middle">123</td>
</tr>
<tr>
<th scope="row">3</th>
<td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td>
<td class="align-middle">아주대학교</td>
<td class="align-middle">아주대사랑꾼</td>
<td class="align-middle">123</td>
</tr>
<tr>
<th scope="row">4</th>
<td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td>
<td class="align-middle">아주대학교</td>
<td class="align-middle">아주대사랑꾼</td>
<td class="align-middle">123</td>
</tr>
<tr>
<th scope="row">5</th>
<td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td>
<td class="align-middle">아주대학교</td>
<td class="align-middle">아주대사랑꾼</td>
<td class="align-middle">123</td>
<td class="align-middle">{{univ.univ}}</td>
<td class="align-middle">{{univ.score}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
......
......@@ -43,7 +43,7 @@ class Join(APIView):
def post(self, request):
password = request.data.get('password')
# email = request.data.get('user_id')
email = "ksshhses@ajou.ac.kr"
email = "ksshhses@khu.ac.kr"
user_id = request.data.get('nickname')
name = request.data.get('name')
univ = request.data.get('univname')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment