in line 4 in class Video(models.model): AttributeError: module 'django.db.models' has no attribute 'model'

I think you have typo mistake. models do not have model instead it have Model. convert

Convert

Video(models.model)

to

Video(models.Model)
Answer from bkawan on Stack Overflow
🌐
GitHub
github.com › typeddjango › django-stubs › issues › 83
"Type[Model]" has no attribute "objects" (again?) · Issue #83 · typeddjango/django-stubs
June 1, 2019 - I tried to use your package yesterday and I like it, although I've encountered one issue, when the django model I was accessing had no attribute 'objects', according to mypy. So it's like #16: ... anchor/users/forms.py:26: error: "Type[Model]" has no attribute "objects" anchor/users/views.py:38: ...
Author   kam1sh
🌐
Django
code.djangoproject.com › ticket › 13872
#13872 ("AttributeError: 'module' object has no attribute 'day_abbr'" when using Admin to add instance of model with DateField, TimeField, or DateTimeField) – Django
Tested on a clean project with versions you gave. I'm guessing you named one of your apps or some other module "calendar" which breaks the built-in python module. Rename your app/module and it should work fine. ​A similar problem on django-users from the past.
Discussions

AttributeError: module 'django.db.models' has no attribute 'model' - Stack Overflow
I think you have typo mistake. models do not have model instead it have Model. convert ... Sign up to request clarification or add additional context in comments. ... Maybe you should point out that the problem is due to the Django version 2020-07-02T19:37:21.327Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 1 AttributeError: 'module' object has ... More on stackoverflow.com
🌐 stackoverflow.com
Model Product in django has no attribute 'objects' - Django - Code with Mosh Forum
In lesson 41 Mosh called the objects attribute from the Product class, but in my case no such attribute exists (as shown in the picture above). Could anyone help me? Thanks in advance, Jonas More on forum.codewithmosh.com
🌐 forum.codewithmosh.com
0
May 15, 2023
Django - AttributeError: 'Model' object has no attribute '***_set'

Based on your models.py, each project has a foreign key to one hole, while each hole can be used to refer to multiple projects. If you want to add a hole to a project, just do project.hole = hole.

The 'attribute_set' keyword always works in the opposite direction from how you define your foreign key -- it's for the reverse. So your Hole model has a project_set relationship, because that is the reverse relationship for the defined foreign key.

https://docs.djangoproject.com/en/2.0/topics/db/queries/#following-relationships-backward

More on reddit.com
🌐 r/learnpython
7
6
August 27, 2018
AttributeError: module 'django.db.models' has no attribute 'JSONField'
Bug Report At what date and time did you most recently experience the problem? October, 6th 2020 22:36:31 UTC+1 Where did you experience the problem? E.g. Azure Web Apps, Azure Functions, Azure Con... More on github.com
🌐 github.com
7
October 6, 2020
🌐
Django Forum
forum.djangoproject.com › using django › using the orm
Model does not have a attribute called `objects` - Using the ORM - Django Forum
May 16, 2023 - I am trying to use the “objects” attribute that should be available for every model that you create. Unfortunately, if I try to call this attribute, I get an error. views.py file: from django.shortcuts import render from django.http import HttpResponse from store.models import Product def say_hello(request): Product.objects return render(request, 'hello.html', {'name': 'Jonas'}) models.py : from django.db import models class Promotion(models.Model): description = models.Char...
🌐
Django
code.djangoproject.com › ticket › 22033
#22033 ('Model' object has no attribute 'replace') – Django
It's hard to say without seeing your models.py but you most likely have an issue with one of your models' __unicode__ method (or __str__ if you're using Python 3).
🌐
Code with Mosh
forum.codewithmosh.com › django
Model Product in django has no attribute 'objects' - Django - Code with Mosh Forum
May 15, 2023 - In lesson 41 Mosh called the objects attribute from the Product class, but in my case no such attribute exists (as shown in the picture above). Could anyone help me? Thanks in advance, Jonas
Find elsewhere
🌐
GitHub
github.com › microsoft › Oryx › issues › 809
AttributeError: module 'django.db.models' has no attribute 'JSONField' · Issue #809 · microsoft/Oryx
October 6, 2020 - AttributeError: module 'django.db.models' has no attribute 'JSONField' Requirements.txt file specifies Django >= 3.1: Django >= 3.1 · App Service Built console: ##[group]Run azure/appservice-build@v1 with: platform: python platform-version: 3.8 env: pythonLocation: /opt/hostedtoolcache/Python/3.8.5/x64 ...
Author   JV-conseil
🌐
Django
code.djangoproject.com › ticket › 3860
#3860 (AttributeError: 'module' object has no attribute 'myapp') – Django
Sorry to comment on a 4-year-old thread, but this is the first google result for this issue, no apparent resolution was reached here, and the django-users discussion (if there was one) is not linked :) The problem is that myapp/__init__.py imports auth.models when it's executed; at this point, the subpackage myapp of mysite has not yet been imported, and is not yet an attribute on the parent package (mysite.myapp doesn't exist yet).
🌐
PyTutorial
pytutorial.com › django-attributeerror-db-models
PyTutorial | How to Solve AttributeError: module 'django.db.models' has no attribute 'model' in Django
February 15, 2023 - Today, I'll show you how to solve AttributeError: module 'django.db.models' has no attribute 'model' and AttributeError: module 'django.db.models' has no attribute 'models' in django.
🌐
Reddit
reddit.com › r/django › type object 'grocery' has no attribute 'objects'
r/django on Reddit: type object 'Grocery' has no attribute 'objects'
August 1, 2021 -

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

