In my app I want to create favorite system:
- user input url
- some data is calculated
- then user can add this link to favorite
After clicking add, user is redirected to other endpoint which returns all his favorites links. At this point I want to add possibility which allow user to click on one of his favourites, return to other view and calculate some data.
My views.py
def home(request):
"""this function returns form which allows user to input link"""
if request.method =='POST'
url = request.POST['url']
request.session['url'] = url
return redirect('bokeh')
return render(request,'base.html')
After this, bokeh.html is returned and has some data like charts
def bokeh(request):
url = request.session.get('url')
cl = CalculationLogic()
return cl.get_data_from_url(request,url)
In this view, there is a button which allows add to favorite. After clicking, method is called:
def favorites(request):
url = request.session.get('url')
repo = Repository(url=url,user=request.user)
repo.save()
repo.repositorys.add(request.user) #adding value to ManyToMany field
user = User.objects.get(username=request.user.username)
repos = user.users.all() #return all url which current user has in favorites
return render(request,'favorites.html',{'repos':repos})
And in my favorites.html
{% extends 'bokeh.html' %}
{% block content %}
<h1>Favorites repositorys for {{ user }}</h1>
{% for r in repos %}
<br><a href="{% url 'bokeh' %}">{{ r }}</a>
{% endfor %}
{% endblock %}
So, at this point I display all of user's favorite repos. After clicking on one of them I want to go back to bokeh view and return different data based on clicked url. Is there a easy way to solve this problem?