django-models

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

How to add array of integer field in Django Rest Framework?

How to add array of integer field in Django Rest Framework? Question: I want to add an array of integer fields in my model class Schedule(models.Model): name = models.CharField(max_length=100) start_time = models.DateTimeField(auto_now_add=True) end_time = models.DateTimeField(null=True, blank=True) day_of_the_week = ?? ( array of integer ) I tried with class Schedule(models.Model): name = models.CharField(max_length=100) start_time = models.DateTimeField(auto_now_add=True) …

Total answers: 2

Django Rest Framework, how to use serializers.ListField with model and view?

Django Rest Framework, how to use serializers.ListField with model and view? Question: I want to store an array of integers in the day_of_the_week field. for which I am using the following code models.py class Schedule(models.Model): name = models.CharField(max_length=100) day_of_the_week = models.CharField(max_length=100) serializers.py class ScheduleSerializer(serializers.ModelSerializer): day_of_the_week = serializers.ListField() class Meta(): model = Schedule fields = "__all__" …

Total answers: 1

I have written a django query but need specific user information of particular date

I have written a django query but need specific user information of particular date Question: Models: class Employee(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, default=1,related_name=’Employee’) eid = models.IntegerField(primary_key=True) salary = models.IntegerField(null=True, blank=True) gender = models.CharField(max_length=6, choices=GENDER_CHOICES, default=1) contactno = models.CharField(max_length=10, blank=False) email = models.CharField(max_length=50 ,null=True, blank=True) country = models.CharField(max_length=30) address = models.CharField(max_length=60) def __str__(self): return self.user.first_name + …

Total answers: 2

Display option value and text to select

Display option value and text to select Question: I have a select field populated from the database table ‘Grade’. It displays Grade objects instead of ‘Grade 1’, ‘Grade 2’, ‘Grade 3’ etc. How can I populate the select to display the texts. My codes: models.py class Grade(models.Model): grade_id = models.AutoField(primary_key=True) grade_name = models.CharField(max_length=10, default="") class …

Total answers: 2

Copying only non-relation attributes django/python

Copying only non-relation attributes django/python Question: I am copying a model object to another, but I want that it doesn’t copy the relations For example, assume you have a model like this: class Dish(models.Model): name = models.CharField(max_length=100) description = models.CharField(max_length=500) category = models.ForeignKey(Category, on_delete=models.CASCADE, default=1) def __str__(self): return self.name Then I do: my_dish = Dish.objects.get(pk=dish.id) …

Total answers: 3

How to filter the dates from datetime field in django

How to filter the dates from datetime field in django Question: views.py import datetime from django.shortcuts import render import pymysql from django.http import HttpResponseRedirect from facligoapp.models import Scrapper from django.utils import timezone import pytz roles = "" get_records_by_date = "" def index(request): if request.method == "POST": from_date = request.POST.get("from_date") f_date = datetime.datetime.strptime(from_date,’%Y-%m-%d’) print(f_date) to_date = …

Total answers: 1

RegexValidator in Django Models not validating email correctly

RegexValidator in Django Models not validating email correctly Question: I’m making a django form with an email field and using a RegexValidator and want a specific format of of the email but it seems to be not validating the field correctly email = models.EmailField( unique=True, validators=[ RegexValidator( regex=r"^[2][2][a-zA-Z]{3}d{3}@[nith.ac.in]*", message= "Only freshers with college email addresses …

Total answers: 1

How to update django database with a list of dictionary items?

How to update django database with a list of dictionary items? Question: I have a list of key value pairs here. stat = [{‘id’: 1, ‘status’: ‘Not Fixed’}, {‘id’: 2, ‘status’: ‘Not Fixed’}, {‘id’: 4, ‘status’: ‘Not Fixed’}, {‘id’: 5, ‘status’: ‘Not Fixed’}, {‘id’: 6, ‘status’: ‘Not Fixed’}, {‘id’: 7, ‘status’: ‘Not Fixed’}] The id …

Total answers: 2

How to access value in QuerySet Django

How to access value in QuerySet Django Question: I am creating a simple Pizza Delivery website and trying to add an option to choose a topping. When I want to print Ingredients it returns QuerySet and Values in it separated by a comma. Is there any option how can I get values based on their …

Total answers: 1