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

Managers, model inheritance or what for slicing Users in django?

I'm writing a Project in Django where I've 5 kind of groups of Users: Group1 Group2 ... Then I've a Model, Item which has many relation with users, the Item has one Owner (a User in Group1), a Customer (an User in Group2) and many RelatedUser…
Enrico Carlesso
  • 6,818
  • 4
  • 34
  • 42
0
votes
0 answers

Django with Tornado: Django models are not updated on tornado server

I'm accessing Django models from a Tornado server, but I'm stuck on a problem. I've two servers running: one main gunicorn server which serves the whole Django project and other Tornado server for websockets. When I'm adding a model from via main…
Dheerendra
  • 1,488
  • 5
  • 19
  • 36
0
votes
1 answer

Refactoring a custom User model to user UserProfile: Should I create a custom UserManager or add user.get_profile() dozens of times?

I have been refactoring an app that had customized the standard User model from django.contrib.auth.models by creating a UserProfile and defining it with AUTH_PROFILE_MODULE. The problem is the attributes in UserProfile are used throughout the…
BryanWheelock
  • 12,146
  • 18
  • 64
  • 109
0
votes
1 answer

expanding the SQL query inside managers in Django models?

Here is the code from django docs that explains the use of managers. class PollManager(models.Manager): def with_counts(self): from django.db import connection cursor = connection.cursor() cursor.execute(""" …
brain storm
  • 30,124
  • 69
  • 225
  • 393
0
votes
2 answers

Filtering manager for django model, customized by user

I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return True and I want to override its default Manager. But I don't know how to pass the current user variable to the…
Valentin Golev
  • 9,965
  • 10
  • 60
  • 84
0
votes
2 answers

Validating input in custom manager methods?

Let's say I'm creating a polls app, and I want users to create their polls and their choices together, and not modify them at a later point. At the moment I have something like: class PollManager(models.Manager): def create_poll(self, name,…
0
votes
1 answer

custom manager object not working in Django?

Here are my models and the manager class. I think the problem is in the PostingFilterManager below. They way I search of the keywords in title and body_text is wrong. I want to query for a list of keywords in title and body_text of Postings model…
brain storm
  • 30,124
  • 69
  • 225
  • 393
0
votes
1 answer

How can I filter a model based on a field in child model?

I have the following model structure. Is it possible to alter the InventoryManager to check if a loaf is no longer in inventory due to having been sliced up? from django.db import models from shipping.models import Shipment class…
Joost VanDorp
  • 348
  • 1
  • 2
  • 10
0
votes
1 answer

how does this model work in Django?

I found this code for a blog post app written using Django here: I am confused with what this snippet of code does: Please explain what the CommentManager class below do and how the parameters passed to it are assigned to some 'arbitrary keys'. The…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
0
votes
1 answer

Model manager for start_date and end_date not working if date is set in the future

Im trying to write a model Manager to get all entries that is published, and start_date is in the past of now. The strange thing is if I set the date to a value in the past (1 minute prior), everything works, but if I set the date in the future (1…
Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81
0
votes
2 answers

django: got an unexpected keyword argument while accessing ForeignKey _id-Field in Manager

I have a model which looks like this: class Mentorship (models.Model): mentor = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='mentor_user_id') mentee = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='mentee_user_id') …
Chris
  • 612
  • 7
  • 16
0
votes
1 answer

Django: Model inheriting from base model with custom manager. Can the manager have dynamic variables?

I need to have all my models inherit this manager (Haven't tested this manager and it may be ridiculous so I'm completely open to suggestion/criticism on it as well): class AccountFilterManager(models.Manager): def __init__(self, account=None,…
orokusaki
  • 55,146
  • 59
  • 179
  • 257
0
votes
1 answer

How to filter relationship item in Django?

Lets say I have 2 model class. Category has a name and multiple tags and Tag has a name, can be visible or not. EDIT : Lets say that I have a list of categories and for each category I would like to only display the tags that have visible=True, how…
i_am_jc
  • 3
  • 3
0
votes
2 answers

Django what is "objects" inside a Manager

Normally I'd access the queryset via SomeModel.objects(). I notice that inside the model, the objects is defined to be some Manager, like, objects=SomeManager(). So, if I'm defining a method inside a Manager, how would I access objects? As in...…
reedvoid
  • 1,203
  • 3
  • 18
  • 34
0
votes
1 answer

Django inherited model instance creation function

Say I have the following, Model_1 has 1 integer, Model_2 inherits Model_1 and adds another integer. class Model_1Manager (models.Manager): def create (self, i) m = self.model(value1=i) m.save() class Model_1 (models.Model): value1 =…
reedvoid
  • 1,203
  • 3
  • 18
  • 34
1 2 3
16
17