-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ComputedFieldsModelMixin #82
Comments
Do you have a more detailed explanation, why it is impossible with For less intrusive 3rd party django modules, normally this should keep working: class Model(ComputedFieldsModel, ThirdPartyModelClass):
... (Note that the class inheritance order might be important, whether the cf logic should be applied before or after the 3rd party logic.) |
@stygmate Tested it with this dummy setup: # models.py
from django.db import models
from solo.models import SingletonModel
from computedfields.models import ComputedFieldsModel, computed
class Solo(SingletonModel, ComputedFieldsModel):
name = models.CharField(max_length=32)
@computed(models.CharField(max_length=32), depends=[
('children', ['name'])
])
def children_name_list(self):
return ','.join(self.children.all().values_list('name', flat=True))
class Child(ComputedFieldsModel):
name = models.CharField(max_length=32)
solo = models.ForeignKey(Solo, related_name='children', on_delete=models.CASCADE)
@computed(models.CharField(max_length=32, default=''), depends=[
('solo', ['name'])
])
def solo_name(self):
return self.solo.name
# admin.py
from django.contrib import admin
from solo.admin import SingletonModelAdmin
from .models import Solo, Child
class SoloAdmin(SingletonModelAdmin):
readonly_fields = ('children_name_list',)
list_display = ('children_name_list',)
class ChildAdmin(admin.ModelAdmin):
readonly_fields = ('solo_name',)
list_display = ('name', 'solo_name',)
admin.site.register(Solo, SoloAdmin)
admin.site.register(Child, ChildAdmin) Works in both directions ( I see that |
@closing the issue, feel free to reopen if something is still unanswered. |
Using ComputedFields with other models class like SingletonModel of Django-Solo is impossible.
Adding the declaration of a ComputedFieldsModelMixin can resolve this issue, allowing us to write:
The text was updated successfully, but these errors were encountered: