Questions tagged [django-managers]

A Manager is the interface through which database query operations are provided to Django models.

A Manager is the interface through which database query operations are provided to Django models.

Source: https://docs.djangoproject.com/en/dev/topics/db/managers/

251 questions
0
votes
2 answers

Manager isn't accessible via "model" instances django

I am suffering an error with django and their custom Managers. I have this custom Manager: class CallManager(models.Manager): def get_queryset(self): return super(CallManager, self).get_queryset().filter(is_active=True) class…
0
votes
1 answer

Where is the update method on the BaseUserManager class?

I have the following class that creates a new user and the user has a m2m object located in the kwargs dict and the update creates this error: 'SomeUser' object has no attribute 'update'. class SomeUserManager(BaseUserManager): def…
Chris
  • 4,643
  • 6
  • 31
  • 49
0
votes
1 answer

CurrentSiteManager via related model

Is it possible to use the CurrentSiteManager to check the site of a related object - not the site of the object itself? So, given the following models:- class A(models.Model): site = models.ForeignKey(Site) class B(models.Model): a =…
bodger
  • 1,112
  • 6
  • 24
0
votes
1 answer

Word frequency count within record with Django model Manager

I am building a Django app that works with a text-heavy database, and it counts some predefined phrases within the text. It does not count the number of records that contain the phrases, but it counts the frequency within one record. And here is…
0
votes
1 answer

How to avoid repeated django prefetch related database hits

When i fetch a client i want to also prefetch all related probes and probe channels, and when i fetch a probe i also want to fetch all related probe channels. But it seems that when i get a client object, or view the admin, it runs the get_queryset…
rbennell
  • 1,134
  • 11
  • 14
0
votes
1 answer

django queryset method on related model filter

I have the following set-up: class Person(models.Model): name class AppointmentQuerySet(models.QuerySet): def active(self): from django.utils import timezone return self.filter(initial_date__date__lte=timezone.now().date()) class…
Onilol
  • 1,315
  • 16
  • 41
0
votes
2 answers

custom manager is returning all the objects django.11 postgres

class CustomManager(models.Manager): def get_query_set(self): queryset = super(CustomManager, self).get_query_set() return queryset.filter( models.Q(expiration_date__gte=datetime.date.today()) | models.Q( …
anjaneyulubatta505
  • 10,713
  • 1
  • 52
  • 62
0
votes
1 answer

Using custom Manager & QuerySet does not work with related objects properly

Given two simple models: class Employee(Model): user = models.OneToOneField(User, on_delete=models.SET_NULL, null=True) class AttendanceLog(Model): from_datetime = models.DateTimeField(_('from')) to_datetime =…
emihir0
  • 1,200
  • 3
  • 16
  • 39
0
votes
1 answer

Django custom manager to filter nearby through related model

I have two models Shop and Address. Shop Model: class Shop(BaseModel): name = models.CharField( max_length=100, blank=True, null=True ) address = models.ForeignKey( Address, blank=True, …
user2858738
  • 520
  • 4
  • 15
0
votes
1 answer

Django - Meta.base_manager_name - make related argument in the custom queryset and manager

I have a custom model manager and a custom queryset defined specifically for related obj which means I have defined Meta.base_manager_name in the model. I would like to use a all() manager method which fetches related obj on a OneToOneFeild. Now I…
Uma
  • 689
  • 2
  • 12
  • 35
0
votes
0 answers

How to access Manager of through model

I've created a Manager for a through model and want to use it when accessing the Many-to-many objects. class Contact(models.Model): first_name = models.CharField(max_length=50, null=True, blank=True) last_name =…
toni88x
  • 53
  • 2
  • 8
0
votes
1 answer

How to create a custom related manager in Django?

class ModelA(Model): pass class ModelB(Model): modela = ForeignKey(ModelA, on_delete=CASCADE) class ModelC(Model): modelb = ForeignKey(ModelB, on_delete_CASCADE) In this case Django will automatically create a few additional managers…
user4385532
0
votes
1 answer

Run custom code when adding to Many-To-One relation

from django.db import models class Reporter(models.Model): pass class Article(models.Model): reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE, null=True) Now whenever I add an article to a reporter (like below) I want to…
0
votes
2 answers

Django: Where should I put queries about User which is in relation with other models

I am writing a Django app which define groups of user. A user can be part of many groups. I want to be able to retrieve, from a list of groups, users which are members of at least one of those groups and with no duplicate. So i wrote a query to…
0
votes
1 answer

Annotate number of identical items in manager

Let's say I have following simplified model: class CurrentInvoices(models.Manager): def get_queryset(self): qs = super(CurrentInvoices, self).get_queryset() current_invoices = qs.order_by('person',…
SaeX
  • 17,240
  • 16
  • 77
  • 97