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
0 answers

Check Model instance against QuerySet

Is there a way to validate a Model instance against a QuerySet in Django, without hitting the database? I am defining a set of common QuerySets and using different model Managers for them and I would like a method on my Model that I can run to check…
0
votes
1 answer

default model manager only get objects that belong to a logged in user

When I get a list of objects I only ever want to the objects that belong to the logged in user. I'm thinking, maybe this can be done in the model manager by overriding the default manager, but I'm unsure how to get the logged in use. This is what I…
jason
  • 2,895
  • 8
  • 26
  • 38
0
votes
2 answers

Problems with django managers

I have following model: class UserProfile(models.Model): """ User profile model, cintains a Foreign Key, which links it to the user profile. """ about = models.TextField(blank=True) user = models.ForeignKey(User,…
Oleg Tarasenko
  • 9,324
  • 18
  • 73
  • 102
0
votes
1 answer

Django - how to write custom queryset per-field instead instead of per-model

I want to create a custom field such that if the field is queried, then the filter is always __iexact. Example: class Domain(models.Model): domain = models.IExactCharField() name = models.CharField() I want a query like…
John Smith
  • 179
  • 7
0
votes
1 answer

PyCharm doesn't understand custom Manager of model

I extend default model manager and add cache-specific logic to it: class ReadOnlyManager(manager.Manager): use_for_related_fields = True def create(self, **kwargs): obj = super(ReadOnlyManager, self).create(**kwargs) …
Marboni
  • 2,399
  • 3
  • 25
  • 42
0
votes
2 answers

django: how to memoize model manager methods?

I have a memoized Django model manager method as follows: class GroupManager(models.Manager): def get_for_user(self, user): cache_key = 'groups_%s' % (user.id) if not hasattr(self, key): groups = get_groups_somehow() …
onurmatik
  • 5,105
  • 7
  • 42
  • 67
0
votes
0 answers

How do I append more objects to a json file?

I am trying to create test fixtures for a Django project. I have a Question child object and a Node parent object. Because of some custom managers, the parent object Node are not captured with manage.py dumpdata. I'm attempting to create my own…
BryanWheelock
  • 12,146
  • 18
  • 64
  • 109
0
votes
1 answer

How do I attach an instance-specific queryset to a model in Django?

I am making a very minimal user-to-user messaging app using Django 1.4. I want to fetch unread messages that a user received in a straightforward way from my templates. My model looks something like this: from django.contrib.auth.models import…
-1
votes
1 answer

Django-Filter over Managers

I've been stuck in this for several weeks now and I believe the answer is super simple but somehow I can't find it anywhere online. Which makes me think I'm going about it totally wrong. All I want to do is be able to filter my stats such as the…
-1
votes
2 answers

How to use a Managers to save data in Django

I understand the role of Managers in Django when listing or filtering data. However, when it comes to saving data on the model I often see the following two ways used... Using a Manager: class Project(TimeStampedModel): stuff def…
Prometheus
  • 32,405
  • 54
  • 166
  • 302
-1
votes
1 answer

How can I print out an HTML table that access 2 tables in Django?

To get started with Django, I'm using it to build a small site for my softball team where we can list the stats of each player. For the model I've defined 2 tables - Player and Statline where the player in Statline is the foreign key. class…
rails_newbie
  • 53
  • 1
  • 10
1 2 3
16
17