I have a table called video which has all video attributes, first issue the image of the uploader which is a foreign key with the user table, now when a video is uploaded i can retrieve the user name “creator” but the image of the uploader is not appearing “creator_img”, second issue is categories when i cick on it its working and i can choose from the dropdown list but when i tey to return the choosen values to the user it doesn’t work and returns None, third issue i am trying to show the favourite button if its clicked to show an icon if not a different icon but my condition is not working.
<div style="margin-top: 35px ;width: 46%;float:right;margin-right: 5% ;height: 23%; border-radius: 15px; background-color:#f9f4fe;">
<br>
<img style="margin-left: 15px ;height: 54px; width: 54px;border-radius:28px" src="{{x.creator_img.url}}"/> {{x.creator}}
{{x.creator_img.url}}
<br><br><br>
<p style="padding-left: 15px ;">
{{x.title}}
<br>
Lorem ipsum dolor sit amet, consecter adipiscing elit. Sed consectetur quis </p>
<br><br>
{{x.categories|safe}}
<br>
{{x.created}}
<label style="color: #999999 ;"></label>
<div style="float: right;">
{% if fav %}
<a href="{% url 'favourite' x.uuid %}">
<i class="fa-regular fa-heart fa-2xl" style="color: #2623cd;"></i>
</a>
{% else %}
<a href="{% url 'favourite' x.uuid %}">
<i class="fa-solid fa-heart fa-2xl" style="color: #2623cd;"></i>
</a>
{% endif %}
class Video(models.Model):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
creator = models.ForeignKey(NewUser, on_delete=models.CASCADE)
creator_img = models.ForeignKey(NewUser, on_delete=models.CASCADE, to_field='profile_img', related_name='user_img')
title= models.CharField(max_length=100, null=True, blank=True)
video = models.FileField(upload_to='videos/', validators=[file_size])
categories = models.ManyToManyField(category)
favourites = models.ManyToManyField(NewUser, related_name='favourite', default=None, blank=True)
created = models.DateTimeField(auto_now_add= True)
class category(models.Model):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
name = models.CharField(max_length=200)
def __str__(self):
return self.name
Views.py
def favourite(request, vid=None):
video = get_object_or_404(Video, uuid=vid)
fav = bool
if video.favourites.filter(uuid = request.user.uuid).exists():
fav = True
video.favourites.remove(request.user)
else:
video.favourites.add(request.user)
return HttpResponseRedirect(request.META['HTTP_REFERER'], {'fav':fav})