0

Using Django 1.6.5, I have a case where I want to make a particular record read-only after comparing it with some pattern in an inline formset.

Is it possible to do this?

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
user956424
  • 1,611
  • 2
  • 37
  • 67
  • 3
    Well if you could show us a little bit more about what you have done and what you are not able to do we could help you a lot more as your question is quite abstract – Thomas Gak-Deluen Apr 17 '15 at 08:52
  • 2
    possible duplicate of [In a django form, How to make a field readonly (or disabled) so that it cannot be edited?](http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b) – rnevius Apr 17 '15 at 09:06
  • Welcome to Stack Overflow, I've tried to reword your question to make it more clear what you are looking for, but it appears as though this question has already been asked before. If it wasn't already asked before, can you add some more details to your question to separate it from the existing one? – Kevin Brown-Silva Apr 21 '15 at 00:33
  • http://stackoverflow.com/users/3518452/rnevius, the difference in question is : to make a row of data readonly, and not the field readonly! Is it possible user django without using client side scripting? – user956424 Apr 21 '15 at 12:32

2 Answers2

1

You can do it using jquery. This is the way at clientside if suitable for you.

You can get value of form fields using id generated by form like(abc_1, abc_2 etc)

then you can compare it with some value and apply css ('disable',true) to specific field using id.

jatinkumar patel
  • 2,920
  • 21
  • 28
0

Yes, it is possible by using parent model form init method sample code:

class VForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(VForm, self).__init__(*args, **kwargs)

        if self.instance.field == 'Y':
            self.fields['field2'] = forms.ChoiceField(
                choices=[(self.instance.field,
                          self.instance.field),], required=True)

This will filter the choice field restricted to only 1 choice, and a blank to select from .In above case 'N' as one of the choice fields is suppressed. Same is the case for model fields also.

user956424
  • 1,611
  • 2
  • 37
  • 67