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

django one to one reverse lookup override

Need help with one to one reverse lookup. My models: class User(MarkedAsDeletedMixin): fields here class UserProfile(MarkedAsDeletedMixin): user = models.OneToOneField(User) class MarkedAsDeletedMixin(models.Model): marked_as_deleted =…
Adilet Maratov
  • 1,312
  • 2
  • 14
  • 24
0
votes
1 answer

how to assign a user in a particular group in the registration process itself in django

I have created a custom user creation form in which I included a choice field 'Company' & 'Truck' so that user can be identified according to the field. Here is my registration page I also created two groups Truck & Company via admin page. I want to…
vanam
  • 135
  • 1
  • 4
  • 14
0
votes
0 answers

Django transfer data in custom manager for filtering query

Im trying to make dialog app. I can check if the user has unread messages from all senders, but i cant filter unread query for each sender #model from .middleware import get_current_user #local copy of user class ChatManager(models.Manager): …
0
votes
1 answer

DJANGO - Queryset and model design

So I've been stuck with a design problem for the last couple of days and have sunk countless hours into it, to no avail. My problem is that I wish return all the active Articles. I have made a method within the model, however am unable to use…
0
votes
1 answer

Django Admin Manager Override

I have a Multiple Choice Questions, in which Model Question is Question and Choices as answers. I want to limit the number of Choices that can be created to a Question to 4. A models.Manager is used to verify the number of choices for the question.…
Karan Kumar
  • 2,655
  • 19
  • 36
0
votes
1 answer

Django - Perform queryset level task before delete

I have the following models: class Camera(models.Model) deleted_images_counter = models.IntegerField(...) class Image(models.Model) image = models.ImageField(....) camera = models.ForeignKey(Camera) Now, i want to update the camera…
Agey
  • 891
  • 8
  • 17
0
votes
2 answers

Getting items in model referenced by a onetoonemodel in django

I have this database layout class Clinic(models.Model): class Menu(models.Model): ... menu = models.OneToOneField(Clinic, related_name='menu') class Item(models.Model): ... menu = models.ForeignKey('Menu') and I would like to…
user3282276
  • 3,674
  • 8
  • 32
  • 48
0
votes
1 answer

GeoDjango: Extending GeoManager with Search Functionality

I am learning to use GeoDjango, and it is my understanding that a GeoManager() is needed to interact with GIS objects. However, I was trying to build in some search functionality for my models. I found this old post that showed how to build a nifty…
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
0
votes
1 answer

Django Queryset dynamic field value based on request.user

I have a webservice that returns list of links. { [ {"id":1,"href":"http://website.com","title":"Title1"}, {"id":2,"href":"http://website.com","title":"Title2"}, {"id":3,"href":"http://website.com","title":"Title1"} …
0
votes
0 answers

Form not valid. ID: Select a valid choice. That choice is not one of the available choices

When I run this code, even the whole data is correct. demobilized_formset.is_valid() gives me False and demobilized_formset.errors gives {u'id': [u'Select a valid choice. That choice is not one of the available choices.']} I don't know why an error…
nabeel
  • 1,181
  • 2
  • 10
  • 24
0
votes
1 answer

How to manage Model, Manager and QuerySet?

If each of Model objects has many Manager and QuerySet, it causes my models.py to be unreadable and so long. How do I manage them? I come up with a solution. Originally. Model, Manager and QuerySet are in models.py. I want to separate from them and…
Tony
  • 1,019
  • 2
  • 13
  • 25
0
votes
0 answers

Can a manager's get_queryset function query across relationships?

I'm trying to use a custom Manager class to limit the queryset when accessing objects from a model. But I'd like to limit the queryset with fields from a related model, something like class MyManager(models.Manager): def get_queryset(self): …
brandonchinn178
  • 519
  • 3
  • 20
0
votes
1 answer

Difference between custom QuerySet methods implementation

Reading djangodocs about managers, I'm interested in different implementation of custom QuerySet methods. So, I'm giving my examples. First implementations as in djangodocs: class ProductQuerySet(models.QuerySet): def small(self): …
litwisha
  • 392
  • 3
  • 12
0
votes
1 answer

Using a custom reverse manager in Filter

Given I have: class Publisher(Model): pass class Author(Model): name = models.CharField(...) publisher = models.ForeignKey(Publisher) is_alive = models.BooleanField(...) objects = models.Manager() # Default Manager alives =…
Alex Rothberg
  • 10,243
  • 13
  • 60
  • 120
0
votes
1 answer

Test case give error object has no attribute '_meta'

I have the following Django test case: objects = ActionManager() action = objects.log_action(user=self.test_user) self.assertIsInstance(action, Action) However, because of the unconventional way I'm accessing the manager in the above example I get…
Prometheus
  • 32,405
  • 54
  • 166
  • 302