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

Do DRF views use its queryset's object manager?

If I have a custom object manager with a custom create function for a model: class CustomManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(custom=True) def create(self): kwargs["custom"] = True …
0
votes
1 answer

Django: related_name issue

I am trying to make a query with related_name. I need to list tenants and its domain. But I am getting this error: 'TenantManager' object has no attribute 'domains' What am I doing wrong? models.py class Tenant(TenantMixin): id =…
catdev
  • 68
  • 4
0
votes
1 answer

How do i modify my create function in Django model manager

So i have this model: class Token(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=False) code = models.IntegerField(default=code) date_created = models.DateTimeField(auto_now_add=True) …
Melly
  • 675
  • 8
  • 24
0
votes
0 answers

'UserManager' object has no attribute 'validate'

My usual registration and login validators stopped working and I'm banging my head against the wall trying to figure out why. This is the error: AttributeError at /register 'UserManager' object has no attribute 'validate' Models.py class…
0
votes
2 answers

Django creates two model instances instead of one

I'm trying to learn some django basics following one turorial from youtube and have got strange result when I try to create some model instances using forms. Django implicitly creates two duplicate instances. This is my view: from django.shortcuts…
Alex
  • 153
  • 7
0
votes
1 answer

how to seprately queryset admin django and rest api by model manger?

By code below in admin panel query set return only rows that is_deleted is "false" if I want to return all rows. I have one idea but not sure that is bests or does not have a bug. all models inherit from this model class BaseModel(models.Model): …
0
votes
1 answer

How to filter draft contents from django website?

I have two options for my articles in my django website: "draft" and "published" I wrote sth that helps me show only the articles that are on "published" status in admin page. But the code doesn't work. when I click on the specified category for…
0
votes
1 answer

How to add a calculated field to a django query expression

I have a Django model, DocumentComments, with two datetime fields, created and updated. I am working on a search function that parses a search string and returns a Q expression to query the DocumentComments model based on the values in the search…
user1045680
  • 815
  • 2
  • 9
  • 19
0
votes
1 answer

Recursive relationship in Django: get all the interrelated records from each record

I have this model for a tune: class MsTune(models.Model): name = models.CharField(max_length=255) ms = models.ForeignKey(Manuscript, on_delete=models.CASCADE, related_name="mstunes") concordances = models.ManyToManyField("self",…
HBMCS
  • 686
  • 5
  • 25
0
votes
2 answers

Help with creating a custom create and a custom get method

I have two models like so: class Visit(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=65535, null=False) class Session: id = models.AutoField(primary_key=True) visit =…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
0
votes
1 answer

pytest: how to avoid repetition in custom User manager testing

I'm testing a custom user manager with pytest and factory_boy. I want to test those cases where information required to create a new user is incomplete, but I have different required parameters at the moment there are 3 (email, username,…
Cristian Flórez
  • 2,277
  • 5
  • 29
  • 51
0
votes
0 answers

django change the default query set based on the requesting user

I have a system with multiple organizations logging in and interacting with us and our partners. I have a table that keeps track of what users have access to what organizations. I would like for customers to only see their own records. I am doing…
0
votes
1 answer

How to use default manager in django migrations with inherited models?

I have a model Baz that's inheriting from an abstract model Bar which is inheriting as well from an other abstract model Foo. from django.db import models class BarManager(models.Manager): pass class Foo(models.Model): attr1 =…
mdalp
  • 77
  • 6
0
votes
4 answers

DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

hi i create a custom manager class called usermanager in monage.py to customise my login template for 2 types of user admin,entrepreneur #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os from…
user3828990
  • 17
  • 1
  • 9
0
votes
1 answer

Django manager in lookup fields

I have a SoftDeletableModel named Offer: class Offer(SoftDeletableModel): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name='offers') order = models.ForeignKey(Order, on_delete=models.PROTECT,…
AlexMercer
  • 301
  • 3
  • 10