Top answer
1 of 4
84

The reason for this error is that .get() returns an individual object and .update() will only operate on a QuerySet, such as what would be returned with .filter() instead of .get().

If you are using .get(), then .update() will not work. You will need to save the information to the object manually:

archivo = archivo.objects.get(archivo_id=procesar)
archivo.archivo_registros = sh.nrows
archivo.save()

You can also use update_fields if you only wish to save this particular piece of data:

archivo = archivo.objects.get(archivo_id=procesar)
archivo.archivo_registros = sh.nrows
archivo.save(update_fields=['archivo_registros'])

This prevents triggering any signals that you may not want to invoke.

Your other option is to simply use .filter().

archivo = archivo.objects.filter(archivo_id=procesar).update(archivo_registros=sh.nrows)

Note that this will update multiple objects if they exist. If you want to be sure that doesn't happen, you should include the primary key in the filter, or use one of the earlier approaches to make sure you are only modifying a single object.

2 of 4
11

Encountered this behavior and used a "filter" then update works as expected. For example:

 Students.objects.select_for_update().filter(id=3).update(score = 10)

Just FYI: Unless you are handling transactions, modifying each field separately using save() might create data inconsistency in a multi-threaded environment. By the time threadA calls save() on a model, another threadB could have changed the model fields and saved. In which case threadA has to read the updated model and change.

This was on Django 1.6.2

🌐
Stack Overflow
stackoverflow.com › questions › 69496389 › django-attributeerror-model-object-has-no-attribute-field
python - Django AttributeError: 'Model' object has no attribute 'field' - Stack Overflow
I couldn't imagine that Django took one of the most common variable names by itself. ... I figured it out. The "name" parameter was the problem. If you specify it, then your variable must match it. first_name = models.CharField(name='First name', max_length=20) # <- 'name=' is the problem · What I actually needed is the verbose_name parameter. It comes first if you don't specify anything. So here is the solution: first_name = models.CharField('First name', max_length=20) # or verbose_name='First name'
🌐
GitHub
github.com › typeddjango › django-stubs › issues › 742
Error on automatic primary key fields - model has no attribute "id" · Issue #742 · typeddjango/django-stubs
October 29, 2021 - Based on the Typechecking models and queryset section of the tutorial, I do not expect error: "BlogPost" has no attribute "id", and I expect the revealed type of id to be builtins.int*. ... server/apps/main/models.py:21: note: Revealed type is 'builtins.int*' server/apps/main/models.py:22: note: Revealed type is 'django.contrib.auth.models.User*' server/apps/main/models.py:23: note: Revealed type is 'builtins.str*' server/apps/main/models.py:24: note: Revealed type is 'builtins.bool*' server/apps/main/models.py:25: note: Revealed type is 'datetime.datetime*'
Author   mvernacc
🌐
Django
code.djangoproject.com › ticket › 28793
#28793 (AttributeError: 'ModelName' object has no attribute 'save_m2m') – Django
I'm getting below error. Django version 1.11.6 · AttributeError: 'ModelName' object has no attribute 'save_m2m'
🌐
Reddit
reddit.com › r/django › object has no attribute 'object'
r/django on Reddit: Object has no attribute 'object'
May 19, 2022 -

I've been trying for a few days now to do something that I initially thought would be very simple;

From a FormView, redirect on form submission to the DetailsView for the submitted data.

After a lot of refactoring, this is where I am right now:

views.py:

class addrecipe(FormView):
  form_class = AddRecipeForm
  model = Recipe
  template_name = 'recipebook/addrecipe.html'
  fields = '__all__'
  extra_context = {
    'recipe_list': Recipe.objects.all()
    }

  def get_success_url(self):
    test_recipe_id = self.object.id
    return reverse('recipeBook:recipe_details', pk=test_recipe_id)

forms.py:

class AddRecipeForm(forms.ModelForm):
  name = forms.CharField(max_length="50", label="Recipe Name")
  description = forms.Textarea(attrs={'class': 'desc-text-area'})
  servings = forms.IntegerField()
  tools = forms.ModelMultipleChoiceField(queryset=Tool.objects.all(), widget=forms.CheckboxSelectMultiple, required = True, help_text="Select all relevant tools")
  class Meta:
      model = Recipe
      fields = ("__all__")

urls.py:

path('<int:pk>/recipedetails', views.recipedetails.as_view(), name='recipe_details'),

When submitting the data, I get the following error:

AttributeError at /recipebook/addrecipe 
'addrecipe' object has no attribute 'object'

Does anyone have any idea what I need to do to get this functional? I feel like I'm losing my mind.

🌐
Django Forum
forum.djangoproject.com › using django › forms & apis
AttributeError at /Column-Create: object has no attribute 'instance' - Forms & APIs - Django Forum
March 27, 2023 - I’m trying to submit a Column model, but it throws me an error when I clicked a submit button: the error: 'ColumnForm' object has no attribute 'instance' Forms.py: class ColumnForm(forms.Form): class Meta: model = Column fields = ['name', 'selec_type'] Models.py: class Column(models.Model): user = OneToOneFields (settings.AUTH_USER_MODEL, on_delete=models.CASCADE) name = models.CharField(max_length=100) selec_type = models.ForeignKey(Type, on_delete= mo...