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

Custom Django Model Managers giving error when trying to use it

I'm trying to write a simple model manager that will filter on a particular field. I have a model which looks like this: """Model definition for Period.""" year = models.ForeignKey(Year, on_delete=models.PROTECT) name =…
Hanny
  • 580
  • 3
  • 16
  • 44
0
votes
1 answer

When to use a custom model manager?

Right now i'm reading about custom managers that you can use to add additional logic when doing a CRUD action like Create. You make a custom manager class and then initialize the objects attribute of the table class with an instance of the custom…
FAM_Maurice
  • 363
  • 3
  • 10
0
votes
1 answer

Custom Chainable QuerySet

This is a piece of my code from django.db import models from django.db.models.query import QuerySet from mptt.models import MPTTModel from base.models import Content, OrderedContent class ArgumentQuerySet(QuerySet): def…
0
votes
0 answers

Update a Model in Django right before the backend select

Before my Model in Django gets hydrated and filled with data, I want to update (alter) my model, save it back to the database and then go on the normal way. My approach (not working) as now is this: from django.db import models from MyApp import…
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
0
votes
1 answer

Django prevent users from editing their own record in admin

In Django I have model called Loans. I want users to be able to edit a loan created by someone else, but not if they created it themselves. As a bonus, I would like staff members not to be able to edit loans that belong to other staff. How can I do…
Davtho1983
  • 3,827
  • 8
  • 54
  • 105
0
votes
0 answers

Django Model.create won't save to database

I'm trying to create an instance of a model (Transaction) from a view's post method but it's not saving to the database, but to my surprise is that, after "creating the object" and it not saving, i can pass it to my context dict and use its values,…
0
votes
1 answer

create fixtures with custom manager methods, json dumps and ways to avoid type error :xxx is not json serializable

I'm trying to create a test fixture using custom manager methods as my app uses a subset of dbtables and fewer records. so i dropped the idea of using initial_data. In manager I'm doing something like this. in Managers.py: sitedict =…
stackover
  • 6,275
  • 6
  • 22
  • 20
0
votes
1 answer

UNIQUE constraint failed in django project

I have an application in django 1.11, where I have an app 'accounts' to manage users. User can have assigned roles, with which there are problems when creating usera using manager. When adding a username, I get an error: IntegrityError at…
user10605113
  • 211
  • 1
  • 10
0
votes
1 answer

Django custom creation manager logic for temporal database

I am trying to develop a Django application that has built-in logic around temporal states for objects. The desire is to be able to have a singular object representing a resource, while having attributes of that resource be able to change over time.…
wakey
  • 2,283
  • 4
  • 31
  • 58
0
votes
1 answer

Django Manager for Group model does not work - returns empty queryset

I'm junior dev. I want to create managers for Django Groups. One new one and one that will override default manager EDIT: Django 1.8, python 2.7.15 My managers: class DefaultGroupManager(models.Manager): def get_queryset(self): test_ids…
Adrian Kurzeja
  • 797
  • 1
  • 11
  • 27
0
votes
2 answers

Django Group.objects monkey patch problem - 'NoneType' object has no attribute '_meta'

I'm junior dev and I'm trying to monkey patch django.contrib.auth.models Group manager. (Python 2.7.15, Django 1.8) There is my code: class DefaultGroupManager(models.Manager): def get_queryset(self): tests = Test.objects.values() …
Adrian Kurzeja
  • 797
  • 1
  • 11
  • 27
0
votes
0 answers

How to access the instance from a model manager?

I was told that doesn't make sense as managers operate on all rows not a single instance but I see what I want to achieve done in django-taggit library. Here: https://github.com/alex/django-taggit/blob/master/taggit/managers.py And the the…
Adam
  • 2,948
  • 10
  • 43
  • 74
0
votes
0 answers

Access related manager method from another manager

I am trying to access a manager method from a manager of a related model but I'm having no success. Let's say these are my models: class ModelA(models.Model): description = models.TextField(blank=True) objects =…
Leonardo
  • 4,046
  • 5
  • 44
  • 85
0
votes
1 answer

Command object has no attribute meta, Django management commands

I am trying to run a one time management command to pre-populate a db. Here is the model: class ZipCode(models.Model): zip_code = models.CharField(max_length=7) latitude = models.DecimalField(decimal_places=6, max_digits =12) longitude =…
0
votes
2 answers

Best practice when updating Django model fields? Is this what manager classes are for?

I am very new to Django and I am wondering what the best practice is for updating a field. Here is my model: class Website(models.Model): id = models.AutoField(primary_key=True) url = models.TextField() is_awesome =…
superdee
  • 637
  • 10
  • 23