Comments (5)
Which order are you using for the inheritance? You can also set the form
explicitly. The form needs to inherit the TranslatableModelForm
off course.
from django-parler.
In django-fluent-pages, the following inheritance chain is used:
class UrlNodeAdminForm(MPTTAdminForm, TranslatableModelForm):
# The form class
pass
class UrlNodeParentAdmin(TranslatableAdmin, PolymorphicMPTTParentModelAdmin):
# The polymorphic parent admin.
base_model = UrlNode
class UrlNodeChildAdmin(PolymorphicMPTTChildModelAdmin, TranslatableAdmin):
# The polymorphic child admin.
base_model = UrlNode
base_form = UrlNodeAdminForm
Just for reference:
class PolymorphicMPTTParentModelAdmin(PolymorphicParentModelAdmin, MPTTModelAdmin):
pass
class PolymorphicMPTTChildModelAdmin(PolymorphicChildModelAdmin, MPTTModelAdmin):
pass
from django-parler.
I actually don't need django-polymorphic-tree, so I just use django-polymorphic.
I've been so far already, and for existing objects this works fine. Please have a look at https://github.com/edoburu/django-parler/blob/master/docs/polymorphicmodel.rst for details on how the models are defined.
The problem arises, when I add a new product. First I have to choose between Book
or Pen
. After I filled the model specific fields for the first time, and then try to save that new object, the form is rejected telling me, that the field "Type" is mandatory and that I have to choose between Book
or Pen
, showing me the same form as at the beginning.
This is my admin.py
for testing the demo:
from django.contrib import admin
from parler.admin import TranslatableAdmin, TranslatableModelForm
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
from myapp.models.myproduct import BaseProduct, Book, Pen # from docs/polymorphicmodel.rst
class BookAdmin(TranslatableAdmin, PolymorphicChildModelAdmin):
base_form = TranslatableModelForm
base_model = BaseProduct
base_fields = ('code', 'price', 'name', 'slug')
class PenAdmin(TranslatableAdmin, PolymorphicChildModelAdmin):
base_form = TranslatableModelForm
base_model = BaseProduct
base_fields = ('code', 'price', 'identifier',)
class BaseProductAdmin(PolymorphicParentModelAdmin):
base_model = BaseProduct
child_models = ((Book, BookAdmin), (Pen, PenAdmin),)
list_display = ('code', 'price',)
admin.site.register(BaseProduct, BaseProductAdmin)
Each model admin (polymorphic, parler) by itself works fine, however combining them causes this issue. BTW, if I switch the order of inheritance, the language tabs disappear.
from django-parler.
After I filled the model specific fields for the first time, and then try to save that new object, the form is rejected telling me, that the field "Type" is mandatory and that I have to choose between Book or Pen, showing me the same form as at the beginning.
The logic for that happens in PolymorphicParentModelAdmin.add_view()
. For your own debugging, please look at that code too. First of all, which Django version are you using? Can you see whether the ct_id
GET parameter is passed to the next page?
BTW, if I switch the order of inheritance, the language tabs disappear.
That's caused by which modeladmin defines the change_form_template
. You can overwrite it yourself too if you like, and combine both templates there.
from django-parler.
Thanks for your hints, I now fixed this bug in django-polymorphic.
One question remains. I pilfered your pattern with the add_preserved_filters
. However I did not find any API docs about this in Django. Could you please point me onto some docs, where this function is described in detail.
from django-parler.
Related Issues (20)
- Django Elasticsearch DSL + Parler -> How? HOT 2
- Deleting a record - ManyToMany Field StackOverflow error
- Migrate from django-hvad
- django-hvad migration: How to modify old migrations?
- django-treebeard
- Clearing FileField don't work
- dumpdata & loaddata manage.py command with django parler HOT 1
- "wrong number of arguments for 'del' command" when deleting TranslatableModel using Redis cache
- Django Parler shows translated object one time per translation on the admin list HOT 5
- Store translated model to/from more than one database fails
- get_or_create not working HOT 2
- (Bug) `bulk_create` on TranslatableModel HOT 1
- (Bug) Redis cache "wrong number of arguments for 'del' command"
- Async and parler
- Is the package still maintained? HOT 2
- django-parler does not honor validators attribute -- validation possible at all?
- how to translate a form with parler_tags.
- django-parler with unique field raise IntegrityError
- how do I translate a easy_thumbnails.fields.ThumbnailerImageField
- Tags are not being saved when using django-taggit with django-parler.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-parler.