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
1
vote
1 answer

Django + (django-model-utils): Combining two models / inheriting from two models

I recently learned about model inheritance in Django. I used it to great succes using the awesome package django-model-utils. I inherited from the TimeStampedModel and from the SoftDeletableModel. My problem is that I only managed to do the…
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
1
vote
1 answer

Querying all objects including soft deleted ones of a SoftDeletableModel

I'm try to get rid of home-brew solution to favor more standard ones. My previous pattern: class MarkDeleteManager(models.Manager): use_for_related_fields = True def get_queryset(self): if "instance" in self._hints: …
Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
1
vote
1 answer

Django MonitorField() not working with Foreign Key if when condition is added

Greeting, as mention in the question, my MonitorField stop updating the date when I add a when condition in it, below is my code : class A(models.Model): name = models.CharField(max_length=50, unique=True) def __str__(self): return…
M.Izzat
  • 1,086
  • 4
  • 22
  • 50
1
vote
4 answers

Is there a way to have dictinary-like field in Django model?

Suppose, I am making a movie rating app. A logged-in user should be able to rate the movie with stars (in the range 1 to 5). I want to quickly access all the rater's name along with their rating. If a user rates the movie again, the rating should…
1
vote
1 answer

Django save behaving randomly

I have a Story model with a M2M relationship to some Resource objects. Some of the Resource objects are missing a name so I want to copy the title of the Story to the assigned Resource objects. Here is my code: from collector import models from…
user667804
  • 740
  • 6
  • 25
1
vote
1 answer

Attaching custom queryset to model via django-model-utils

I am trying to define a custom QuerySet subclass, and attach it to my model using django-model-utils. In previous Django versions (I am using 1.9), PassThroughManager was used to accomplish this by the following code: from model_utils.managers…
Edgar Navasardyan
  • 4,261
  • 8
  • 58
  • 121
1
vote
1 answer

Django - Override Default Manager in Admin - InheritanceManager

(This seems to be a common question based on the "Questions that may already have your answer" list, but none of those has helped me.) I have a several models with multi-table inheritance. In admin (and later, in the front-end app), I need to have a…
Adam Michael Wood
  • 1,730
  • 16
  • 23
1
vote
1 answer

For django-model-utils, how can `select_subclasses()` be applied to fields of an object?

I have some models like this: class Container(models.Model): pass class Parent(models.Model): container = models.ForeignKey(Container, related_name='items') pass class Child(Parent): pass class RedHeadedStepChild(Parent): …
Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
0
votes
1 answer

Django DRF - Access to field ForeignKey instance inside a custom serializer validator method

I'm currently having a bit of a conceptual headache over how best to reference the instance of a ForeignKey field inside a custom serializer validator method ... To give an overview of the system. I have the following "Candidate" model, the imporant…
0
votes
1 answer

How to show created in admin panel from TimeStampedModel

trying to follow https://github.com/jazzband/django-model-utils/issues/186 #admin.py class CompanyAdmin(admin.ModelAdmin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.readonly_fields += ( …
Harry Moreno
  • 10,231
  • 7
  • 64
  • 116
0
votes
1 answer

Django manager in lookup fields

I have a SoftDeletableModel named Offer: class Offer(SoftDeletableModel): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name='offers') order = models.ForeignKey(Order, on_delete=models.PROTECT,…
AlexMercer
  • 301
  • 3
  • 10
0
votes
0 answers

how to iterate on two subclass models with same for loop?

I want to create a photo sharing website, but i don't know how to iterate over this code: all_post = Images.objects.all().order_by('-created').select_subclasses() my models.py class Images(models.Model): user =…
0
votes
1 answer

DjangoRestFramework ChoiceField fails float value validation

I have a question regarding validation logic of serializers.ChoiceField. As I've seen in the code, here is to_internal_value() of ChoiceField that is used to validate client inputs: def to_internal_value(self, data): if data == '' and…
0
votes
1 answer

Access child model class attributes in multi table inheritance in Django

I'm trying to iterate over a child model instances' attributes in a template, specifically I only want to access the childs attributes. At runtime I won't know what concrete sub-class it is. Using django-model-utils I've been able to return the…
KingFu
  • 1,358
  • 5
  • 22
  • 42
1
2