How do I create a read only datatime field with a custom admin?


Here is the psudo code from what I've done:

-------------------------------------

class myAdminForm(forms.ModelForm):

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

           super(myAdminForm, self).__init__(*args, **kwargs)

            ...

self.fields['Created_date'].widget.attrs['readonly'] = 'readonly'

            ...

class myAdmin(admin.ModelAdmin):

    ...

    change_form_template= 'my_change_form_admin.html'

    form = myAdminForm

    ...

    #readonly_fields = ['Created_date', 'Modified_date']

usrAdminSite.register(myMdl, myAdmin)

-------------------------------------


For 'my_change_form_admin.html' I've started with the admins 'change_form.html' and tweaked it. Since I want to access the individual fields I've removed:

---------------------

{% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" %}
{% endfor %}

----------------------

and replaced it with code like 'adminform.form.Created_date'.


This worked fine till I tried to give 'Created_date' a read only attribute. In myAdmin if I add <readonly_fields = ['Created_date',]> then 'adminform.form.Created_date' no longer exists.


Next in 'myAdminForm' I added <self.fields['Created_date'].widget.attrs['readonly'] = 'readonly'> but this seems to be ignored. I also tried <self.fields['Created_date'].widget.attrs['readonly'] = True> with the same effect.



How should I create a read only datatime field?  I'm using Django 1.3.


Brian

--
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