Re: Searching IntegerField

2009-07-01 Thread Marcelo Ramos

On Wed, Jul 1, 2009 at 2:29 AM, Harish<harish.bha...@gmail.com> wrote:
>
> hi friends,
>    I designed a model in django, which has a Integer field. When I
> include the integer field in the search_list, the searching is not
> working. I am using django 0.97 (when I gave 'django.VERSION' in
> python interpreter it gave me (0, 97, 'pre') ).
>
> the code is as follows
>
> class Person(models.Model):
>     name=models.CharField('Name',max_length=20)
>     rollNo=models.IntegerField('Roll No', maxloength=12)
>
>     def __unicode__(self):
>            return self.name
>
>     class Admin:
>         list_display=('name','rollNo')
>         search_field=['name','rollNo']

The keyword name is "search_fields" and you are using "search_field".

-- 
Marcelo Ramos
Django/Python developer

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



Re: How to deal with problem about ForeignKey

2009-04-29 Thread Marcelo Ramos

On Wed, Apr 29, 2009 at 2:57 AM, Vincent <pho...@gmail.com> wrote:
> Hi,
> I got a problem like this:
> class A(models.Model):
>     id = models.AutoField(primary_key=True)
>     field1 = models.TextField()
> class B(models.Model):
>     a = models.ForeignKey(A)
>     field1 = models.TextField()
> then there are some records of A/B,
> how can i delete records of A and do not delete records of B which have
> foreignkey on A

Did you mean how to delete records of A for which there are no records
in B pointing to them through the foreign key "a", right?

-- 
Marcelo Ramos
Django/Python developer

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



Re: Template within a Template

2009-04-27 Thread Marcelo Ramos

On Mon, Apr 27, 2009 at 9:12 PM, Renato Untalan <phis...@gmail.com> wrote:
>
> Hey guys,
>
> In my current project, I'm making a soap call to a remote server,
> which will return to me a Django template.
> Once I have the Django template, I insert it into my Context object,
> and when it renders, it renders the template in plain text, and does
> not show any of the HTML tags.
>
> My context object's dictionary:
> myVars = { "custom_settings_template" : connector_template }
>
> My template:
>
> 
> {{ connector_template }}

I think you need the "safe" template filter there [1]:

{{ connector_template|safe }}

Beware of the html you are injecting from the soap call, the safe
filter will let it pass unmodified. Maybe you can chain "safe" with
the filter "removetags" [2] to get rid of potentially dangerous html
tags.

[1] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe
[2] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#removetags

Regards.

-- 
Marcelo Ramos
Django/Python developer

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



Re: Query subset

2008-10-31 Thread Marcelo Ramos

On Fri, Oct 31, 2008 at 5:08 AM, Tonne <[EMAIL PROTECTED]> wrote:
>
> So, what I've done is use Model.objects.values() to limit the returned
> values, which is not ideal as I'm losing the objectness of the
> queryset.
>
> I've worked around the loss Queryset.get_absolute_url by using a less
> than elegant semi-hardcoded url.
>
> So if I'm missing a blindingly obvious way of limiting a query to
> nominated fields so that I can still keep the benefits of a queryset,
> please let me know.

You are right about not having the full functionality of the objects
and I don't know
about a way to keep it while restricting the fields retrieved by the query.

> Also, is using Model.objects.values() to limit the fields returned
> actually more efficient than Model.objects.all() in terms of database
> hits?

Not in terms of database hits, but yes in terms of the "size" of the
retrieved data. If you are avoiding
a lot of fields the difference in traffic size from the database can be big.

Regards.

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: fetching images from database

2008-10-31 Thread Marcelo Ramos

On Fri, Oct 31, 2008 at 4:06 AM, please smile <[EMAIL PROTECTED]> wrote:
> Hi All,
>
>   I have uploaded some images in a folder and also saved  the image name
> into  data base table.
> Now I need to fetch and display all the images to my client side web page .
> How can I do this .Please help.
> Thanks

If you use an ImageField to store the images then you can easily show them with
the url() method of each image object in your templates.

Look at http://docs.djangoproject.com/en/dev/ref/models/fields/#imagefield and
http://docs.djangoproject.com/en/dev/topics/files/#using-files-in-models
for more info.

Regards.

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: Query subset

2008-10-31 Thread Marcelo Ramos

On Fri, Oct 31, 2008 at 4:37 AM, Tonne <[EMAIL PROTECTED]> wrote:
>
> I have spent hours looking in the docs and one this list for an answer
> to this problem:
>
> I have a model that has, for example, 20 fields.
>
> On my site's homepage, where I'd like to offer a preview version of
> the object, I'd need to retrieve only say, half of those fields to be
> displayed.
>
> My dilemma is whether to simply use a Model.objects.all() query and
> ignore the unnecessary data in the template, or find a more efficient
> way to call only the data I need.
>
> Perhaps my model design is flawed and I should separate out the data
> that is not common to the list and detail version of the content, or
> perhaps I should have a model method that returns only the data fields
> I need, etc.

There is nothing wrong with having a model with 20 fields if you keep
the DRY (Don't Repeat Yourself) principle.
I mean, if you are not sharing a subset of those fields with another
model then it is ok.

I think you need the values() method. It receives the fields you want
to get as positional parameters (restricting
the select sql query only to those fields).

You can read the docs
http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields
for further information.

Regards.

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: Making sure published date is respected in views

2008-09-12 Thread Marcelo Ramos

2008/9/12 Dana <[EMAIL PROTECTED]>:
>
> Hey all,
>
> Wondering what the best technique would be to make sure that an entry
> (such as a blog entry/story/etc...) with a datetime object 'pub_date'
> does not show up on the front end if the pub_date is in the future. I
> would assume using ".filter(...something...)" is the way to go but
> what would be the best filter to apply? Any other ways to achieve
> this?

Yes, a filter is a good option. For example:

from datetime import datetime

.objects.filter(pub_date__lte=datetime.now())

Regards.

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: Using unique on a field

2008-09-11 Thread Marcelo Ramos

2008/9/11 Chris Stromberger <[EMAIL PROTECTED]>:
> Curious about using "unique" in a column definition of a model for a legacy
> db.  My assumption is that "unique" only comes into play during db creation,
> to create the index on the field, and thereafter uniqueness is enforced by
> the db?  Or does unique in a model affect creation of new model objects or
> anything else?
>
> Just wondering bcs I made a few columns unique on the db after the initial
> model creation.  Is it important to go back and add unique to the Django
> model in this case?

You can read in the documentation of the unique field option[1]:

"This is enforced at the database level and at the Django admin-form
level. If you try to save a model with a duplicate value in a unique
field, a django.db.IntegrityError will be raised by the model's save()
method."

About a legacy db where you put a unique constraint manually it is
recommended to put the option unique to the field so you get
a nice error in the Django forms  instead of an error screen.

Regards.

[1] http://docs.djangoproject.com/en/dev/ref/models/fields/#unique

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: Timeout for URLField?

2008-06-29 Thread Marcelo Ramos
2008/6/26 jabbercat <[EMAIL PROTECTED]>:

>
> Hello,
>
> does somebody know if there is a possibility to specify a timeout for
> the URLField? I'm just using a URLField, but if the URL is not correct
> the URLField needs a lot of time to response with an error.
>
>
No. Django's builtin validators has two results: validated or not. If you
put a timeout then you are not validating, you are "trying"  to validate
which is a completely different thing :-)

Why are you putting a validator if you allow it to be overriden. Just use a
CharField in that case.

Regards.

-- 
Marcelo Ramos

--~--~-~--~~~---~--~~
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: create_object error

2007-04-05 Thread Marcelo Ramos

2007/4/5, Michael Radziej <[EMAIL PROTECTED]>:
>
> On Thu, Apr 05, Marcelo Ramos wrote:
>
> > es_AR:
> >
> > #: views/generic/create_update.py:43
> > #, python-format
> > msgid "The %(verbose_name)s was created successfully."
> > msgstr "Se creó con éxito %(verbose_name)."
>   
> this should be
>
>   msgstr "Se creó con éxito %(verbose_name)s."
>
> (note the 's' before '.')

Right! I fixed that in django.po and the problem is gone!
I will contact the es_AR translation mantainer about this.

Thanks very much Michael.

Regards.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

--~--~-~--~~~---~--~~
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: create_object error

2007-04-05 Thread Marcelo Ramos

2007/4/5, Malcolm Tredinnick <[EMAIL PROTECTED]>:
[...]
> In [1]: from django.utils.translation import activate, gettext
>
> In [2]: gettext("The %(verbose_name)s was created successfully.") % 
> {"verbose_name": "xyzzy"}
> Out[2]: 'The xyzzy was created successfully.'
>
> In [3]: activate('es')
>
> In [4]: gettext("The %(verbose_name)s was created successfully.") % 
> {"verbose_name": "xyzzy"}
> Out[4]: 'El xyzzy se ha creado correctamente.'
>
> In [5]: activate('de')
> In [6]: gettext("The %(verbose_name)s was created successfully.") % 
> {"verbose_name": "xyzzy"}
> Out[6]: 'xyzzy wurde erfolgreich angelegt.'
>
> In particular, what happens when you use activate() for your preferred
> locale and then run the gettext() test?

I found it works with the locale "es" but not with the "es_AR".
The only difference i find about that specific translation in the
.po's is that es_AR has accented characters and es has not:

es:

#: views/generic/create_update.py:43
#, python-format
msgid "The %(verbose_name)s was created successfully."
msgstr "El %(verbose_name)s se ha creado correctamente."

es_AR:

#: views/generic/create_update.py:43
#, python-format
msgid "The %(verbose_name)s was created successfully."
msgstr "Se creó con éxito %(verbose_name)."

When I changed LANGUAGE_CODE to es instead of es_AR it worked fine but
es_AR will probably fail if i use create_update.update_object()
because the translation for a successfull update has accented
characters.

Are the accented chars the problem?
Maybe it is related with the problem reported in the email with
Subject: svn trunk broken since [4919], encoding problems.

Regards.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

--~--~-~--~~~---~--~~
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: create_object error

2007-04-04 Thread Marcelo Ramos

2007/4/4, Malcolm Tredinnick <[EMAIL PROTECTED]>:
>
> Hi Marcelo,
>
> On Wed, 2007-04-04 at 17:46 -0300, Marcelo Ramos wrote:
> > After submitting a form using a generic view I get this error:
> >
> > Request Method:   POST
> > [...]
> > Exception Type:   ValueError
> > Exception Value:  incomplete format
> > Exception Location:
> >   /usr/lib/python2.3/site-packages/django/views/generic/create_update.py
> > in create_object, line 43
> >
> > It seems an error with the format given to gettext():
> >
> > request.user.message_set.create(message=gettext("The %(verbose_name)s
> > was created successfully.") % {"verbose_name":
> > model._meta.verbose_name})
> >
> > Is that a bug or a feature? I checked that model._meta.verbose_name
> > has the correct value then i'm a bit lost here.
>
> Me, too. That looks unexpected. I've been trying to iron out a few i18n
> problems during the last few days, so it's possible that either (a) I've
> introduced a new bug or (b) fixing an older problem has exposed this.

Well, it seems to be just a syntax error:

request.user.message_set.create(message=gettext("The %(verbose_name)s
was created successfully." % {"verbose_name":
model._meta.verbose_name}))

Remove the ) after successfully." and add it in the end of the line.

Isn't the correct syntax
gettext(".. %(foo) .." % {'foo': 'bar'} )) instead of
gettext(".. %(foo) ..") % {'foo': 'bar'} ) ?

But another problem remains: the string is not being translated here.

If you need any help or feedback i'm here to help.

Regards.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

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



create_object error

2007-04-04 Thread Marcelo Ramos

After submitting a form using a generic view I get this error:

Request Method: POST
[...]
Exception Type: ValueError
Exception Value:incomplete format
Exception Location:
/usr/lib/python2.3/site-packages/django/views/generic/create_update.py
in create_object, line 43

It seems an error with the format given to gettext():

request.user.message_set.create(message=gettext("The %(verbose_name)s
was created successfully.") % {"verbose_name":
model._meta.verbose_name})

Is that a bug or a feature? I checked that model._meta.verbose_name
has the correct value then i'm a bit lost here.

I'm working with a svn copy of revision 4926 (today).

Thanks in advance.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

--~--~-~--~~~---~--~~
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: using Order-by with dynamic attribute

2007-03-28 Thread Marcelo Ramos

2007/3/28, Merric Mercer <[EMAIL PROTECTED]>:
>
> I am currently creating a query set of a Model.  I'm then iterating
> through the query set to create a calculation called "total".
> At the end of each loop I am adding "total" to the query set.  Example:-
>
> qs= Cash.objects.all()
> for i in qs:
># calculate total
>i.total = total
>
> Note:  The Cash object has no data field called "total".   I don't want
> to save this to the database because it is different for each user, so
> its created dynamically
> for each view.
>
> So far so good.  This works very well and allows me to iterate over the
> query set and the dynamically created attribute "total" in the template.
>
> However,  I would now like to sort the qs using "total.".  Since there
> is no record in the DB I'm guessing that order_by will not work.   Can
> anybody advise on a way.

You can make a custom sort_ by_total() function, create a list from
the queryset result and sort the list with sort() and sort_by_total.

I remember doing that some time ago and it worked but if the queryset
result is big you can suffer of performance problems.


Regards.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

--~--~-~--~~~---~--~~
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: tuples into a select list

2007-03-23 Thread Marcelo Ramos

2007/3/23, Greg Donald <[EMAIL PROTECTED]>:
>
> I have some tuples like this:
>
> categories = ( ( 'a', 'abc' ), ( 'b', 'def' ) )
>
> How can I build select options from that in a template?
>
> When I try this:
>
> {% for c in categories %}
> {{ c[1] }}
> {% endfor %}

Try:

{{c|slice:"1:2"|first}}

Regards.

-- 
Marcelo Ramos
Fedora Core 6 | 2.6.19
Socio UYLUG Nro 125

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