MU
Maciej UrmańskiАқп. 4, 2019, 12:46 Т.Қ.
Django getstream integration problem
Django, django, python, python3
Hi, maybe this community help me.
I try integrate Getstream.io on my project. Following this code: https://github.com/GetStream/django_twitter I create most things like activity feed and notification but i don't know how to create a form to follow other people on profile page. (userdetailpage)
Code say how to create follow button on user list page but no on detail page.
Code to follow other people on list user page:
# Views class DiscoverView(TemplateView): template_name = 'stream_twitter/follow_form.html' def get_context_data(self): context = super(DiscoverView, self).get_context_data() users = User.objects.order_by('date_joined')[:50] following = [] for i in users: if len(i.followers.filter(user=self.request.user.id)) == 0: following.append((i, False)) else: following.append((i, True)) context['users'] = users, context['form'] = FollowForm() context['login_user'] = self.request.user context['following'] = following return context class FollowView(CreateView): form_class = FollowForm model = Follow success_url = reverse_lazy('timeline_feed') def form_valid(self, form): form.instance.user = self.request.user return super(FollowView, self).form_valid(form) class UnfollowView(DeleteView): model = Follow success_url = reverse_lazy('timeline_feed') def get_object(self): target_id = self.kwargs['target_id'] return self.get_queryset().get(target__id=target_id) #Forms class FollowForm(forms.ModelForm): class Meta: exclude = set() model = Follow #Urls path('follow/', login_required(views.FollowView.as_view()), name='follow'), re_path(r'^unfollow/(?P<target_id>\d+)/', login_required(views.UnfollowView.as_view()), name='unfollow'), #Template {% for one, followed in following %} <div class="col-md-3 col-sm-6 col-xs-12"> <div class="user"> {% include "stream_twitter/_user.html" with user=one %} <div class="follow-button"> <form action="{% if followed %}{% url 'unfollow' one.id %}{% else %}{% url 'follow' %}{% endif %}" method="post"> {% csrf_token %} <input type="hidden" id="id_target" name="target" value="{{one.id}}"> <input type="hidden" id="id_user" name="user" value="{{user.id}}"> <button type="submit" class="btn btn-primary" value="Create" /> {% if followed %} Unfollow {% else %} Follow {% endif %} </button> </form> </div> </div> </div> {% if forloop.counter|divisibleby:'4' %} <div class="clearfix visible-sm-block visible-md-block visible-lg-block"></div> {% elif forloop.counter|divisibleby:'2' %} <div class="clearfix visible-sm-block"></div> {% endif %} {% endfor %}
Рекомендуем хостинг TIMEWEB
Стабильный хостинг, на котором располагается социальная сеть EVILEG. Для проектов на Django рекомендуем VDS хостинг.Ол саған ұнайды ма? Әлеуметтік желілерде бөлісіңіз!
Пікірлер
AD
- Akiv Doros
- Қар. 11, 2024, 2:58 Т.Қ.
C++ - Тест 004. Указатели, Массивы и Циклы
- Нәтиже:50ұпай,
- Бағалау ұпайлары-4
m
- molni99
- Қаз. 26, 2024, 1:37 Т.Ж.
C++ - Тест 004. Указатели, Массивы и Циклы
- Нәтиже:80ұпай,
- Бағалау ұпайлары4
m
- molni99
- Қаз. 26, 2024, 1:29 Т.Ж.
C++ - Тест 004. Указатели, Массивы и Циклы
- Нәтиже:20ұпай,
- Бағалау ұпайлары-10
Соңғы пікірлер
ИМ
Django - Оқулық 017. Теңшелген Django кіру беті Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Игорь МаксимовҚар. 22, 2024, 11:51 Т.Ж.
Evgenii LegotckoiҚаз. 31, 2024, 2:37 Т.Қ.
Qt Creator көмегімен fb3 файл оқу құралы Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Django - Сабақ 064. Python Markdown кеңейтімін қалай жазуға болады Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
Игорь МаксимовҚаз. 5, 2024, 7:51 Т.Ж.
QML - Сабақ 016. SQLite деректер қоры және онымен QML Qt-та жұмыс істеу Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Енді форумда талқылаңыз
Mosquito Spray System Effective Mosquito Systems for Backyard | Eco-Friendly Misting Control Device & Repellent Spray - Moogo ; Upgrade your backyard with our mosquito-repellent device! Our misters conce…
Evgenii LegotckoiМаусым 24, 2024, 3:11 Т.Қ.
t
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
tonypeachey1Қар. 15, 2024, 6:04 Т.Ж.
NSProjectМаусым 4, 2022, 3:49 Т.Ж.
IscanderCheҚаз. 31, 2024, 3:43 Т.Қ.
Hello,
I think, will be better to use AJAX requests, without common form.
For example, I have an article with my own system with Likes Dislikes.
In fact I have two sides fot implementing of these logic.
Therefore, I think you can create url path with ID of user, which you want use for following logic.
And implement FollowView
And JavaScript logic for Ajax like in the article.
Sorry, I haven`t experiense with django_twitter library, but I think it will be first, what I will try.
Thanks, i know Your Like Dislike system is cool. :D