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
1
vote
1 answer

Build a Django "ForeignKey" that returns multiple values

I'd like to build a new related field type. Here's a simple example: class CustomQuerySet(QuerySet): def current(self): return self.filter(invalid_date__isnull=True) class CustomManager(Manager): def get_query_set(self): …
Aaron McMillin
  • 2,532
  • 27
  • 42
1
vote
1 answer

Django ORM cannot resolve keyword for related field for aggregate when model used by more than one application

In Django 1.5 I have 3 apps: common, app1, app2 in which I have the following (simplified) models: # common/models.py class ApiUser(models.Model): username = models.CharField(max_length=255) channel = models.CharField(max_length=20) #…
rojoca
  • 11,040
  • 4
  • 45
  • 46
0
votes
1 answer

Join tables in Django that share the same ForeignKey

I have three classes I'd like to query. I would like to let the database do the work. Would it be possible to run a single query on the User object to get all the related fields that match? I am trying to avoid joining the three tables in my code.…
Val Neekman
  • 17,692
  • 14
  • 63
  • 66
0
votes
1 answer

Django Related Manager Add

I have an intermediate model which is as follows - class Link_Book_Course(models.Model): book = models.ForeignKey(Book) course = models.ForeignKey(Course) image = models.CharField(max_length = 200, null=True) rating =…
praks5432
  • 7,246
  • 32
  • 91
  • 156
0
votes
0 answers

Intances are created when using annotate and Foreign Key

I have the following situation: I am creating an app where I have a Person model and I want to store a status history in a table, so that looking for the most recent status in the table would return the current status of the person. My solution was…
0
votes
1 answer

Django: How to navigate multi-level reverse relationships?

I have several models that are related hierarchically: Projects have one or more Experiments Experiments have one or more Scans Scans have one or more Scan Decisions Simplified Models: class Project(models.Model): id =…
Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
0
votes
1 answer

Django sequentially link tables through ForeignKey

I have a User Following Django Models system based on one posted here. How can I get all Post objects of that a user follows, having two models: Post and UserFollowings pointing at User model via ForeignKey but User model not pointing back? I need…
euh
  • 319
  • 2
  • 11
0
votes
0 answers

RelatedManager object is not iterable

Whenever I run my code, I get a "RelatedManager" object is not iterable error. Here is my models.py: from django.db import models from django.contrib.auth.models import User from django.utils import timezone from django.urls import reverse class…
Keshav V.
  • 73
  • 7
0
votes
2 answers

Django access manytomany field from related_name in a view

I have what i think is a simple question but I am struggling to find out how it works. I get how related name works for foreign keys but with many to many fields it seems to break my brain. I have two 3 models at play here. A User, TeamMember and…
jAC
  • 3,155
  • 3
  • 18
  • 29
0
votes
1 answer

How do I perform a nexted query on django models

so i have these 2 model Profile (have one to one relationship with my default django User model) Item ( also have one to one relationship with my default django User model) from Item model, how do i get access to Profile model using User…
0
votes
0 answers

Django related objects reference remove(obj, bulk=False)

I've tried to use related manager remove() method with bulk=False but no success.Can anyone tell me what happened and where is mistake ? Thanks. In order to use remove(obj, bulk=False) I created models like Then I tried method itself in…
TheBrko
  • 11
  • 3
0
votes
0 answers

Access related model fields from ModelAdmin actions for exporting to excel

I am desperately waiting for someone attention to get my question answered.... please help.. ModelAdmin model has to export to Excel action method. I need to access related model fields in action method. That means I can not pass any arguments…
0
votes
1 answer

How do I find the class that RelatedManager is managing when the QuerySet is empty?

I have two models that are related. From the object of one, I want to get the class name of the other. Currently, I'm doing it this way: associated_model = getattr(object_specific, associated_model_str) associated_model_instance =…
msb
  • 3,899
  • 3
  • 31
  • 38
0
votes
0 answers

Django admin custom filter by ManyToMany through model

I need to create a filter in Django admin by a Through Model. class Location(models.Model): created_at = models.DateTimeField(editable=False, auto_now_add=True) lat = models.DecimalField(max_digits=13, decimal_places=10, default=None) …
0
votes
1 answer

Django verbose_name of reverse relation

I have a model like: class Question(models.Model): ... class Answer(models.Model): question = models.ForeignKey( Question, null=False, blank=False, on_delete=models.CASCADE, related_name='answers', …
1 2 3
8 9