idlesign/django-sitetree

Can't add root items in Admin with current github version

gb119 opened this issue · 8 comments

gb119 commented

In django 1.10 and current github master version (as of 15th August 2016), I'm getting validation errors on the parent field when I try to add or edit root items (i.e. things with no parent). Seems Admin wants me to select a value for parent.... since loading and dumping data seem to work ok, I'm guessing this is a form validation error, but I'm not sufficiently expert to know where to look next...

gb119 commented

Ok, I have a fix. The problem appears to be in the javascript validation in admin (or possibly django-suit) - it's not liking a choiuce field with a value of ''. In sitetree/fields.py TreeItemChoiceField, I give the root item a value of "-1" (line 52) and then change the test in the clean method to be not value or int(value)<0

and it starts worming again.

There's probably a more elegant way and sorry for the lack of PR.....:-)

Thank you for the report, I'll check that at weekends.

Can't reproduce using master on 1.10: successfully added a couple of root tree items in Admin contrib without any validation error. Am I missing some steps to reproduce?
Please verify that it's not django-suit to blame.

gb119 commented

Hi, Sorry been on vacation so couldn't look into this any last week. I've now pinned it down to an incompatibility between sitetree and django-suit which is doing some client side validation of select fields that doesn't like an empty value. Not sure which project should give way here (and I'm just the poor user trying to make both packages play nicely). Changing the return value for the root item in fields.py as outlined above fixes the problem with no loss of functionality to sitetree, but I'd understand a reluctance to make changes due to another project's choices on validation.

So, it's suit's client side validation.
I'll relabel this issue and introduce another sitetree setting, so you can set any value you consider fit.

Added ITEMS_FIELD_ROOT_ID settings in feat/items_field_root_id branch (https://github.com/idlesign/django-sitetree/tree/feat/items_field_root_id).
You can check that branch out, adjust the setting and try to add an item.

gb119 commented

Works beautifully ! Thanks, look forward to it being in a future release and meanwhile pip installing from github branches is nice and easy).

Considered closed.
Feel free to reopen if required.