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
4
votes
1 answer

django related manager - in template

i am trying to show the latest rating score of a location. i have 2 tables(django models) Class Location(models.Model): locationname = models.CharField() ... Class Rating(models.Model): von_location =…
doniyor
  • 36,596
  • 57
  • 175
  • 260
3
votes
1 answer

TypeError: Direct assignment to the reverse side of a related set is prohibited

I have a Django model 'Restaurant' which has a field parent_rest_id, which refers to one its parent restaurant which is saved in same table. class Restaurant(DefaultColumns): name = models.CharField(null=False, max_length=40) restaurant_code =…
3
votes
0 answers

Overriding Django RelatedManager and Queryset to filter on a field in the Through Model

I have two models that are linked via Many-To-Many field via third Through Model. The Through Model has some extra fields in it. I want to override the RelatedManager to produce some custom QuerySets that use the extra fields in the Through Model.…
s_boardman
  • 416
  • 3
  • 9
  • 27
3
votes
0 answers

Django Use Many To Many with Through in Form

I have a data model where I am using a manual intermediate table for a m2m relationship. Building on the classical example from the django doc: from django.db import models INSTRUMENT_CHOICES = ( ('guitar', 'Guitar'), ('bass', 'Bass…
Leonardo
  • 4,046
  • 5
  • 44
  • 85
3
votes
0 answers

Specifying ordering of backref / RelatedManager in Django

I currently have two Models: class Blog(Model): ... class Entry(Model): blog = models.ForeignKey(Blog) capture_dt = models.DateTimeField() If I want blog.entry_set to be ordered by capture_dt, it seems like the best way to get this is…
Alex Rothberg
  • 10,243
  • 13
  • 60
  • 120
3
votes
0 answers

Django REST Framework nested serializer and select_related

I have the following setup: I am using django-rest-framework and django-model-utils InheritanceManager to automatically get the child objects. models.py: class Location(models.Model): address = models.CharField(max_length=255) class…
3
votes
2 answers

sort django queryset by latest instance of a subset of related model

I have an Order model and order_event model. Each order_event has a foreignkey to order. so from an order instance i can get: myorder.order_event_set. I want to get a list of all orders but i want them to be sorted by the date of the last event. A…
2
votes
1 answer

Access RelatedManager object in django

I have the following model : class Travel(models.Model): purpose = models.CharField(max_length=250, null=True) amount = models.IntegerField() class TravelSection(models.Model): travel = models.ForeignKey(Travel, related_name='sections',…
user1595929
  • 1,284
  • 3
  • 13
  • 23
2
votes
1 answer

Django error: The QuerySet value for an exact lookup must be limited to one result using slicing?

I have the following models schema: class Site(models.Model): name = models.CharField(max_length=255) location = models.OneToOneField(GeoLocation, on_delete=models.PROTECT, …
user12177026
2
votes
1 answer

Create or Update field in Django many-to-many-through model

I want to create_or_update in m-m through model field This is my models.py from django.db import models class Person(models.Model): name = models.CharField(max_length=128) def __str__(self): return self.name class…
Somil
  • 1,921
  • 1
  • 21
  • 35
2
votes
1 answer

Django: Programmatically add Groups on User save

After a user is saved, I need to make sure that its instance is associated with a group by default. I have found two ways to achieve that: Overriding the model's save() method models.py: from django.contrib.auth.models import AbstractUser,…
raratiru
  • 8,748
  • 4
  • 73
  • 113
2
votes
2 answers

Django - edit both sides of a many-to-many relation with generic UpdateView

I have a question whether or not it is possible to use the generic UpdateView class to edit "both sides" of a many-to-many relationship. I have the following classes defined in models.py: class SomeCategory(models.Model): code =…
2
votes
1 answer

related objects queries django rest framework

I have the following models class STUser(AbstractBaseUser): email = models.EmailField(unique=True) name = models.CharField(max_length=255) companyname = models.CharField(max_length=200, blank=True, null=True) ... class…
user9487981
2
votes
2 answers

Django: filter() on multiple instances of related models

My model is as following: I have set of Dudes, and each Dude has a set of preferences. I can easily find Dudes based on their single preference, but I need to find those preferring two different things. I tried to pass two Q objects to filter()…
2
votes
1 answer

Get all parent categories Django - Follow foreign key UP

I got the following models: class Category(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey("self", blank=True, null=True) class Meta: verbose_name = _("category") verbose_name_plural =…
1
2
3
8 9