You are not creating an instance, but instead referencing the class Goblin itself as indicated by the error:
AttributeError: type object 'Goblin' has no attribute 'color'
Change your line to Azog = Goblin()
You are not creating an instance, but instead referencing the class Goblin itself as indicated by the error:
AttributeError: type object 'Goblin' has no attribute 'color'
Change your line to Azog = Goblin()
When you assign Azog = Goblin, you aren't instantiating a Goblin. Try Azog = Goblin() instead.
AttributeError: type object 'Model' has no attribute 'load'
Type object has no attribute objects on view
python - Why am I getting AttributeError: Object has no attribute? - Stack Overflow
django - type object 'X' has no attribute 'objects' - Stack Overflow
Videos
Hi everyone, just trying to get some clarity on this issue but chances are I'm just making a really dumb mistake. I tried looking around a bit already but to no success. Here's the code:
class COG:
def __init__(self, name, AC):
self.name = name
self.AC = AC
Test = COG("Hal", 14)
print(COG.AC)
Basically I want a class that has the attributes "name" and "AC"... But apparently I'm doing something wrong because this shows up in the Shell:
AttributeError: type object 'COG' has no attribute 'AC'
Could anyone shine some light on what's going on here?
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.
The line notifications = Notification.objects.all() is referencing the Notification View class defined in api.py and not models.py.
The easiest way to fix this error is to rename the Notification class in either api.py or models.py so that you can refer to your model properly. Another option would be to use named imports:
from .models import Notification as NotificationModel
class Notification(generics.ListAPIView):
...
def get_queryset(self):
notifications = NotificationModel.objects.all()
...
Add objects = models.Manager() to your model, or any other custom manager that you are using and/or define.
class Notification(models.Model):
NOTIFICATION_ID = models.AutoField(primary_key=True)
user = models.ForeignKey(User, related_name='user_notification')
type = models.ForeignKey(NotificationType)
join_code = models.CharField(max_length=10, blank=True)
requested_userid = models.CharField(max_length=25, blank=True)
datetime_of_notification = models.DateTimeField()
is_active = models.BooleanField(default=True)
objects = models.Manager()
i run into this error when trying my hands on django-shopping-cart
error
AttributeError: type object 'Grocery' has no attribute 'objects'
the error was pointing this below
return Grocery.objects.all()
Models.py
from django.db import models
from django.urls import reverse
class Grocery(models.Model):
item_name = models.CharField(max_length=50)
price = models.FloatField()
picture = models.ImageField(upload_to='pictures', default='')
def __str__(self):
return self.item_name
def get_absolute_url(self):
return reverse('marketing_sys:home')views.py
from django.shortcuts import render, redirect
from django.views.generic import DetailView
from cart.cart import Cart
from .models import Grocery
class CartAdd(DetailView):
model = Grocery
context_object_name = 'grocery'
template_name = 'mismas/cartdetail.html'
def get_queryset(self):
return Grocery.objects.all()urls.py
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from mismas.views import Grocery
app_name = 'marketing_sys'
urlpatterns =[
path('cart_add/<int:pk>/', CartAdd.as_view(), name='cart_add'),
]i will be glad to receive help. thanks