There is actually a workflow that feels inconsistent if we cannot easily 
enforce validate_min & _max on the Formset of the contrib.Admin.
Example:
a) For model A, attach an Inline for model B (B having a ForeingKey to A), 
with min_num < max_num
b) create an instance of A in the Admin interface: you will need to create 
between min_num and max_num B instance in the formset (because min_num and 
max_num are checked on creation)
c) edit the inserted A instance, you can delete as many B attached to it as 
you want, *allowing to save the result with number of B < min_num* (<- this 
is what validate_min would prevent)
d) now if you open the modified A instance for edition, you cannot save it 
anymore *even if you do not change anything* (because you have less B than 
min_num)


Le mercredi 12 août 2015 12:01:03 UTC+2, [email protected] a écrit :
>
> Hi,
>
>  I would need to enforce the max_num and min_num  attributes of formsets 
> on my admin pages at validation time.
> From the documentation and the source, it seems that validate_max and 
> validate_min would be the FormSet attributes that need to set to True for 
> that to happen.
>
> Yet, while investigating this issue, it seems to me that it is currently 
> not possible to forward them to FromSet classes used in the Admin site:
> 1) From InlineModelAdmin.get_formset() code 
> <https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1810-L1819>,
>  
> it is not useful to set validate_* on the inline itself, as it would not be 
> forwarded to the inlineformset_factory() call on return.
> 2) From formset_factory() code 
> <https://docs.djangoproject.com/en/1.8/_modules/django/forms/formsets/#formset_factory>,
>  
> it is not useful to set validate_* on the FormSet class itself, because it 
> would be overwritten by the argument provided to the factory function.
>
> Are you aware of a way to have the Admin instantiate FormSet classes with 
> valide_min and validate_max set to true ?
> If not, it seems to me it would be easy to allow it by extending the 
> defaults dictionary in 1), so I am curious if there is a rationale for not 
> allowing it, or if it is a simple oversight ?
>
> Thank you very much for reading,
>   Ad
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9af8e744-1f38-4a20-a8a3-a654d882b7d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to