skip to Main Content

Get a Foreign Key value with django-rest-framework serializers – Postgresql

I'm using the django rest framework to create an API. models.py class DepartmentModel(models.Model): DeptID = models.AutoField(primary_key=True) DeptName = models.CharField(max_length=100) def __str__(self): return self.DeptName class Meta: verbose_name = 'Department Table' class EmployeeModel(models.Model): Level_Types = ( ('Genin', 'Genin'), ('Chunin', 'Chunin'), ('Jonin', 'Jonin'),…

VIEW QUESTION

Django combine queries with and (&) in m2m field – Postgresql

I have such models: class Post(models.Model): title = models.CharField(max_length=200) content = models.TextField() tags = models.ManyToManyField(to="tag", related_name="tags", blank=True) def __str__(self): return self.title class Tag(models.Model): value = models.CharField(max_length=50) parent = models.ManyToManyField("Tag", related_name="children", blank=True) image = models.ImageField(upload_to="tags", null=True, blank=True) def __str__(self): return self.value…

VIEW QUESTION

Groupby using Django's ORM to get a dictionary of lists from the queryset of model with foreignkey – Postgresql

I have two models, Business and Employee: from django.db import models class Business(models.Model): name = models.CharField(max_length=150) # ... class Employee(models.Model): business = models.ForeignKey( Business, related_name="employees", on_delete=models.CASCADE, ) name = models.CharField(max_length=150) # ... Here's a sample data: Business.objects.create(name="first company") Business.objects.create(name="second company")…

VIEW QUESTION
Back To Top
Search