#django #object #attributes #attributeerror
Вопрос:
Я работаю над функцией «Добавить в избранное» в 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
lt;form action="" method="POST" id="favouriteForm"gt; {% csrf_token %} lt;ligt;lt;a href="javascript:void()" onclick="document.getElementById('favouriteForm').submit();" gt;lt;i class="fa fa-bookmark"gt;lt;/igt;lt;/agt;lt;/ligt; lt;ligt;lt;a href="#"gt;lt;i style="color: red;" class="fa fa-bookmark"gt;lt;/igt;lt;/agt;lt;/ligt; lt;!-- lt;ligt;lt;a href="#"gt;lt;i class="fa fa-share"gt;lt;/igt;lt;/agt;lt;/ligt; --gt; lt;/formgt;