Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-19 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+

Comment (by hadisunyoto):

 A little update:

 i tried get_fields() method and still keep del intact, it turns out to be
 an error

 KeyError at /admin/thicknesses/thickness/0.55/
 'value'

 {{{

 21.def __init__(self, *args, **kwargs):
 22.super(ThicknessForm, self).__init__(*args, **kwargs)
 23.instance = getattr(self, 'instance', None)
 24.
 25.# edit
 26.if instance and instance.pk:
 27.del self.fields['value'] <--
 28.
 29.class Meta:

 }}}

 occur in line 27

 i guess i have to forget about the form and put everything in admin then.
 What worries me is there will be several models that requires the clean()
 method in form to check related fields, that means that i have two places
 (form and admin) that handles the form, and i don't think that's a good
 approach

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.358b696f4aec56c58b9f5787d39e2e41%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-19 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+

Comment (by hadisunyoto):

 thank you for your quick response, in the mean time, i will try your
 suggestion

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.4994db1f4e85c66b790e0a78d73e9a62%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-18 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+

Comment (by timgraham):

 You should be able to keep the `del` logic, as long as you also use
 `get_fields()`.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.7a34b5739d4edbeebde9c1a4bf3af6a9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-17 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+

Comment (by hadisunyoto):

 I am aware of such methods, what i was trying to do is to push as much
 form control in modelform instead of in the admin. So next time when i
 have time i can build my own admin and reuse modelform without modifying
 the code again

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.81ea33c005eeae82cd2244bdb872a845%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-17 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by timgraham):

 * stage:  Unreviewed => Accepted


Comment:

 I looked into this and I believe you can fix this by using
 
[https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_fields
 ModelAdmin.get_fields()] to exclude the field. It might be easiest to
 simply document that you should use that method and not the `del`
 approach.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.6cba3d2a9ceeeb72b431ea43a5db353d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-17 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+--
 Reporter:  hadisunyoto|Owner:  nobody
 Type:  Bug|   Status:  new
Component:  contrib.admin  |  Version:  1.7
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Unreviewed
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+--
Changes (by hadisunyoto):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> model:
> {{{
> class Thickness(models.Model):
> value = models.DecimalField(primary_key=True, max_digits=7,
> decimal_places=2)
> is_active = models.BooleanField()
> }}}
> model form:
> {{{
> class ThicknessForm(forms.ModelForm):
> def __init__(self, *args, **kwargs):
> super(ThicknessForm, self).__init__(*args, **kwargs)
> instance = getattr(self, 'instance', None)
>
> # edit
> if instance and instance.pk:
> del self.fields['value']
> else:
> del self.fields['is_active']
>
> class Meta:
> model = Thickness
> fields = '__all__'
> }}}
>
> admin:
> {{{
> class ThicknessAdmin(admin.ModelAdmin):
> list_display = ('value', 'is_active')
> form = ThicknessForm
>
> admin.site.register(Thickness, ThicknessAdmin)
> }}}
>
> refresh page, go to admin->Thickness, create one:
>
> KeyError at /admin/thicknesses/thickness/add/
> "Key 'is_active' not found in 'ThicknessForm'"
> ...
>
> Error during template rendering
>
> In template D:\env\lib\site-
> packages\django\contrib\admin\templates\admin\includes\fieldset.html,
> error at line 7
>
> The highlighted line is number 7
>
> 6{% for line in fieldset %}
> 7
> 8{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif
> %}
>
> go to admin->Thickness again, modify one (without using model form):
> KeyError at /admin/thicknesses/thickness/0.55/
> "Key 'value' not found in 'ThicknessForm'"
> ...
>
> same error as above
>
> Without admin, model form works as expected, it remove is_active when
> create, and it remove value when edit

New description:

 model:
 {{{
 class Thickness(models.Model):
 value = models.DecimalField(primary_key=True, max_digits=7,
 decimal_places=2)
 is_active = models.BooleanField()
 }}}
 model form:
 {{{
 class ThicknessForm(forms.ModelForm):
 def __init__(self, *args, **kwargs):
 super(ThicknessForm, self).__init__(*args, **kwargs)
 instance = getattr(self, 'instance', None)

 # edit
 if instance and instance.pk:
 del self.fields['value']
 else:
 del self.fields['is_active']

 class Meta:
 model = Thickness
 fields = '__all__'
 }}}

 admin:
 {{{
 class ThicknessAdmin(admin.ModelAdmin):
 list_display = ('value', 'is_active')
 form = ThicknessForm

 admin.site.register(Thickness, ThicknessAdmin)
 }}}

 refresh page, go to admin->Thickness, create one:

 KeyError at /admin/thicknesses/thickness/add/
 "Key 'is_active' not found in 'ThicknessForm'"
 ...

 Error during template rendering

 In template D:\env\lib\site-
 packages\django\contrib\admin\templates\admin\includes\fieldset.html,
 error at line 7

 The highlighted line is number 7

 6{% for line in fieldset %}
 7
 8{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif
 %}

 go to admin->Thickness again, modify one (created previously without using
 model form):
 KeyError at /admin/thicknesses/thickness/0.55/
 "Key 'value' not found in 'ThicknessForm'"
 ...

 same error as above

 Without admin, model form works as expected, it remove is_active when
 create, and it remove value when edit

--

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.10cbfb928ae43f6f0350aa532902f87c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #23501: remove/add fields programatically in modelform fails in admin

2014-09-16 Thread Django
#23501: remove/add fields programatically in modelform fails in admin
---+
 Reporter:  hadisunyoto|  Owner:  nobody
 Type:  Bug| Status:  new
Component:  contrib.admin  |Version:  1.7
 Severity:  Normal |   Keywords:
 Triage Stage:  Unreviewed |  Has patch:  0
Easy pickings:  0  |  UI/UX:  0
---+
 model:
 {{{
 class Thickness(models.Model):
 value = models.DecimalField(primary_key=True, max_digits=7,
 decimal_places=2)
 is_active = models.BooleanField()
 }}}
 model form:
 {{{
 class ThicknessForm(forms.ModelForm):
 def __init__(self, *args, **kwargs):
 super(ThicknessForm, self).__init__(*args, **kwargs)
 instance = getattr(self, 'instance', None)

 # edit
 if instance and instance.pk:
 del self.fields['value']
 else:
 del self.fields['is_active']

 class Meta:
 model = Thickness
 fields = '__all__'
 }}}

 admin:
 {{{
 class ThicknessAdmin(admin.ModelAdmin):
 list_display = ('value', 'is_active')
 form = ThicknessForm

 admin.site.register(Thickness, ThicknessAdmin)
 }}}

 refresh page, go to admin->Thickness, create one:

 KeyError at /admin/thicknesses/thickness/add/
 "Key 'is_active' not found in 'ThicknessForm'"
 ...

 Error during template rendering

 In template D:\env\lib\site-
 packages\django\contrib\admin\templates\admin\includes\fieldset.html,
 error at line 7

 The highlighted line is number 7

 6{% for line in fieldset %}
 7
 8{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif
 %}

 go to admin->Thickness again, modify one (without using model form):
 KeyError at /admin/thicknesses/thickness/0.55/
 "Key 'value' not found in 'ThicknessForm'"
 ...

 same error as above

 Without admin, model form works as expected, it remove is_active when
 create, and it remove value when edit

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.fd1b0d315fa9ff9aa3e0529dc43ac1cc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.