Я получаю эту ошибку AttributeError at /listings/5689-resot-relly-market, 'Profile' object has no attribute 'favorite' please any help would be apprciate
Я работаю над функцией добавления в избранное в django и я продолжаю получать эту ошибку, когда я нажимаю кнопку сохранения, все выглядит нормально отсюда, поэтому я не могу сказать, откуда берется ошибка, и я застрял с этим проектом сейчас. Это вроде как срочно, пожалуйста, любая помощь была бы очень признательна и почтена.
Models.py
from basefunc.models import Accomodation
class Profile(models.Model):
user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE)
usertitle = models.CharField(max_length=1000, null=True, blank=True)
city = models.CharField(max_length=1000, null=True, blank=True)
state = models.CharField(max_length=1000, null=True, blank=True)
address = models.CharField(max_length=10000, null=True, blank=True)
about = models.TextField(max_length=10000, null=True, blank=True)
about = models.TextField(max_length=10000, null=True, blank=True)
facebook = models.URLField(max_length=10000, null=True, blank=True)
twitter = models.URLField(max_length=10000, null=True, blank=True)
instagram = models.URLField(max_length=10000, null=True, blank=True)
other = models.URLField(max_length=10000, null=True, blank=True)
phone = models.IntegerField(null=True, blank=True)
zipcode = models.IntegerField(null=True, blank=True)
image = models.ImageField(default='default.jpg', upload_to="profile_pic")
favorite = models.ManyToManyField(Accomodation, related_name='profile')
views.py
from userauth.models import Profile
def AccomodationDetails(request, accomodation_slug):
accomodations = get_object_or_404(Accomodation, slug=accomodation_slug)
accomodations_list = Accomodation.objects.filter(status="publish").order_by("-publication_date")
images = Images.objects.all()
categories = Category.objects.all()
features = Features.objects.all()
amenities = Amenities.objects.all()
advanced_features = Advanced_Features.objects.all()
user = request.user.id
profile = Profile.objects.get(user__id=user)
if request.method == "POST":
if profile.favourite.filter(slug=accomodation_slug).exists():
profile.favorite.remove(accomodations)
else:
profile.favorite.add(accomodations)
context = {
'accomodations': accomodations,
'accomodations_list': accomodations_list,
'categories': categories,
'features': features,
'advanced_features': advanced_features,
'amenities': amenities,
'images': images,
}
return render(request, 'accomodation_detail.html', context)
templateDetails.html
<form action="" method="POST" id="favouriteForm">
{% csrf_token %}
<li><a href="javascript:void()" onclick="document.getElementById('favouriteForm').submit();" ><i class="fa fa-bookmark"></i></a></li>
<li><a href="#"><i style="color: red;" class="fa fa-bookmark"></i></a></li>
<!-- <li><a href="#"><i class="fa fa-share"></i></a></li> -->
</form>