Thanks for your response. Currently I am dealing with a form with
individual field permissions. I guess it explains it gets difficult with
Django Form, which are made for only editing. I know a custom read-only
field can be created in the code below. I am still struggling with post
the form with labels not fields. As I newcomer to Django, it's very
convenient to have these capabilities on a regular with simple form
permissions. But once it gets bit more complicated in security, Form object
is not very helpful or i maybe am missing a point.
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.forms.util import flatatt
class ReadOnlyWidget(forms.Widget):
def render(self, name, value, attrs):
final_attrs = self.build_attrs(attrs, name=name)
if hasattr(self, 'initial'):
value = self.initial
return mark_safe("<p %s>%s</p>" % (flatatt(final_attrs),
escape(value) or ''))
def _has_changed(self, initial, data):
return False
class ReadOnlyField(forms.Field):
widget = ReadOnlyWidget
def __init__(self, widget=None, label=None, initial=None,
help_text=None):
super(type(self), self).__init__(self, label=label,
initial=initial,
help_text=help_text, widget=widget)
self.widget.initial = initial
def clean(self, value):
return self.widget.initial
On Saturday, March 19, 2016 at 9:24:57 AM UTC-4, bobhaugen wrote:
>
> Questions interspersed below:
>
> On Friday, March 18, 2016 at 11:38:59 AM UTC-5, Gorkem Tolan wrote:
>>
>> I am a new comer to Django. Last four weeks I have been working on web
>> application purely created with Django framework.
>> I realized that Django forms are very cumbersome to use.
>>
>
> What is cumbersome about them? Can you post some of your form code that
> you find cumbersome? Maybe you are doing something that is more complicated
> than it needs to be.
>
> My experience with Django forms is that they get something up and running
> very quickly and very easily and run into problems when I try to do
> something more complicated. And then the main problem for me is if I have a
> lot of forms on the same page: the page starts to render very slowly. But
> the code is still fairly simple.
>
>
>> I'd rather have DRF (rest framework) and just angularjs form. I am sure
>> alot users will bombard me tons of oppositions.
>>
>
> DRF is awesome! If you are more familiar with Angular than Django, it
> might be a good way for you to go.
>
--
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/7646b734-e313-448e-8256-d779688dd190%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.