让我们这样说:我在Google中搜索了React js工作。它查看许多结果。在我的项目中,我已经对搜索作业进行了类似的应用,但是我们可以将每个结果固定在我们的个人资料中。我怎样才能做到这一点?我试图遵循许多教程,但是无法理解。我的项目中有作业应用程序和帐户应用程序。每个都有自己的模型,视图,URL等。如何固定/保存我喜欢的搜索结果,以便将来在个人资料中引用?谢谢。
工作/views.py:-
def list_jobs(request, category_slug=None)
:
users = User.objects.exclude(id=request.user.id)
jobs_list = Jobs.objects.all()
query = request.GET.get('q')
if query=='':
return HttpResponseRedirect('/')
if query:
jobs_list = Jobs.objects.filter(Q(Job__icontains=query)| Q(URL__icontains=query)).order_by("-Deadline")
jobs_counter = jobs_list.annotate(Count('id'))
jobs_count = len(jobs_counter)
context = {
'jobs_list':jobs_list,
'jobs_count':jobs_count,
'query':query,
'users':users,
}
return render(request, 'jobs/product/list.html',context)
2.Jobs/models.py
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Jobs(models.Model):
#Id = models.IntegerField()
Job = models.CharField(max_length=250)
Company = models.TextField(max_length = 250, default="Not Available")
Address = models.TextField(max_length = 250, default="Not available")
Deadline = models.DateTimeField(default=timezone.now)
URL = models.URLField(
max_length=128,
db_index=True,
unique=False,
blank=True
)
class Meta:
ordering = ('-Deadline',)
def __str__(self):
return self.Job
{% if request.user.is_authenticated %}
<a href="#" data-toggle="modal" data-target="#myModal" style="font-size:small"><b> PIN POST </b></a>
{% else %}
<a href="#" data-toggle="modal" data-target="#myModal" style="font-size:small"><b>PIN POST AFTER SIGN IN </b></a>