Skip to content

Conversation

@vinnyrose
Copy link
Contributor

Expanding on the already present can_have_children so that it can also be
a list in addition to booleans. (Empty list == False, Non-empty == True)

The list is list of values similar to those values accepted in a model
ForeignKey. If it is a list it is changed into a list of the content
type ids of the listed models.

i.e. ["self", "app.Model", "Model", Model]
With "self" referring to the model on which can_have_children is defined.
"app.Model" is an app_label-model dot string.
"Model" is a model in the current app.
And the last is a Model class or Model instance.

Expanding on the already present can_have_children so that it can also be a list in addition to booleans. (Empty list == False, Non-empty == True) The list is list of values similar to those values accepted in a model ForeignKey. If it is a list it is changed into a list of the content type ids of the listed models. i.e. ["self", "app.Model", "Model", Model] With "self" referring to the model on which can_have_children is defined. "app.Model" is an app_label-model dot string. "Model" is a model in the current app. And the last is a Model class or Model instance.
vinnyrose added a commit to vinnyrose/django-fluent-pages that referenced this pull request Oct 10, 2014
Based on django-polymorphic/django-polymorphic-tree#24 Probably needs django-polymorphic >= 0.6 due to it's use of get_child_type_choices(self, request, action). Fixes django-fluent#31
vinnyrose added a commit to vinnyrose/django-fluent-pages that referenced this pull request Oct 10, 2014
Based on django-polymorphic/django-polymorphic-tree#24 Probably needs django-polymorphic >= 0.6 due to its use of get_child_type_choices(self, request, action). Fixes django-fluent#31
@meshy
Copy link
Contributor

meshy commented Oct 10, 2014

Rather than check a list, would it be possible to use a method to check this instead of it having to be a list of classes? I have a case on the roadmap for my personal project that requires me to limit the children by a property of my polymorphic type, and a method would be more generic.

@meshy
Copy link
Contributor

meshy commented Oct 10, 2014

If can_have_children continues to be a boolean, it could be overridden with property at the moment. I suppose that that would allow it to be a method.

@meshy
Copy link
Contributor

meshy commented Oct 10, 2014

(Please excuse me if I am way off the mark here, I'm not very familiar with the code of this project yet.)

@vinnyrose
Copy link
Contributor Author

You can have a boolean or a list it works either way.

@meshy
Copy link
Contributor

meshy commented Oct 13, 2014

it works either way

Ok, great. Sorry for butting in!

Thank you for considering my use-case in bd1758b :)

@vdboor
Copy link
Member

vdboor commented Dec 30, 2014

Hi! sorry for not noticing this PR before.
Great to see you've made it to a pull-request for this type of functionality.

I'd strongly prefer a solution where can_have_children stays a bool, and a new property is added, e.g. child_types = [...]. This avoids the type checking/flipping which simplifies the code and API a lot.

@vinnyrose vinnyrose closed this Dec 30, 2014
@vinnyrose vinnyrose deleted the restrict_children branch November 21, 2018 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants