Re: How to create a Generic Show View ?

2008-08-27 Thread Mario Hozano
Hi Koen,

I think your code snippet will work fine in my application too. But, how
instantiate the DisplayModelForm directly in my urls.py showed below?

(r'^core/user/show/(?P\d+)/$', 'object_detail',
dict(queryset=User.objects.all(),

template_name="baseshow.html",

extra_context={'model_entity':'user'}))

Should I use the 'django.views.generic.create_update.create_object' view? I
want only to use the urls.py without write in views.py to instantiate the
form.

Is it possible?

Thanks.
Mario Hozano.


On Wed, Aug 27, 2008 at 3:34 AM, koenb <[EMAIL PROTECTED]> wrote:

>
> Hi Mario,
>
> a few months ago I posted a snippet on djangosnippets [1] that kind of
> does something like this: it takes a form (can be the same one you use
> for editing) and displays it as read-only. The disadvantage is it uses
> the entire form machinery just to display some values, which is a lot
> of overhead, the advantage is I have quick and dirty display of data
> without much extra work (I have my own generic view wrapped around
> this).
> It needs a lot of improvement, but it works ok for me for now.
>
> Koen
>
> [1]: http://www.djangosnippets.org/snippets/758/
>
> On 26 aug, 20:00, Mario Hozano <[EMAIL PROTECTED]> wrote:
> > Hi People.
> >
> > I am new in Django and I am using the django support to create generic
> > views (CRUD) in my app. To handle Create and Show actions, i have
> > written 2 main pages with the code snippets described below.
> >
> > baseform.html
> > {% for field in form %}
> > {{ field.label_tag }}{% if field.field.required %}*{%
> endif
> > %}
> > {{ field }}
> > {% if field.help_text %}{{ field.help_text }}{%
> endif %}
> > {% if field.errors %}{{ field.errors
> }} > dd>{% endif %}
> > {% endfor %}
> >
> > baseshow.html.
> > {% for key, value in object.as_dict.items %}
> > {{ key.capitalize }}
> > {{ value }}
> > {% endfor %}
> >
> > These pages are called directly from my urls.py that uses the Generic
> > views supported by django. In this sense, the baseform.html can be
> > used by all model classes, because the ModelForm handles the
> > presentation of each model attribute (excluding id) transparently.
> >
> > In baseshow.html I need to show the same attributes of a given model
> > class, as done in baseform.html. In this case, the attributes
> > (excluding id) must be presented in a read-only mode, with html labels
> > instead of input widgets. To do it, i've implemented a "as_dict"
> > method in each model class. This method only returns the
> > "self.__dict__" attribute of the model classes, hence, the private
> > attributes cannot be acessed from templates.
> >
> > The solution presented works, but it is ugly, because the id attribute
> > must be verified on template and it needs to adjust the model class to
> > work fine.
> >
> > Does Django offer another way to present the model attributes in a
> > Show view? Is it possible to use a ModelForm class to show the
> > attribute values in html labels?
> >
> > Thanks.
> > Mario Hozano
> >
>


-- 
Mário Hozano Lucas de Souza
Embedded and Pervasive Computing Laboratory - embedded.ufcg.edu.br
Electrical Engineering and Informatics Center - CEEI
Federal University of Campina Grande - UFCG - www.ufcg.edu.br
PGP: 0xAEA0ACBD

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to show a model count value in a html page?

2008-08-26 Thread Mario Hozano
Good, Rajesh.

I will do it.

Thanks.

Mario Hozano

On Tue, Aug 26, 2008 at 5:38 PM, Rajesh Dhawan <[EMAIL PROTECTED]>wrote:

>
> Hi Mario,
>
> > I am new in Django. I am implementing a web application using the
> > django template support. In this way, i am using a single 2-columns
> > template. While the second column changes according to the presented
> > content, the first column shows the menu and some statistical
> > information for all pages. This information must indicate the number
> > of entities of the model, for example the number of registered users.
> >
> > I want to know how show the number of registered users in that page.
> > Do I need to retrieve this value to each action described in views.py?
> > The code presented below does not work.
> >
> > Statistics
> > 
> > Users({{User.objects.count}})
> > ...
> > 
>
> You could create a custom template tag that renders these statistics
> for you. See:
>
>
> http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags
>
> You can then embed this tag in templates where you want to display
> that info. For added measure, you can add some caching when/if these
> repetitive DB calls start hurting application performance:
> http://www.djangoproject.com/documentation/cache/
>
> -Rajesh D
>
> >
>


-- 
Mário Hozano Lucas de Souza
Embedded and Pervasive Computing Laboratory - embedded.ufcg.edu.br
Electrical Engineering and Informatics Center - CEEI
Federal University of Campina Grande - UFCG - www.ufcg.edu.br
PGP: 0xAEA0ACBD

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to show a model count value in a html page?

2008-08-26 Thread Mario Hozano

Hi People.

I am new in Django. I am implementing a web application using the
django template support. In this way, i am using a single 2-columns
template. While the second column changes according to the presented
content, the first column shows the menu and some statistical
information for all pages. This information must indicate the number
of entities of the model, for example the number of registered users.

I want to know how show the number of registered users in that page.
Do I need to retrieve this value to each action described in views.py?
The code presented below does not work.

Statistics

Users({{User.objects.count}})
...


Regards.
Mario Hozano.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to create a Generic Show View ?

2008-08-26 Thread Mario Hozano

Hi People.

I am new in Django and I am using the django support to create generic
views (CRUD) in my app. To handle Create and Show actions, i have
written 2 main pages with the code snippets described below.

baseform.html
{% for field in form %}
{{ field.label_tag }}{% if field.field.required %}*{% endif
%}
{{ field }}
{% if field.help_text %}{{ field.help_text }}{% endif %}
{% if field.errors %}{{ field.errors }}{% endif %}
{% endfor %}

baseshow.html.
{% for key, value in object.as_dict.items %}
{{ key.capitalize }}
{{ value }}
{% endfor %}

These pages are called directly from my urls.py that uses the Generic
views supported by django. In this sense, the baseform.html can be
used by all model classes, because the ModelForm handles the
presentation of each model attribute (excluding id) transparently.

In baseshow.html I need to show the same attributes of a given model
class, as done in baseform.html. In this case, the attributes
(excluding id) must be presented in a read-only mode, with html labels
instead of input widgets. To do it, i've implemented a "as_dict"
method in each model class. This method only returns the
"self.__dict__" attribute of the model classes, hence, the private
attributes cannot be acessed from templates.

The solution presented works, but it is ugly, because the id attribute
must be verified on template and it needs to adjust the model class to
work fine.

Does Django offer another way to present the model attributes in a
Show view? Is it possible to use a ModelForm class to show the
attribute values in html labels?

Thanks.
Mario Hozano

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---