'tuple' object has no attribute 'quantity' django

Advertisements I’m trying to do a cart system where an user can add a product to the cart and if it was already in there I would add one of it but I keep getting the error "’tuple’ object has no attribute ‘quantity’ django". class OrderItem(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) item = models.ForeignKey(Product, on_delete=models.CASCADE) quantity… Read More 'tuple' object has no attribute 'quantity' django

Django outputs verbose_name in quotes and parentheses in admin panel

Advertisements My problem is the following. Code: … class Meta: verbose_name = ‘сайт’, verbose_name_plural = ‘1. Сайт’, … Result: Why Django outputs verbose_name in quotes and parentheses in admin panel? >Solution : Remove the commas after the string values, so that verbose_name and verbose_name_plural are defined as strings. The trailing comma after the string values… Read More Django outputs verbose_name in quotes and parentheses in admin panel

Error: UnboundLocalError at /receptionist/patient_form/ local variable 'username' referenced before assignment

Advertisements The following code gives the error : UnboundLocalError at /receptionist/patient_form/ local variable ‘username’ referenced before assignment. Exception Type: UnboundLocalError Exception Value: local variable ‘username’ referenced before assignment. ` @login_required def createPatient(request): form=PatientForm(request.POST, request.FILES) # try: if request.method == "POST": if form.is_valid(): first_name = form.cleaned_data[‘first_name’] last_name = form.cleaned_data[‘last_name’] username = form.cleaned_data[‘username’] email = form.cleaned_data[’email’] password… Read More Error: UnboundLocalError at /receptionist/patient_form/ local variable 'username' referenced before assignment

DJango pick Operating system username instead of user name present in settings file

Advertisements About the issue I created the project using command django-admin startproject test and updated the settings file to have mysql database details. Apart from that nothing added/updated/deleted in code. Database details in config file DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.mysql’, "Name": "django", "User": "root", "Password": "", "Host": "localhost", "Port": "3306" } } Then… Read More DJango pick Operating system username instead of user name present in settings file

Clean up unused database tables after removing a Django app?

Advertisements When I remove a Django app from my list of INSTALLED_APPS, it doesn’t get rid of the old database tables; running ./manage.py makemigrations doesn’t detect any changes. Apart from going into the database myself and dropping the old tables, is there a better way to clean up unused tables after uninstalling an app from… Read More Clean up unused database tables after removing a Django app?

error in django URLconf, I can't start the local server, an error pops up in the screenshot

Advertisements enter image description here I have a ready-made html template with css. It seems to have done everything correctly, but it does not work. project location C:\Projects\brew\brewtopia location of the application C:\Projects\brew\brewtopia\users location of the main urls.py C:\Projects\brew\brewtopia\brewtopia\urls.py location urls.py in the app C:\Projects\brew\brewtopia\users\urls.py location of views.py in the app C:\Projects\brew\brewtopia\users\views.py html layout C:\Projects\brew\brewtopia\users\templates\users\Brewtopia.… Read More error in django URLconf, I can't start the local server, an error pops up in the screenshot

Django html format radio select labels

Advertisements Consider the following structure: models.py: class modela(models.Model): fielda = models.BooleanField(default=True, choices=((True, ‘some <b>bold</b> text’), (False, ‘zzz’))) forms.py: class forma(forms.ModelForm): class Meta: model = modela widgets = {‘fielda’: forms.RadioSelect} fields = ‘__all__’ views.py: def a(request): form = forma() return render(request, ‘a.html’, {‘form’: form}) a.html: {{ form.fielda }} Django kindly escapes the tags for me as… Read More Django html format radio select labels

Django: get model's fields name

Advertisements I am trying to create a table in react that uses as table information from a django backend. I would like to fetch the table’s columns from the API, so I tried updating the model: class Activity(models.Model): aid = models.AutoField(primary_key=True) uid = models.ForeignKey(USER_MODEL, default=1, verbose_name="Category", on_delete=models.SET_DEFAULT, db_column="uid") rid = models.IntegerField() action = models.TextField(max_length=254, blank=True,… Read More Django: get model's fields name

Reverse for 'save-review' not found. 'save-review' is not a valid view function or pattern name

Advertisements I have error in Django: "django.urls.exceptions.NoReverseMatch: Reverse for ‘save-review’ not found. ‘save-review’ is not a valid view function or pattern name." I study django through YouTube, I do everything as in the video, but I get an error. When there is no authorization and "Add review" button is hidden, the page works fine. But… Read More Reverse for 'save-review' not found. 'save-review' is not a valid view function or pattern name

Tests failling after django and python upgrade

Advertisements I’ve upgraded Django from 4.0.5 to 4.1.6 and python from 3.9 to 3.11 I’ve also upgraded dependencies: pip==23.0 pytest==7.2.1 pytest-django==4.5.2 coverage==7.1.0 pytest-cov==4.0.0 pylint==2.16.2 mock==5.0.1 These are my logs: django-admin test Traceback (most recent call last): File "/usr/local/bin/django-admin", line 8, in <module> sys.exit(execute_from_command_line()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 440,… Read More Tests failling after django and python upgrade