Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'tuple' object has no attribute 'is_preview'

i am woking on a project where users can create a videos and check if the particular can be previewed before they purchase or not, everything was working fine up till now i got this 'tuple' object has no attribute 'is_preview' i can’t really tell where this error is coming from.

This is where the traceback is pointing too
traceback

Traceback (most recent call last):
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Users\Destiny\Desktop\DexxaEd\dnextedprj\course\views.py", line 122, in course_details
    if(video.is_preview is False):
AttributeError: 'tuple' object has no attribute 'is_preview'
[01/May/2022 20:08:43] "GET /course/et-ea-velit-ad-veritatis-explicabo HTTP/1.1" 500 73905

views.py line 122

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


    if serial_number is None:
        serial_number = 1

    
    # if Video.objects.all().exists
    video = Video.objects.get_or_create(serial_number=serial_number, course=course)
    video_count = Video.objects.get(serial_number=serial_number, course=course)

    if(video.is_preview is False):

        if request.user.is_authenticated is False:
            return redirect("course:sign-in")
        else:
            user = request.user
            try:
                user_course = UserCourse.objects.get(user=user, course=course)
            except:
                return redirect("course:check-out", slug=course.slug)

form.py

CourseVideosFormset = inlineformset_factory(Course, Video, fields=('title','serial_number', 'video_id', 'is_preview'))

>Solution :

.get_or_create(…) [Django-doc] returns a 2-tuple with the object created/retrieved as first item, and a boolean that is True in case the object was created as second. You thus unpack these with:

video, __ = Video.objects.get_or_create(serial_number=serial_number, 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading