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
7
votes
2 answers

django soft delete doesn't cascade delete

I'm using a soft delete in my django admin, done like this. The issue is that when I delete a foreign key item, that it doesn't seem to trigger the deletes for all the items it's linked to. Or maybe it does but it's not running the custom def…
darren
  • 18,845
  • 17
  • 60
  • 79
6
votes
2 answers

How to use custom managers in reverse relations?

I want to get the related object references and I want to use a custom manager. I see there has been already a question about it, but its not open anymore. So im creating a new one Edit: And its outdated. This is pretty much what im trying to…
Agey
  • 891
  • 8
  • 17
6
votes
1 answer

Django - accessing foreign key's Manager from django templates

I have two models: class Product(models.Model): name = models.CharField(max_length=255) class ProductPhoto(models.Model): product = models.ForeignKey('Product', related_name='photos') is_live = models.IntegerField(choices=LIVE_CHOICES,…
DavidL
  • 1,260
  • 2
  • 17
  • 35
5
votes
2 answers

Why does declaring a manager to a Django model, void "objects"

I have declared a manager to the following model, but after doing so, I can no longer use List.objects.get(). Anybody know why? class List(models.Model): title = models.CharField(max_length=20, unique=True) archived = models.BooleanField() …
Josh
  • 4,427
  • 5
  • 28
  • 27
5
votes
1 answer

Django pagination (get page no. corresponding to the object)

I have a paginate I am trying to get the index page from an object page (sort of pagination in reverse) The get_paginated_posts returns a paginator for the model Post: class PostManager(models.Manager): def get_paginated_posts(self,…
crodjer
  • 13,384
  • 9
  • 38
  • 52
5
votes
0 answers

Defining custom RelatedManager in django

I want to override related manager for a class. I have a Company model. It has state column which can be in ACTIVE, INACTIVE, SUSPENDED. I am adding 2 new states called SALES, CLOSED. Since its legacy model, just adding state can be…
Mohan
  • 1,850
  • 1
  • 19
  • 42
5
votes
2 answers

Django, Custom Managers affect save method?

I'm using Django 1.7. I've got a default custom manager that filters on an "active" boolean field. According to the docs, it needs to be the default manager to work with related fields (ie. accessing User.story_set only shows active Story objects).…
sybaritic
  • 392
  • 6
  • 15
5
votes
2 answers

Do Django Models inherit managers? (Mine seem not to)

I have 2 models: class A(Model): #Some Fields objects = ClassAManager() class B(A): #Some B-specific fields I would expect B.objects to give me access to an instance of ClassAManager, but this is not the case.... >>>…
Zach
  • 18,594
  • 18
  • 59
  • 68
5
votes
2 answers

Is timezone.now().date a function or a callable?

I'm writing a manager in Django 1.5. I want to return a QuerySet that contains objects with a start date either today or in the future. Based on this answer to a previous problem I presume my manager needs to use a callable rather than a function.…
cms_mgr
  • 1,977
  • 2
  • 17
  • 31
5
votes
1 answer

How to filter/exclude inactive comments from my annotated Django query?

I'm using the object_list generic view to quickly list a set of Articles. Each Article has comments attached to it. The query uses an annotation to Count() the number of comments and then order_by() that annotated number. 'queryset':…
5
votes
1 answer

Purpose of using a custom manager to create objects with django?

I see in the Django documentation : Model Instance reference : Creating objects You may be tempted to customize the model by overriding the __init__ method. If you do so, however, take care not to change the calling signature as any change may…
Levans
  • 14,196
  • 3
  • 49
  • 53
5
votes
1 answer

Override update method for a queryset - Django

How can we change the default process of the update method for a queryset in django as it does not call save method for each object. And since I have overridden the save method, I need it to be called each time the object is changed. I looked for…
ashish
  • 2,090
  • 3
  • 17
  • 16
4
votes
2 answers

Django manager queries don't work in a chain of queries. AttributeError: 'QuerySet' object has no attribute

Problem: I've implemented a custom manager for a model with just one custom query set named get_by_tag and it's working fine if I use it this way: ViewStatistic.objects.get_by_tag('some-tag-name').filter(user=user_id) But when I change the order of…
Hamidreza
  • 1,465
  • 12
  • 31
4
votes
3 answers

How do I access my model's custom manager in a Django data migration context?

I have a custom model manager used in several of my models. This manager helps speed up DB inserts. I need to perform a data migration, and it involves migrating several millions of records/objects. I need my custom manager in my data migration.…
4
votes
2 answers

Django custom manager`s method that changes data works incorrectly with other manager`s methods (filter, get, etc.)

I have created a custom Manager, but in my case its method adds some string to the end of particular field in a model instead of just filtering queryset as in usual cases. My goal is to return already changed objects when calling SomeModel.objects.…
Michael
  • 1,170
  • 2
  • 14
  • 35
1 2
3
16 17