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

How to force django model save method to lookup queryset in custom manager method?

I have a model named Run with a manager named RunManager and with a custom save() method as follows. class RunManager(models.Manager): use_for_related_fields = True def get_queryset(self): queryset = super(RunManager,…
1
vote
4 answers

Django Display first item from related_name list

I'm working on a project using Python(3.7) and Django(2.2) in which I have implemented two models ItemModel and Images so every item will have multiple images and added item into the images model and add a related_name but when I try to access these…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
1
vote
0 answers

How to order_by related field date with annotation?

i have this model : class Node(MPTTModel): parent = TreeForeignKey('self', on_delete=models.CASCADE, blank=True, null=True, related_name='children') name = models.TextField(blank=True, null=True) which have this…
Farhani Walid
  • 927
  • 1
  • 9
  • 20
1
vote
1 answer

Aggregate related integer-field values in Django template

I have this model which is related to a Node model, class Views(models.Model): related_tree = models.ForeignKey(Node, on_delete=models.CASCADE, blank=True, null=True, related_name='related_views') views_count =…
Farhani Walid
  • 927
  • 1
  • 9
  • 20
1
vote
0 answers

Accessing many to many data in class-based detail view with models in different apps Django

I have two models related via ManyToMany relationship, but they are located in separate apps. I am trying to load details of one model then adding the manytomany field in the template but the conventional way is not working. Here is my code so…
japheth
  • 373
  • 1
  • 10
  • 34
1
vote
0 answers

Django RelatedObjectDoesNotExist After Upgrade to 2.2

I've recently upgraded one of my Django projects from 1.9.6 to 2.2 and in doing so I'm getting a strange error around a specific ForeignKey relation. models.py class MyObject1(models.Model): myobject2 = models.ForeignKey(MyObject2, on_delete =…
apardes
  • 4,272
  • 7
  • 40
  • 66
1
vote
0 answers

Django Rest Framework Test: How to refresh a relation?

I have a permission in Django Rest Framework: from annoying.functions import get_object_or_None from django.utils.translation import ugettext_lazy as _ from rest_framework import permissions from restaurants.models import Restaurant class…
1
vote
1 answer

Django - Get related objects

I have 3 Models (lets say A, B, C). Model C has both A and B as Foreign keys. Now I have primary_key of A and I want to retrieve the list of related B objects. I want entire object of B not just fields which I can get using values() or…
1
vote
0 answers

Django annotation on related model

Having these models (simplified): class UserProfile(models.Model): user = models.OneToOneField(User) products = models.ManyToManyField(Product, through='UserProduct') class Product(models.Model): title =…
1
vote
1 answer

Get one related object in single request for Django ORM

I have this models class Book(models.Model): title = models.CharField(max_length=255, blank=False, null=False) class Like(models.Model): user = models.ForeignKey(User, related_name="like_user", blank=False, null=False) book =…
1
vote
2 answers

How to get image connected by Foreign Key via Template in django

i want to get the images form the image model in the template. class Products(models.Model): category = models.ForeignKey(Category) name= models.CharField(max_length=120, unique=True) slug = models.SlugField(unique = True) price =…
1
vote
0 answers

Model.add() in multiple database configuration

The related manager has a method called add that, "Adds the specified model objects to the related object set." For example, you can do: b = Blog.objects.get(id=1) e = Entry.objects.get(id=234) b.entry_set.add(e) # Associates Entry e with Blog…
mlissner
  • 17,359
  • 18
  • 106
  • 169
1
vote
1 answer

Related Resources with Django and Tastypie

EDIT 2: I have made some progress and have updated my code as follows: I have these three models in models.py: class Variables(models.Model): variableid = models.IntegerField(db_column='VariableID', primary_key=True) variableName =…
denvaar
  • 2,174
  • 2
  • 22
  • 26
1
vote
1 answer

Django queryset on related field

Django is to making a query much more complicated than it needs to be. A Sentiment may have a User and a Card, and I am getting the Cards which are not in the passed User's Sentiments This is the…
robert
  • 819
  • 1
  • 10
  • 24
1
vote
1 answer

Filtering QuerySet by __count of RelatedManager

I've got a QuerySet I'd like to filter by the count of a related_name. Currently I've got something like this: objResults = myObjects.filter(Q(links_by_source__status=ACCEPTED),Q(links_by_source__count=1)) However, when I run this I get the…
benwad
  • 6,414
  • 10
  • 59
  • 93
1 2 3
8 9