0

I'm doing a web app with Django, but I keep getting this error all the time.

This is the code from my models.pty, where I create the class Room.

from django.db import models
import string
import random


def generate_unique_code():
    length = 6

    while True:
        code = ''.join(random.choices(string.ascii_uppercase, k=length))
        if Room.objects.filter(code=code).count() == 0:
            break

    return code


class Room(models.Model):
    code = models.CharField(max_length=8, default="", unique=True)
    host = models.CharField(max_length=50, unique=True)
    guest_can_pause = models.BooleanField(null=False, default=False)
    votes_to_skip = models.IntegerField(null=False, default=1)
    created_at = models.DateTimeField(auto_now_add=True)

And here is where I import the room to views.py, I'm also getting the same error here.

from django.shortcuts import render
from rest_framework import generics
from .serializer import RoomSerializer
from .models import Room


class RoomView(generics.CreateAPIView):
    queryset = Room.objects.all()
    serializer_class = RoomSerializer

What's wrong with my code?

  • Does this answer your question? [Class has no objects member](https://stackoverflow.com/questions/45135263/class-has-no-objects-member) – Ivan Starostin Mar 12 '21 at 07:01

1 Answers1

0

You need to install pylint-django

pip install pylint-django

And assuming you use Visual Studio Code you need to add this setting by pressing ctrl+shift+p then going to Preferences: Configure Language Specific Settings and then selecting Python It will open a json file. You will need to add this code to that file and save:

{
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django"
    ],

    "[python]": {

    }
}

Restart VS Code and it should be ok

Based on the answers to this question

periwinkle
  • 386
  • 3
  • 9