Questions tagged [django-related-manager]

django-related-manager refers to the RelatedManager class that is used in Django to manage one-to-many or many-to-many related context

django-related-manager refers to the RelatedManager class that is used in Django to manage one-to-many or many-to-many related context.

129 questions
0
votes
1 answer

Filter nested queryset in serializer

I have these models: class Item(..): .... class Folder(..): ... class File(..): item = ... folder = ... class FileSerializer(...): class Meta: model = File class FolderSerializer(...): …
0
votes
1 answer

Django getting one to many on same query

I need to display a view with Courses with its dependable Lectures on an accordion in html. A Course has many Lectures. class Course(models.Model): title = models.CharField(max_length=1500) def __str__(self): return self.title class…
0
votes
0 answers

Search by end nested relation django rest framework

I recently picked up an existing project in nodejs, this one is full of all kinds of problems. I decided to reconvert it for more ease with django rest framework, I try to keep the same json structure so as not to interfere with react. For the most…
0
votes
1 answer

How to find all related items of django foreign key with multi level self relationships?

Given a model: class Example(models.Model): name = models.CharField(max_length=50, blank=True) master= models.ForeignKey('Example', on_delete=models.PROTECT, blank=True, null=True) With this model, it is possible to have an "Example"…
0
votes
2 answers

Add or change a related_name argument

Django: 3.0.6 Below is my attempt to organize tags and tags for admin staff only (django-taggit is used). from taggit.managers import TaggableManager # django-taggit from taggit.models import TaggedItemBase # django-taggit class…
Michael
  • 4,273
  • 3
  • 40
  • 69
0
votes
1 answer

Filter django queryset: Query objects with two or more reverse-related objects with a certain identical field value

Suppose we have two models like this: from django.db import models ModelA(models.Model): ... ModelB(models.Model): a = models.ForeignKey(ModelA, ..., related_name='b_models') some_field = models.CharField(...) other_field = ... …
0
votes
1 answer

Django: Proper Way to Acess data from a One to Many Relationship?

I am having issues with accessing data through a django one to many relationship. After 3 painstaking days I figured out a way to display the data from the relationship by overriding the get_context_data method. I was wondering if that was the…
0
votes
1 answer

Overriding Django Admin's "add" button for related fields

I've been trying to override the functioning of +(add) button for related fields in Django admin to open a new tab instead of a popup. I looked at the RelatedObjectLookup.js to see how it works but still stuck at implementing the same functioning by…
0
votes
1 answer

Loop over related model's children in Django template

I have a model for a company. Then I have a base model for company posts. It contains common posts attributes. An attribute is the company that publishes the posts. It refers to the Company model with a ForeignKey. Finally I have a child model…
0
votes
1 answer

How to Annotate Specific Related Field Value

I am attempting to optimize some code. I have model with many related models, and I want to annotate and filter by the value of a field of a specific type of these related models, as they are designed to be generic. I can find all instances of the…
0
votes
1 answer

'Keyerror at /' when passing user with primary key in queryset for a listview

models.py class Notes(models.Model): author = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=100) content = models.TextField() date_added =…
0
votes
1 answer

How to get attribute of related object set in DRF serializer?

I am trying to nest data from a single attribute of a related set in one of my DRF serializers. So far, I am only able to do it through an intermediary serializer, which seems messy. I would like to do it directly. As of now, this is the structure…
0
votes
1 answer

Django - how to control and filter related objects

I have two models Note : there are some code i have removed to make the question simple class Categories(models.Model): category_name = models.CharField(max_length=100, null=True) class Courses(models.Model): course_name …
DAMAR225
  • 1,993
  • 1
  • 13
  • 22
0
votes
1 answer

Django filter table by foreign keys in related manager column

I have three models in my Django application: class MainData(models.Model): # bunch of fields class Label(models.Model): label = models.CharField(max_length=512, null=True, unique=True) class MapData(models.Model): labelMatch =…
kneedhelp
  • 555
  • 4
  • 18
0
votes
2 answers

How to set choices of field dynamically from foreign key related models field?

I have models as Offer , Wood , SliceTec and JointTec. And Wood related with SliceTec and JointTec by M2M field. At Django admin I can select multiple options for SliceTec and JointTec when adding new Wood record. No problem. When it comes to Offer…
1 2 3
8 9