django

__init__.py issue in django test

__init__.py issue in django test Question: I have an issue with running a test in my Django project, using the command python manage.py test. It shows: user:~/workspace/connector$ docker-compose run –rm app sh -c "python manage.py test" Creating connector_app_run … done Found 0 test(s). System check identified no issues (0 silenced). ———————————————————————- Ran 0 tests in …

Total answers: 1

how to add a profile object by using objects.create method

how to add a profile object by using objects.create method Question: simply my error is this Exception has occurred: TypeError User() got an unexpected keyword argument ‘User’ here is the data I receive from the post request in view.py if request.method == "POST": student_surname = request.POST.get(‘student_surname’) student_initials = request.POST.get(‘student_initials’) student_birthday = request.POST.get(‘student_birthday’) student_username = request.POST.get(‘student_username’) …

Total answers: 1

Moving tables data from sqlite3 to postgressql

Moving tables data from sqlite3 to postgressql Question: What is the simplest way to move data from sqlite3 tables to posgressql in Django project Asked By: Islam Fahmy || Source Answers: To perform a data backup, we use the following command: python manage.py dumpdata > data.json #use this command adding before postgres in django This …

Total answers: 1

How can get products for active owners (users) only with Django Rest Framework?

How can get products for active owners (users) only with Django Rest Framework? Question: I’m creating an e-commerce API with DRF. I would like to retrieve and display only active products from active owners (users) using a ModelViewSet How can I do this? Here is my code : views.py class ProductViewSet(viewsets.ModelViewSet): serializer_class = ProductSerializer parser_classes …

Total answers: 1

Multiple choice in model

Multiple choice in model Question: ANIMALS = ((‘dog’,’dog’), (‘cat’,’cat’)) class Owner(models.Model): animal = models.Charfield(choices=ANIMALS, max_length=10) My problem is how I can do if I have both ? Asked By: Coco || Source Answers: your need to have model like this: class Choices(models.Model): animal = models.CharField(max_length=20) class Owner(models.Model): animal = models.ManyToManyField(Choices) Answered By: Divya Prakash Presumably …

Total answers: 2

Django ORM for fetching latest record for specific ID

Django ORM for fetching latest record for specific ID Question: How do I write a django ORM to fetch the most recent records from the table for a specific id. Example: I have table(tr_data) data like: id trs(foreign key) status last_updated 1 301 3 2022-11-28 06:14:28 2 301 4 2022-11-28 06:15:28 3 302 3 2022-11-28 …

Total answers: 1

Django search bar isn't giving correct results

Django search bar isn't giving correct results Question: views.py from django.shortcuts import render from ecommerceapp.models import Product from django.db.models import Q def searchResult(request): products=None query=None if ‘q’ in request.GET: query = request.GET.get(‘q’) products=Product.objects.all().filter(Q(name__contains=query) | Q(desc__contains=query)) return render(request,’search.html’,{‘query’:query,’products’:products}) In views.py I have imported a model named ‘Product’ of another application. search.html {% extends ‘base.html’ %} {% …

Total answers: 1

How to pass a javascript variable in html to views.py?

How to pass a javascript variable in html to views.py? Question: I am currently trying to make an website using django. And i faced a problem like i wrote in title. What i want to make is like this, first of all, shop page shows all products. But, when a user select a brand name …

Total answers: 1

How can I set and append in column with conditional case in Django?

How can I set and append in column with conditional case in Django? Question: I want to run this sql query in Django UPDATE `TABLE` SET `COLUMN` = (CASE WHEN `COLUMN` = "" THEN ‘100’ ELSE CONCAT(`COLUMN`,’100′) END) WHERE `SOMEID` IN [id1,id2,id3]; I tried this from django.db.models import Case, When, F Table.objects.filter(someid__in=[id1,id2,id3]). update(column= Case( When(column="",then="100"), …

Total answers: 1