Sunday, April 18, 2021

Re: Mixin add field to fields in forms

Hello,

Thanks for your fast response. But i don't know how i can use  self.declared_fields and why this would help me...

Regards

shahee...@gmail.com schrieb am Sonntag, 18. April 2021 um 15:14:03 UTC+2:
Try updating self.declared_fields instead. 

On Sun, 18 Apr 2021, 13:47 sebasti...@gmail.com, <sebasti...@gmail.com> wrote:
Hello,


forms.py:

class Newsletterform(StandardMixin):
    class Meta:
        model = Newsletter
        fields = ['newslettername', 'from_link', 'to_list', 'email_subject', 'text_message', 'html_message' ]

Mixins.py:
class StandardMixin(forms.ModelForm):
    class Meta:
        abstract = True

    def __init__(self, *args, **kwargs):

        self.Meta.fields.append('owner')
        super(StandardMixin, self).__init__(*args, **kwargs)


i would append in Meta.Fields owner and after this super. But in Template this field are not shown. 

Why?

--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb10dfa0-ed1e-459c-8e06-46af264a3b7en%40googlegroups.com.

--
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f16d610f-acce-4eef-8940-8a80ff1d36a3n%40googlegroups.com.

No comments:

Post a Comment