yaah, but that's the most … inconvenient. 

the data model allows for the user to customize the fields he wants to use, 
depending on his requirements. I could start small, but the problem _will_ come 
at some point, so I thought I asked beforehand. 

but thanks for the answer, I already started "small" and postponed the problem. 
we'll see when I get there ;)


greetings, 
axel.



Am 23.08.2011 um 19:22 schrieb Subhranath Chunder:

> Manipulating the form instance attributes at runtime in your view might be 
> possible by modifying some internal fields, but that leads to dirty code and 
> not-so-clean views.
> 
> You can rather use different django forms with different field definitions in 
> your view. This might be the cleanest.
> 
> You can also consider creating some generator function which can return you a 
> django form class on the fly, depending upon the form definition parameters 
> provided to the generator function during runtime. Obviously you need to be 
> careful with this, and consider the cons coming with it.
> 
> 
> On Tue, Aug 23, 2011 at 12:01 AM, Axel Bock <axel.bock.li...@googlemail.com> 
> wrote:
> Hi group,
> 
> I have another question about Django forms. I designed a Form for a Model, 
> but now I want to remove fields depending on some user settings.
> Can I do that?
> 
> Lets assume the following:
> 
> class MyModel(models.Model):
>    field1 = TextField(null=True, blank=True)
>    field2 = Textfield(null=True, blank=True)
> 
> class MyModelform(forms.Form):
>    field1 = TextField()
>    fiels2 = TextField()
> 
> def viewform(request):
>    # some magic here :)
>    return render_to_response(context_instance=RequestContext(request, 
> {'form':MyModelForm()}))
> 
> Now I want to disable field2 in the form on display, depending on the user 
> settings. Any suggestions?
> 
> Greetings & thanks,
> Axel.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> 
> -- 
> Thanks,
> Subhranath Chunder.
> www.subhranath.com
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to