django-models

Django ForeignKey("x") field must be a "x" instance on update

Django ForeignKey("x") field must be a "x" instance on update Question: Django version 4.2.9 I try to fix this : Cannot assign "(‘customer’,)": "Project.customer" must be a "Customer" instance. I have 2 classes, Project and Customer. class Customer(models.Model): customer_name = models.CharField(max_length=50) string = models.CharField(max_length=50) def __str__(self): return f"{self.customer_name}" class Project(models.Model): project_name = models.TextField() project_code = …

Total answers: 1

Add Radio Button in gender feied in crud django

Add Radio Button in gender feied in crud django Question: i have a CRUD PROJECT in which i need gender field in radio buttons or in check box i tried to apply those but did not getr the desired result, Radio buttons are not adding if they are adding they are not posting data in …

Total answers: 2

Django Template how to get the value of a model through the OneToOneField

Django Template how to get the value of a model through the OneToOneField Question: In my Django App i have Two Models and the User model from django.contrib.auth.models from django.contrib.auth.models import User class Room(models.Model): host = models.ForeignKey(User, on_delete=models.CASCADE, null=True) topic = models.ForeignKey(Topic, on_delete=models.SET_NULL, null=True) name = models.CharField(max_length=200) description = models.TextField(null = True, blank = True) …

Total answers: 2

Link from Django Model's "absolute url" to its admin page

Link from Django Model's "absolute url" to its admin page Question: According to the docs, you can specify a get_absolute_url in your Django Model for a "View on site" button to show up on Django Admin. However, how would you do the opposite? A link on the above defined "absolute url" that takes you to …

Total answers: 1

Django: aggregate django fields to avoid N + 1 problem

Django: aggregate django fields to avoid N + 1 problem Question: I have 3 tables/classes that are relevant to each other: CourseStudent – represents Student signed up to the course Presence – represents the attendance list of the CourseStudent CourseStudentPayment – represents the payments list for CourseStudent In the code it looks like this: class …

Total answers: 1

foregin key using name value fetch in django rest frame work

foregin key using name value fetch in django rest frame work Question: i have add model.py ,view.py and serilializer.py file ,i will share country and state model . I wiil apply foregin key country and state fields. I will check in html fields in django rest framework in only object id fetch not value so …

Total answers: 2

Django QuerySet Not returning all data

Django QuerySet Not returning all data Question: I am trying to return all the data in queryset which is saved in my model. But when I try to print it only returns the title nothing else. Bellow are the screenshots attached for refrence. Please assist Code: enter image description here and here is the data …

Total answers: 1

admin panel in Django creating for to change Product media and text from webpage

admin panel in Django creating for to change Product media and text from webpage Question: I have created a website in Django that contains product details and captions. Now, I want to create a dynamic admin panel that performs the following tasks without using code (because the client has no idea about coding): Add or …

Total answers: 2

Django returns a tuple instead of returning data

Django returns a tuple instead of returning data Question: I have a simple model that is supposed to store some basic nutritional information about food, but whenever I create or edit the model it returns a tuple instead of the data. The app is simple and these are the only models I have in them. …

Total answers: 1