Questions tagged [django-model-utils]

Django model mixins and utilities. django-model-utils supports Django 1.4.10 and later on Python 2.6, 2.7, 3.2, 3.3 and 3.4.

Django model mixins and utilities.

Installation Install from PyPI with pip:

pip install django-model-utils

To use django-model-utils in your Django project, just import and use the utility classes described in this documentation; there is no need to modify your INSTALLED_APPS setting.

Dependencies django-model-utils supports Django 1.4.2 and later on Python 2.6, 2.7, 3.2, and 3.3.

Documentation

29 questions
8
votes
1 answer

No module named 'model_utils'

I'm using Python 3.4.3 and django 1.9.8. In my models.py, I have from model_utils.managers import InheritanceManager But this error occurs: ImportError: No module named 'model_utils'
bitit1994
  • 362
  • 2
  • 4
  • 10
7
votes
3 answers

Django "ValueError: Can't bulk create a multi-table inherited model"

Problem I am using the django-model-utils InheritanceManager. I have a super Notification(models.Model) class which I use to create many notification subclasses such as PostNotification(Notification), CommentNotification(Notification), etc., and…
jenks
  • 383
  • 1
  • 3
  • 11
5
votes
2 answers

Django-model-utils Filter By Subclass

I'm using django-model-utils inheritance manager to query a data model with multi-table inheritance and it mostly works great! What doesn't work great is when I want to .select_subclasses() but also filter for a specific subclass. For example: class…
TheCatParty
  • 1,449
  • 12
  • 19
4
votes
1 answer

In django, is it possible to have a foreign key defined to some superclass, but having returned the subclass when queried?

Assuming I have the following models: class SomeSuperClass(models.Model): ... class SomeSubClassA(SomeSuperClass) ... class SomeSubClassB(SomeSuperClass) ... class SomeConnector(models.Model): reference =…
3
votes
1 answer

Is there a fix for InheritanceManager breaking static type checking?

I have added django-model-utils to an existing (large) project, and the build is now failing, as part of the build includes static type checking with mypy. It complains that models that I have added objects = InheritanceManager() to, don't have…
David Downes
  • 1,145
  • 10
  • 24
3
votes
1 answer

How to get key from model_utils triple Choices?

If I have some choices variable: In [1]: from model_utils import Choices In [2]: CHOICES = Choices( ...: (1, 'somekey', 'The long title'), ...: ) In [3]: CHOICES[1] Out[3]: 'The long title' How to retrieve somekey key from…
Danil
  • 4,781
  • 1
  • 35
  • 50
3
votes
1 answer

Django how to filter queryset by a subclass using django model utils?

I am using django-model-utils for inheritance Managers. I want to get results of only one subclass at a time. managers.py from model_utils.managers import InheritanceManager class PostManager(InheritanceManager): pass models.py from .managers…
Siddhesh Suthar
  • 425
  • 7
  • 9
3
votes
1 answer

Why does Django keeps asking content types are stale and need to be deleted

I've tried everything found: Can stale content types be automatically deleted in Django? Deleting unused Models, stale content types prompt InvalidBasesError: Cannot resolve bases for [] Django Wagtail CMS migrate:…
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
3
votes
0 answers

Django REST Framework nested serializer and select_related

I have the following setup: I am using django-rest-framework and django-model-utils InheritanceManager to automatically get the child objects. models.py: class Location(models.Model): address = models.CharField(max_length=255) class…
2
votes
1 answer

@classmethod error: TypeError: __call__() takes 2 positional arguments but 3 were given

I have a model/class like this: class MyModel(TimeStampedModel): some_field = models.CharField() @classmethod def my_class_method(cls, value, other_value): print(value) However, when I do this from another view: value =…
coler-j
  • 1,791
  • 1
  • 27
  • 57
2
votes
0 answers

How to filter or query using abstract parent class in Django model?

This one is interesting to solve. I am building a module to register address for hospital, medical store and doctors. There is an abstracted model PrimaryAddress and a subclass called MedicalStorePrimaryAddress, and more subclasses will use the same…
2
votes
1 answer

InheritanceManager bug when access parent-class elements (Django 2.0)

I'm currently trying to have a object oriented schema in Django 2.0 (Python 3.6.3) with a parent class Program and some children classes Snippet and Software. I saw that the model_utils module contains some tools to handle the polymorphism, and…
Ldm
  • 38
  • 6
1
vote
1 answer

How to resolve this "Invalid default value for a django.models field error"?

I am creating a student model which records homework details of a student. It works in a way that student has been given work to do at home with some deadlines of days or hours. When I migrate, I get this error I am getting this error File…
1
vote
0 answers

How to filter against subclass's fields with Django InheritanceManager?

I am using InheritanceManager from django-model-utils library. Is there a way to filter against fields of a subclass? Something like this: from model_utils.managers import InheritanceManager class A(models.Model): objects =…
1
vote
1 answer

Choices function in Django Models giving Error: Select a valid choice. 2 is not one of the available choices

Unable to set rating choice through Django admin console Error: Select a valid choice. 2 is not one of the available choices. models.py from model_utils import Choices class Course_Feedback(models.Model): course = models.ForeignKey(Course,…
user11879807
  • 251
  • 1
  • 3
  • 11
1
2