Apologies, I updated it.

class MyModelAdmin(ModelAdmin):
    model = MyModel
    form = MyForm
 
    def get_form(self, request, obj=None, **kwargs):
        form_class = super(MyModelAdmin, self).get_form(request, obj=obj, 
**kwargs)
 
        some_parameter_for_one_thing = 
self.get_some_parameter_for_one_thing()
 
        from django.forms.models import ModelFormMetaclass
        class FormMetaclass(ModelFormMetaclass):
            def __new__(mcs, name, bases, attrs):
                attrs["some_parameter_for_one_thing"] = 
some_parameter_for_one_thing
                return super(FormMetaclass, mcs).__new__(mcs, name, bases, 
attrs)
 
        another_parameter_for_another_thing= 
obj.another_parameter_for_another_thing
 
        import six
        class FormWrapper(six.with_metaclass(FormMetaclass, form_class)):
            def __init__(self, *args, **kwargs):
                data = {"another_parameter_for_another_thing": 
six.text_type(another_parameter_for_another_thing)}
                super(FormWrapper, self).__init__(data, *args, **kwargs)
 
        return FormWrapper

On Friday, September 16, 2016 at 1:46:32 AM UTC-7, Andrea D'Amore wrote:
>
> On 16 September 2016 at 00:53,  <[email protected] <javascript:>> 
> wrote: 
> > I have a ModelAdmin subclass (code at: <https://dpaste.de/0LAt>) 
>
> Gives a 404: 
>
>     The requested URL /0LAt was not found on this server. 
>
>
> I'm missing the rationale of using an external paste service while 
> you're already using a text-based medium, the mailing list, that's 
> able to accomodate what's (hopefully) a small code excerpt, in worst 
> case scenario I think it'll accept an attachment as well. 
>
> This also has the added bonus of getting archived and never result in 
> broken links and missing content, like it's likely to happen at some 
> point with external services. 
>
>
> -- 
> Andrea 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9481df50-3280-4b9d-87c2-080e632a4cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to