sites framework + gunicorn

2011-03-02 Thread ronny
Hi,

I'm trying to run multiples sites using the sites-framework, and
gunicorn.

I'm using the same project, same databases, only I try to use
different settings.py files with different names.

The idea is that in each gunicorn instance I set the
DJANGO_SETTINGS_MODULE to a different settings.py file, and hopefully
get the corrrect result.

Unforutunately, it doesn't seem to matter what I set
DJANGO_SETTINGS_MODULE to, no matter what it always points to
settings.py


Now I've run gunicorn using manage.py and explicitly pointing to the
settings.py file I want, and maybe that's the solution I will end up
using, but I'd like to be able to set things using gunicorn
configuration files.

So my question is this, does anyone have an idea what my problem is,
and what the solution is?

Thanks

-- 
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: sites framework + gunicorn

2011-03-06 Thread ronny
what I mean is that each supervisor thread calls a separate gunicorn
process.  Sorry I'm getting the terms confused.

Anyway, I tried it, but I'm still having trouble.

Here is my supervisor.conf

[program:gunicorn-blog-HE-development]
directory=/var/www/blog.development/private/blog

command=/var/www/blog.development/private/blog/manage.py run_gunicorn
127.0.0.1:8091 --settings=settingsheb

user=www-data
autostart=true
autorestart=unexpected
redirect_stderr=True
exitcodes=1



Now I have no problems if I run this a command in the terminal, e.g.
"python manage.py ...", however, I also set the python path
beforehand, and I don't see how to do that it supervisor.  I know I
can set an environment variable, for example environment=PYTHONPATH='/
path/to/apps', but what if my python path looks like this:

PYTHONPATH='/path/to/apps1':'/other/path/to/apps2'


This would be a LOT simpler if I could get gunicorn to run properly,
anyone have any suggestions?

-ron

On Mar 3, 3:19 am, Shawn Milochik  wrote:
> What do you mean by 'gunicorn instance' here?
>
> > The idea is that in each gunicorn instance I set the
> > DJANGO_SETTINGS_MODULE to a different settings.py file, and hopefully
> > get the corrrect result.
>
> In any case, I highly recommend you just use supervisord[1] for this
> and put the path to the settings files in your supervisor config.
>
> Here's an example of what your supervisord config might look like:
>
> [program:my_site_1]
> command=/home/username/projects/awesome_site/manage.py run_gunicorn
> 127.0.0.1:8000 --settings=projects.site1_settings
>
> [program:my_site_2]
> command=/home/username/projects/awesome_site/manage.py run_gunicorn
> 127.0.0.1:8100 --settings=projects.site2_settings
>
> 1:http://supervisord.org/
>
> Shawn

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



rewrite rules

2011-03-06 Thread ronny
I have to make a blog application in multiple languages, to do this, I
decided to use zinnia and create to separate urls blogfrench.com and
blog.com (this is an example).  I also used the multisite ability of
django to have a single admin interface for both blogs.

It works great, now I have a non-pythonic problem.

I want both blogs to be read with the same url:

that is, instead of

blog.com
blogfrench.com

I want

blog.com/en/weblog
blog.com/fre/weblog


So.  Does anyone know where I can find help in creating rewrite
rules?  I have no idea how to do it (btw, I'm using nginx if that
helps)

-- 
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: PLEASE HELP ME IN ADDING A CATEGORY IN THE ADMIN SITE

2011-03-08 Thread ronny
Ignore the rest of these guys, and go here:

http://south.aeracode.org/docs/tutorial/part1.html#tutorial-part-1

It's called django-south, all the cool kids are using it.

Enjoy.  :D

-ron

On Mar 8, 7:34 am, pankaj sharma  wrote:
> same as categories i have to add affiliation to every college.
> so i added
>
> class Affiliation(models.Model):
>     title = models.CharField(max_length=100)
>
>     def __unicode__(self):
>         return self.title
>
> to models.py
>
> and  added one more field to class of colleges
>
> class College(models.Model):
>    name = models.CharField(max_length=250)
>    category = models.ForeignKey(Category)
>    city = models.ForeignKey(City)
>    affiliation = models.ForeignKey(Affiliation)            ### i added
> this line to college class in models .py
>
> now i changed my admin.py to this:
>
> from django.contrib import admin
> from college.models import *
>
> class CollegeAdmin(admin.ModelAdmin):
>     list_display = ('name','category', 'city', 'affiliation')
>     list_filter = ['category', 'city']
>     search_fields = ['name', 'city']
>
> class CityAdmin(admin.ModelAdmin):
>     list_display = ('title', 'state')
>     list_filter = ['state']
>     search_fields = ['title',]
>
> admin.site.register(College, CollegeAdmin)
> admin.site.register(City, CityAdmin)
> admin.site.register(State)
> admin.site.register(Category)
> admin.site.register(Affiliation)
>
>  but when i use syncdb command it shows no fixtures found
>
> and when i click on college in admin site  then it show me error like
> this
>
> OperationalError at /admin/college/college/
> (1054, "Unknown column 'college_college.affiliation_id' in 'field
> list'")
>
> now what to do? do i have to edit some more codes?

-- 
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: Filter on multiple fields and/or multiple values...

2008-10-29 Thread Ronny Haryanto

On Thu, Oct 30, 2008 at 8:31 AM, megrez80 <[EMAIL PROTECTED]> wrote:
>   I want to do something like the following:
>
>  my_query_set = my_table.objects.filter(field1 = some_val and
> field2 = another_val)
>
> or
>  my_query_set = my_model.objects.filter(field1 = some_val or
> field1 = another_val)
>
> I couldn't find anything in the docs that describes how to go about
> doing this.

It is in the docs, although it's probably not immediately clear for
people not coming from a python background.

http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-objects-with-filters

**kwargs means keyword arguments (note that it's plural). "field1=val"
is one keyword argument. So you can specify more than one and all of
the conditions will be AND-ed together, like so:

Model.objects.filter(field1=val, field2=val)

You can even chain filters together to achieve the same effect:
http://docs.djangoproject.com/en/dev/topics/db/queries/#id1

If you want to OR them together, have a look at Q objects:
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

Ronny

--~--~-~--~~~---~--~~
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: change the DEBUG in settings.py base on the remoteaddr

2008-11-05 Thread Ronny Haryanto

On Wed, Nov 5, 2008 at 5:41 PM, kele <[EMAIL PROTECTED]> wrote:
>
> the debug flag in settings.py .
>
> what i want to do is to only change the DEBUG varialbe to True when
> just the specific remote address( ip) to send the request .
> cause i do not hope all my users can read the err msg while i am
> coding .
>
> something like this :
> if remoteAdd == 192.168.0.1 :
>   DEBUG = True
> else:
>   DEBUG = False
>
>
> but how ? need help  pls .

"Remote address" is http specific, while settings does not (and to
keep it loosely coupled probably should not) know anything about http
requests.

Have a look at INTERNAL_IPS setting to achieve what you want:
http://docs.djangoproject.com/en/dev/ref/settings/#internal-ips

Ronny

--~--~-~--~~~---~--~~
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: Select only two posts from a database list and show them on a HTML page

2008-11-05 Thread Ronny Haryanto

On Wed, Nov 5, 2008 at 6:34 PM, Bobo <[EMAIL PROTECTED]> wrote:
> In my Django project I've on the front page a table where I wish to
> load the two newest messages. Then I've a link to a message archive
> where all messages are listed.
>
> My problem is that I don't know how to "filter" my list at my front
> page so it only extracts the two newest messages.

messages = Message.objects.order_by('-created')[:2]

Substitute "created" with the actual date field if it's different.

> This is my code in views.py where I extracts all the messages and
> append them to my list:
>
> messages = Message.objects.all()
> messagelist = []
> for i in messages:
> if i.recepient=='Alle':
> messagelist.append(i)
> elif i.recepient==department:
> messagelist.append(i)

You don't have to pull all() if you only need a sub

from django.db.models import Q

messages = Message.objects.filter(
Q(recepient='Alle') | Q(recepient=department)).order_by('-created')[:2]

or if you don't want to use Q:

messages = Message.objects.filter(
recepient__in=['Alle', department]).order_by('-created')[:2]

> Later on my plan is to make the archive so the messages again is
> filtered or sorted in month, so the user can see that e.g. in November
> month this and this message was posted and in October, this and this
> message, but that's a whole new question :-)

Search for "generic views" in the documentation, you might be
interested in the date based views.

Ronny

--~--~-~--~~~---~--~~
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: django admin - list filter - issues with model fields having name ending in 'y'

2008-11-05 Thread Ronny Haryanto

On Wed, Nov 5, 2008 at 6:30 PM, ammo <[EMAIL PROTECTED]> wrote:
> I have a 'Country' model and I have set its 'verbose_plural_name' to
> 'Countries'. This displays fine in the site administration page
> (earlier it showed Countrys there).

Not sure if this has any relation to your problem, but shouldn't the
verbose_plural_name value be in lowercase (i.e 'countries' not
'Countries')?

Ronny

--~--~-~--~~~---~--~~
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: Select only two posts from a database list and show them on a HTML page

2008-11-05 Thread Ronny Haryanto

On Wed, Nov 5, 2008 at 8:23 PM, JoeJ <[EMAIL PROTECTED]> wrote:
> I would guess that this version:
>   messages = Message.objects.order_by('-created')[:2]
>
> would be more memory efficient than the:
>   messages = Message.objects.all()
>   (and then using   |slice:":2" to cut out the top 2)
>
> although, I've done that second one often.

You probably already know this: QuerySets are lazy:
http://docs.djangoproject.com/en/dev/topics/db/queries/#id3

Though I'm not too sure with the slice filter. If anyone's interested
to find out, they could inspect the generated SQL queries to check.

I only use the slice filter if it's not possible for me to know in the
view beforehand how I'm going to slice my list, or if I know for sure
the size of my list is relatively small.

Ronny

--~--~-~--~~~---~--~~
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: Change date format in admin

2008-11-11 Thread Ronny Haryanto

On Tue, Nov 11, 2008 at 4:20 PM, Alex Rades <[EMAIL PROTECTED]> wrote:
> Is there a way to do it? Here in europe we really use DD-MM-

Yes.

Look for DATE_FORMAT in:
http://docs.djangoproject.com/en/dev/ref/settings/

See also http://code.djangoproject.com/ticket/2203 if you have
USE_I18N = True in your settings.

Ronny

--~--~-~--~~~---~--~~
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: Adding a "subtotal" row to the Admin change list page?

2008-11-11 Thread Ronny Haryanto

On Wed, Nov 12, 2008 at 9:39 AM, Eric <[EMAIL PROTECTED]> wrote:
> Hi folks, I am using the default Admin pages for my site, and I have a
> modification/customization question.
>
> I am wondering what the best approach would be to modify the admin
> change list page so that there can be a new row that sums the contents
> of all the other rows. For example, each row in the change list page
> contains a used car transaction, and I want a row that totals up the
> value of all the used cars in the list. I would also like this total
> to be consistent with any filters that may be applied (for example,
> the car's make/model).

You can modify the admin templates, particularly the change list
template (change_list.html), to *show* the subtotal. See here for more
info re: modifying the admin templates:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

*Obtaining* the subtotal is another issue. One way is to use
Javascript that is (conditionally) loaded from the template. There are
other possibilities: custom model manager method, custom SQL that
includes SUM(...) as a field, and maybe custom ModelAdmin (I'm not too
sure about this though). Once you get the subtotal you can display it
using custom admin template.

Hope that gives you a starting point.

Ronny

--~--~-~--~~~---~--~~
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: Intercepting return from new ForeignKey popups? (RelatedObjectLookups.js)

2008-11-18 Thread Ronny Haryanto

On Sun, Nov 16, 2008 at 11:50 PM, Ben Gerdemann <[EMAIL PROTECTED]> wrote:
> I've got everything working correctly except for one problem. When
> adding a new foreign key by clicking on the "+" the hidden field is
> correctly updated with the primary key of the new object, but the
> autocomplete field still shows the previous text which is confusing to
> the user. The insertion still works correctly of course as it's the
> hidden field that is actually used. Any ideas on how to correct this?
> It seems the JavaScript code RelatedObjectLookups.js controls this
> behavior, but I can't quite get my head around what to do. I need
> someway to intercept the return from the Popup to update fields on my
> form.

I just did something similar (the popup part not the autocomplete
part), maybe it could give you some ideas. I ended up modifying the js
(copied into a new file and use that instead of
RelatedObjectLookups.js). Basically I modified the dismiss function so
that it can accept and call a callback function, something like:

function dismiss(window, callback) {
...
callback()
win.close()
}

and then in the view I added this:

return HttpResponse("""

opener.dismissEditPopup(window, function(){
opener.update_info()
});
""")

and I can define update_info() in the opener template to do whatever's
necessary.

This is similar to what django's admin is doing (see
django/contrib/admin/options.py around line 427 under response_add()).

Hope I'm still making sense. It's 1am here.

Ronny

--~--~-~--~~~---~--~~
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 create a form with dynamic number of fields?

2008-11-18 Thread Ronny Haryanto

On Sun, Nov 16, 2008 at 12:14 PM, Low Kian Seong <[EMAIL PROTECTED]> wrote:
> Could anyone here please let me know of the logic or example of doing
> a form with dynamic number of fields (ie. a field with a 'Add more
> field' button). I know how to do it using javascript. However it's the
> logic behind that gets me. Suggestions?

James Bennett just recently wrote a (excellent) blog post about dynamic forms:
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

Ronny

--~--~-~--~~~---~--~~
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: Django 1.0 tutorial

2008-11-27 Thread Ronny Haryanto

On Fri, Nov 28, 2008 at 9:31 AM, Malcolm Tredinnick
<[EMAIL PROTECTED]> wrote:
> On Thu, 2008-11-27 at 07:33 -0800, Benjamin Wohlwend wrote:
> [...]
>
>>  but suggesting on an official
>> Django mailing list to pirate a book written by one of the Django core
>> devs is stretching it a bit, don't you think?
>
> Have you looked at the license under which that book was released?
> http://www.djangobook.com/license/

Malcolm, I think the previously mentioned book was Practical Django
Projects by James Bennett, not the Django Book.

Ronny

--~--~-~--~~~---~--~~
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: login problem

2008-12-06 Thread Ronny Haryanto

On Sat, Dec 6, 2008 at 2:42 PM, vierda <[EMAIL PROTECTED]> wrote:
> today I try to make login page with follow example code in
> djangoproject (user authentication chapter), code as following below :
>
> def my_view(request):
>   username = request.POST['username']
>   password = request.POST['password']
>   user =  authenticate(username=username, password=password)#create
> Authentication object
>
>   if user is not None:
>  if user.is_active:
> login(request,user)
> return HttpResponse('login success')
>  else:
> return HttpResponse('disable account')
>   else:
>  return HttpResponse('invalid login')
>
> the above code always shows MultiValueDictKeyError with exception
> value "Key 'username' not found in ".

That exception will always be raised if the view is called via GET
method instead of POST.

If you're sending it via POST, then the information you provided was
not sufficient. We need to see template code that renders the form (or
the html form if you're not using templates) and probably the form as
well.

Ronny

--~--~-~--~~~---~--~~
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: Development server crash with no error message

2008-12-09 Thread Ronny Haryanto

On Tue, Dec 9, 2008 at 4:50 AM, Andrew Fong <[EMAIL PROTECTED]> wrote:
>
> When I'm poking around in my Django app, my development server
> (manage.py runserver) will sometimes quit without raising an exception
> or leaving any messages. I am not tinkering around with the code or
> doing anything that would force a reload. It just decides to quit.
>
> I can check the last request I made before it crashed, but without any
> exceptions or errors, it's very hard to debug. Does anyone have any
> tips on getting some more useful output out of a crash?

I just ran into the same problem. In my case however, I happen to know
exactly which requests causes the crash, it happened everytime I query
a model (say Entry.objects.all()). So I ran:

from myproj.myapp.models import Entry
Entry.objects.all()

from 'manage.py shell' and I immediately saw from the exceptions that
there was an infinite recursion. It turned out that I defined a custom
Manager's get_query_set() in a very wrong way causing an infinite loop
(I stupidly returned self.filter(...) instead of calling super like
the doc says).

I don't know if this would help in your case, but I thought I share
anyway, just in case.

Ronny

--~--~-~--~~~---~--~~
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 do wire Userprofile to UserAdmin ?

2008-12-09 Thread Ronny Haryanto

On Tue, Dec 9, 2008 at 8:58 PM, mahesh <[EMAIL PROTECTED]> wrote:
> How do wire Userprofile to UserAdmin ?

Here's one way to do it:

# admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from myproj.myapp.models import UserProfile

class UserProfileAdminInline(admin.TabularInline):
model = UserProfile

class NewUserAdmin(UserAdmin):
inlines = [UserProfileAdminInline]

admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)

Ronny

--~--~-~--~~~---~--~~
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: missing admin documentation

2008-12-09 Thread Ronny Haryanto

On Wed, Dec 10, 2008 at 12:50 AM, aparajita
<[EMAIL PROTECTED]> wrote:
> I am using django release 1.0.2, nothing modified. My admin interface
> works fine, but the documentation link never appears. I have
> 'django.middleware.doc.XViewMiddleware' in the list of middleware, I
> have my IP address listed in INTERNAL_IPS.
>
> Any ideas?

Do you have 'django.contrib.admindocs' in your INSTALLED_APPS?

Ronny

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



model instance version numbering, or concurrent model editing

2008-12-11 Thread Ronny Haryanto

G'day all,

Let say I have a wiki-like Django app. I wanted to allow many people
edit a wiki page without any locking, yet have the system prevent two
people saving page updates at almost the same time (one of the updates
would be lost, overwritten by the other one).

This is what I have in mind. Add a version field to the WikiPage model
which is automatically incremented on every update. The system should
not allow saving an existing page with version (in db) >= version (in
data to be saved). This is probably done in save().

I've tried overriding the models's save() method, but I'm always stuck
at how to get the guaranteed-most-recent version number (lock the
row/table?) from the db (as opposed to self.version, which could
already be stale by the time save() is called).

My questions are:
* Is my approach reasonable? (or Have I missed a more obvious/easier way?)
* Can this be achieved in Django? If so, any ideas how?
* Should this be done in Django, or better implemented on the database
level as ON UPDATE trigger(s)?

I checked django-wiki app in google code, but it doesn't seem to have
this feature.

I wanted to keep my question focused on one particular issue first,
but if the bigger picture makes any difference: my WikiPage model is
actually an abstract model, and I wanted to provide this feature for
all of its subclasses.

I would appreciate any help.

Cheers,
Ronny

--~--~-~--~~~---~--~~
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: Filtering parents by child attributes

2009-01-04 Thread Ronny Haryanto

On Fri, Jan 2, 2009 at 11:57 PM, Mathieu Steele  wrote:
> Here is an example of the data model for the type of filter I would
> like to do:
>
> class Student
>   name
>
> class Absence
>   foreign key Student
>   date
>
> Is there a way to filter Students with no absences?
>
> something like Student.objects.filter(absence_set__count=0)

CMIIW, but I think something like this should work:

Student.objects.filter(absence__isnull=False)

Ronny

--~--~-~--~~~---~--~~
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: Dynamic OR statements

2009-01-05 Thread Ronny Haryanto

On Mon, Jan 5, 2009 at 11:52 PM, Bluemilkshake
 wrote:
> for category in category_list:
>results = results.filter(categories__slug = category.slug)

How about results.filter(category__in=category_list)?

Ronny

--~--~-~--~~~---~--~~
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: Dynamic OR statements

2009-01-05 Thread Ronny Haryanto

On Mon, Jan 5, 2009 at 11:59 PM, Ronny Haryanto  wrote:
> On Mon, Jan 5, 2009 at 11:52 PM, Bluemilkshake
>  wrote:
>> for category in category_list:
>>results = results.filter(categories__slug = category.slug)
>
> How about results.filter(category__in=category_list)?

Whoops. Never mind. Replied too fast. Sorry.

Ronny

--~--~-~--~~~---~--~~
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: single list items in templates

2008-07-17 Thread Ronny Haryanto

On Thu, Jul 17, 2008 at 2:03 AM, Tim Chase
<[EMAIL PROTECTED]> wrote:
>
>> I have a list: data = ['apple', 'orange', 'banana']
>> in my template: {{ data }} will output: ['apple', orange, banana]
>> but {{ data[0] }} will throw an error
>
>
> {{ data.0 }} should do the trick.

Or {{ data|first }}.

http://www.djangoproject.com/documentation/templates/#first

Ronny

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

2008-08-19 Thread Ronny Haryanto

2008/8/20 laspal <[EMAIL PROTECTED]>:
> Can anyone give a link for doing corn job.

Cron is Unix-based scheduler, it's not part of or related to Django.
You most likely need to use a system external to Django to achieve
what you want. One of such systems is cron.

There are plenty of info regarding cron on the web:
http://www.google.com/search?q=cron

Ronny

--~--~-~--~~~---~--~~
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: Browser timeout on long processes

2008-08-20 Thread Ronny Haryanto

On Wed, Aug 20, 2008 at 4:16 PM, coulix <[EMAIL PROTECTED]> wrote:
> Yes, if you can check the Restfull book from Oreilly there is a good
> example on using
> a queue system to submit lengthy job. You submit the work and it gives
> you back an url
> that you can check 'repeatedly' to see the progress or completion of
> the job.

There is at least one such project that is specific to Django:
http://code.google.com/p/django-queue-service/

Ronny

--~--~-~--~~~---~--~~
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: Newbie Question - Regex Field to deal with Feet/Inches

2008-08-27 Thread Ronny Haryanto

On Wed, Aug 27, 2008 at 3:13 AM, bkev <[EMAIL PROTECTED]> wrote:
> I'm working on a site that has several imperial measurements (feet and
> inches) and I'd like to implement a field in my model that uses a
> regular expression like:
>  ^(\d{1,5})\'((\s?)(-?)(\s?)([0-9]|(1[0-1]))\")?$
> to parse off the feet and inches and save them in a sortable manner
> (I'm guessing the best way would be to convert them and save them as a
> decimal number, but the list and admin display needs to in x'-y"
> format. Anyone have any ideas as to how I might accomplish that? (or
> where I should look for more information)?

I use the following method in one of my projects:

def feetinch_to_cm(length):
"""convert US style (feet-inch) length to metric (cm)"""
if length == u'' or length is None:
return None
m = re.match(r'(?P\d+)[\'`](
*(?P\d+)(?P.)?("|\'\'))?', length)
if m is None:
raise Exception("unable to parse length: %s" % length,)
feet = int(m.group('feet'))
inch = int(m.group('inch') or 0)
half = int(m.group('half') == u'\xbd')
return (30.48 * feet) + (2.54 * inch) + (1.27 * half)

I save the length in centimeters in database, then I can reformat it
as needed in the template or admin using a custom filter.

Ronny

--~--~-~--~~~---~--~~
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: About Site in django

2008-08-27 Thread Ronny Haryanto

On Thu, Aug 28, 2008 at 8:27 AM, PENPEN <[EMAIL PROTECTED]> wrote:
> I have a question on the site concept.
> While reading the source code, I found that there is the site related
> statement in django.contrib.auth.views.login:
>
>if Site._meta.installed:
>current_site = Site.objects.get_current()
>else:
>current_site = RequestSite(request)
>
> I'm not clear about "Site._meta.installed". I tried in my project, and
> found it is already True. But I could not find a way to toggle its
> value. Could anybody explain how this variable is assigned?

It's already set probably because INSTALLED_APPS includes
'django.contrib.sites' by default.

More info:
http://docs.djangoproject.com/en/dev/ref/contrib/sites/

Ronny

--~--~-~--~~~---~--~~
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: Newbie Question - Regex Field to deal with Feet/Inches

2008-08-30 Thread Ronny Haryanto

On Fri, Aug 29, 2008 at 2:54 AM, bkev <[EMAIL PROTECTED]> wrote:
>
> Ronny,
>
> This is fabulous...thank you so very much. If you don't mind me
> asking, can you give me an example of how you implemented this method
> in your Class? In my case, I've defined the field as a DecimalField
> type, but that brings up an error. Did you define some sort of custom
> save method around that? Thank you; I really appreciate it.

Nothing unusual. I'm using a FloatField to store it.

person = Person.objects.get_or_create(...)
person.height_in_cm = feetinch_to_cm(input)
...
person.save()

Ronny

--~--~-~--~~~---~--~~
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: name 'admin' is not defined

2008-09-02 Thread Ronny Haryanto

On Wed, Sep 3, 2008 at 12:56 AM, Weber Sites <[EMAIL PROTECTED]> wrote:
> I'm trying to follow the Tutorial02 and once i uncomment the admin
> lines in urls.py i get :
>
> ImproperlyConfigured at /mysite/
> Error while importing URLconf 'mysite.urls': name 'admin' is not defined

This probably sounds silly, but since you don't give any code snippets
then I can't be sure. Have you uncommented the import line:

from django.contrib import admin

in urls.py?

Ronny

--~--~-~--~~~---~--~~
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: Newbie Question - Regex Field to deal with Feet/Inches

2008-09-04 Thread Ronny Haryanto

On Fri, Sep 5, 2008 at 1:53 AM, bkev <[EMAIL PROTECTED]> wrote:
>
> Ronny,
>
> Thank you so very much for your input; it has helped this newbie user
> a great deal. The one outstanding problem I'm having here (and it's
> the last field in my model...) is that I'd actually like to use a
> FloatField to save my data, but it's failing validation for that type
> of field ("enter a valid floating point number, etc"). Did you
> override the field validation using some clean() method variation, or
> am I missing something? See my modified class definition below:
>
> Thank you again,
> -bkev
>
>
>
> def feetinch_to_decimal(length):
>"""convert US style (feet-inch) length to decimal feet (ft)"""
>if length == u'' or length is None:
>return None
>m = re.match(r'^(?P(\d{1,5}))(\')(\s?)(-?)(\s?)(?
> P(\d{1,2}))(")?$',length)
>if m is None:
>raise Exception("unable to parse length: %s" % length,)
>feet = int(m.group('feet'))
>inch = int(m.group('inch') or 0)
>return (feet + (inch/12.))
>
> class FooBar(models.Model):
>length = models.FloatField(verbose_name="Length",default="0")
>try:
>bar=FooBar.objects.get_or_create(id='1',length='1')
>bar.foo=feetinch_to_decimal(input)
>bar.save()
>except Exception, e:
>if isinstance(e,IntegrityError):
>print "Pass"
>else:
>print "Fail with %s" % type(e)
>class Admin:
>pass


I wouldn't do that, it doesn't make sense to me.

Only this is needed in models.py:

class FooBar(models.Model):
length_in_cm = models.FloatField(default=0)

Then somewhere else (e.g. views.py or others):

length_us = '5\'2"'
foo = FooBar()
foo.length_in_cm = feetinch_to_cm(length_us)
foo.save()

Alternatively, if you want FooBar to understand and support the
conversion you could create a length_in_feetinch property that will
automatically do the conversion to cm while keeping only the
length_in_cm in the database, have a look at
http://adam.gomaa.us/blog/the-python-property-builtin/ for an example.

Ronny

--~--~-~--~~~---~--~~
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: DjangoCon video

2008-09-11 Thread Ronny Haryanto
On Thu, Sep 11, 2008 at 5:28 PM, Petar Marić <[EMAIL PROTECTED]> wrote:
> Unfortunately I was unable to participate on DjangoCon because of my
> Master thesis. Will there be a video of some/all the talks?

I saw this at http://twitter.com/djangocon/statuses/917078011:

"DjangoCon videos will be made available on the djangocon.org site.
 I will make a loud announcement when they're available."

Ronny

--~--~-~--~~~---~--~~
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: Generating widget based on class type for a Custom Form

2008-10-06 Thread Ronny Haryanto

On Tue, Oct 7, 2008 at 7:09 AM, Leon Yeh | New Avenue.net
<[EMAIL PROTECTED]> wrote:
> I need to generate a different output based if it is a select input type
> or it is a text field.
>
> This code does not work. I am trying to do something like this:
>
> {% for field in form %}
> {% ifequal field.field.widget django.forms.widgets.Select  %}
>   {{ field.label_tag }} {{ field.errors }} {{ field }}
> {% else %}
>   It is not select field
> {% endifequal %}
> {% endfor %}
>
>
> I am having hard time to do the ifequal statement. It does not get the
> correct comparison. It always return true. Any idea how to fix this ?

Leon,

Any reason why {{ field.as_widget }} wouldn't work in your case?

Ronny

--~--~-~--~~~---~--~~
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: Generating widget based on class type for a Custom Form

2008-10-07 Thread Ronny Haryanto

On Tue, Oct 7, 2008 at 7:31 PM, Leon Yeh | New Avenue.net
<[EMAIL PROTECTED]> wrote:
> Hi Ronny, terima kasih... :-)

Sama-sama :-)

> I am trying to generate different output for css styling purpose.
>
> For example for select widget I need to generate
>   
>
> and for other controls, I need to generate
>   
>
> I don't know how field.as_widget would help.

Right. I can see how this is useful for creating a generic form template.

In that case, I'd probably write a custom tag to do the job, probably
something along the line of:

{% if_widget_select field %}

This is something similar that I had done previously:

from djblets.util.decorators import blocktag

register = Library()

@register.tag
@blocktag
def if_is_select_field(context, nodelist, field):
if isinstance(field, forms.MultipleChoiceField):
return nodelist.render(context)
else:
return ''

You can find djblets tag helpers here: http://www.chipx86.com/blog/?p=245

Cheers,
Ronny

--~--~-~--~~~---~--~~
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: Best Practices in Implementing Mini-Content Boxes Across the Site

2008-10-13 Thread Ronny Haryanto

On Mon, Oct 13, 2008 at 3:38 PM, raeldc <[EMAIL PROTECTED]> wrote:
> One of the things I'm wondering about is how to implement mini-content
> boxes. It is known to Joomla as modules, in Drupal as blocks, to
> others they are called widgets or side bars. In CMS systems, I can
> assign a content-box to be viewable on different pages or all pages
> with simple point and click. In Django, I think I would have to call
> the VIEW for those content boxes in every VIEW where I want them
> displayed. This method looks very redundant to me. Or maybe I'm still
> in the stage of my learning where I haven't found the Django way that
> deals with this. So I'm asking the experts on Django for guidance. How
> do I implement easily manageable min-content boxes on my Django
> website? Is there a Django standard way? If none, can you please
> suggest what you think is the best way to do this?

I don't think there's a standard, since Django is not a CMS (you build
your CMS *with* Django), and therefore it doesn't provide any
CMS-specific things like sidebars, widgets, boxes, or whatever it is
called.

However, Django templates supports inheritance and a way to include
other templates that should make it easier:
http://docs.djangoproject.com/en/dev/topics/templates/#id1
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

For static blocks, there's also a 3rd party project called
django-chunks that you might want to take a look at.

Ronny

--~--~-~--~~~---~--~~
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: icontains case-sensitive on MySQL

2008-10-16 Thread Ronny Haryanto

On Fri, Oct 17, 2008 at 12:55 AM, AndyB <[EMAIL PROTECTED]> wrote:
> I've googled and the only problems seem to be with people trying to do
> case-sensite lookups.
>
> What could be going wrong here?:
>
>>>> b.filter(name__icontains='Saff')
> []
>>>> b.filter(name__icontains='saff')
> []

Could you do:

from django.db import connection
connection.queries

to see the raw SQL queries?

Ronny

--~--~-~--~~~---~--~~
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: Limit choices by object, not model

2008-10-16 Thread Ronny Haryanto

On Fri, Oct 17, 2008 at 12:23 AM, AmanKow <[EMAIL PROTECTED]> wrote:
> I need to limit choices dynamically by an object, not a class:

> When adding or changing a
> participation object, either in the admin or via model forms, I need
> to limit the choices for cert type to those offered by the the
> participation's activity topic.

Wouldn't it make more sense to limit them in the admin or the forms
instead of limiting them right in the models? The act of selecting an
activity topic in a form is form specific, the models don't (and
probably don't need to) have any knowledge of that.

Ronny

--~--~-~--~~~---~--~~
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: some help with urls

2008-03-31 Thread Ronny Haryanto

Try:

r'^test/fullpath/(?P[\w/]+)

Ronny

On Mon, Mar 31, 2008 at 4:08 PM, Rishabh Manocha <[EMAIL PROTECTED]> wrote:
>
>  Hey guys,
>
>  I'm trying to setup my urls.py file and am having trouble getting the
>  args to be passed correctly to my view. I basically have something
>  link this:
>
>  urlpatterns = patterns('',
>(r'^test/fullpath/$',"test.browse.views.index"),
>
>  (r'^test/fullpath/(?P\w+)/$',"test.browse.views.index"),
>  )
>
>  What I would like to happen is this:
>
>  url = http://localhost:8000/test/fullpath   :
>  path_name = ""
>  url = http://localhost:8000/test/fullpath/private :
>  path_name = private
>  url = http://localhost:8000/test/fullpath/private/images :
>  path_name = private/images
>
>  I'm having trouble figuring out the correct regexp to get that third
>  case going. I have tried things like
>  "r'^test/fullpath/(?P\w+)/+",
>  "r'^test/fullpath/(?P\w+)+",
>  "r'^test/fullpath/(?P\w+)+/+" but none of these or the
>  other combinations that I have tried have worked. They all just return
>  private (in the 3'rd case) or throw a 404 error.
>
>  Is it the case that urls with "/" in them will automatically be cut
>  apart by Django or am I just screwing up my regexp real bad here (BTW,
>  I am a novice at writing regexp's).
>
>  Some help would be highly appreciated.
>
>  Best,
>
>  R
>
>  >
>

--~--~-~--~~~---~--~~
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: Best practice for databases and distributed development with Django

2008-04-02 Thread Ronny Haryanto

On Thu, Apr 3, 2008 at 7:36 AM, Julien <[EMAIL PROTECTED]> wrote:
>  We're using SVN between several developers to work on the same project
>  and it's working quite well. But it's not as simple concerning the
>  database.
>
>  Each of us has a local database to muck around with, and if one of us
>  makes a change in the models that implies modifying the database
>  manually (e.g. renaming a field, changing the type or the field, etc.)
>  that developer has to inform all others of the changes so they all
>  make the change manually on their own local database.
>
>  Having a common database would avoid that, but that's not ideal since
>  an online database would be slower to access, and it could quickly go
>  out of control if many people add records or change the database
>  structure at the same time.
>
>  So, I just wanted to get some advice from you as to what is the best
>  approach to go?

For our last project (not Django, unfortunately), we created a
directory that holds SQL changes files. The files were named
"from-1234.sql" where 1234 is the current svn revision when the file
was created. Everytime we made a change to the database model, we
modified the main sql file (equivalent to models.py in django), then
we also created an SQL change file containing all the changes (alter,
drop, etc.), then we ran the SQL change file to actually modify the
database instead of modifying the database directly. Other developers
would need to pay attention for additions in the SQL changes directory
and update their database accordingly whenever there's a new file
there.

Ronny

--~--~-~--~~~---~--~~
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: passing form to base template

2008-04-28 Thread Ronny Haryanto

On Tue, Apr 29, 2008 at 9:33 AM, skunkwerk <[EMAIL PROTECTED]> wrote:
>  I've got two forms included in my base template, from which a few
>  others inherit.  Currently I'm passing a newly-constructed form to
>  each of the inherited templates in the functions using
>  render_to_response, like so:
>
>  return render_to_response('contact.html', {'form': form,  'suggform':
>  suggform,  'searchform':searchform })
>
>  it's getting tedious though... is there some way I can pass the forms
>  to only the base template, and have all the other inherited templates
>  get the forms too?  the default forms are all static - no dynamic
>  values.

Would a custom context processor work for you?
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext

Ronny

--~--~-~--~~~---~--~~
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: get for errors as string and not as HTML

2008-04-29 Thread Ronny Haryanto

On Wed, Apr 30, 2008 at 12:03 PM, Mike Chambers <[EMAIL PROTECTED]> wrote:
>  
> Name
> {{ form.user_name }} {{ form.user_name.errors }}
>  

>  Is there any way to just get the raw error string?

You should be able to treat form.user_name.errors as a python list
(e.g. iterate with for, join, etc).

Ronny

--~--~-~--~~~---~--~~
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: Access Control List

2008-05-01 Thread Ronny Haryanto

On Fri, May 2, 2008 at 10:04 AM, Rit Lim <[EMAIL PROTECTED]> wrote:
>  "Mary may change news stories, but only the ones she created
>  herself..."
>
>  How do I go about doing that? I was told I need to write an ACL.
>  However, I'm not sure how to do it.
>
>  Anyone has some sample code?

The documentation clearly says that it's not currently possible (that
is if you're using django's auth system).
http://www.djangoproject.com/documentation/authentication/#permissions

Ronny

--~--~-~--~~~---~--~~
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: Change password only for administrators

2008-05-07 Thread Ronny Haryanto

On Wed, May 7, 2008 at 4:21 PM, Alessandro Ronchi
<[EMAIL PROTECTED]> wrote:
>  I want to make the change of the password possible only for administrators 
> and
>  not the whole staff. Is it possible? How I can do that?

How do you currently allow staff to change password?

Ronny

--~--~-~--~~~---~--~~
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: Getting back to the same page after completing a task in another page

2008-05-11 Thread Ronny Haryanto

On Sun, May 11, 2008 at 11:55 AM, M.Ganesh <[EMAIL PROTECTED]> wrote:
> I am displaying a list of records in a page. I have a link in that page
> which will take me to a form for adding one more record. How do I come
> back to the previous page after adding a record?

If the "previous page" is always the same, then you could return a
HttpResponseRedirect to that view in your view method that handles the
adding of one record.

> I remember seeing somewhere a trick involving something like  href=/list/add/?next=request.get_full_path>Add..

Alternatively, you could probably record the user's trail or view
history in the database, then show it somewhere in the page, so the
user can decide themselves which page they want to go back to.

Ronny

--~--~-~--~~~---~--~~
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: Dynamic lookup

2008-05-17 Thread Ronny Haryanto

On Sat, May 17, 2008 at 6:11 PM, mwebs <[EMAIL PROTECTED]> wrote:
> I am using something like this:
>
> model.objects.filter(field = variable)
>
> Is it possible to pass the field that is used for the lookup
> dynamically, so that field is also a variable ?

It's python kwargs (keyword arguments). You can do this:

dictionary = {field1: val1, field2: val2}
model.objects.filter(**dictionary)

Ronny

--~--~-~--~~~---~--~~
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: load external xml and css with varibles?

2008-05-21 Thread Ronny Haryanto

On Wed, May 21, 2008 at 5:58 PM, sebey <[EMAIL PROTECTED]> wrote:
> I know css does not not have any variables but I was thinking that
> python/django could look though the css file and have
> background-color:{{insert python varible here}}

Django's templating is not restricted to HTML only. You can do
something like this in the view:

render_to_response('style.css', {'bgcol': '#fff', })

Then in style.css you can have:

background-color: {{ bgcol }}

You might need to set the correct mime type when serving non-html
files. Please check the docs.

Ronny

--~--~-~--~~~---~--~~
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: Help for strategy to load dynamic content by domain (not subdomains)

2008-06-10 Thread Ronny Haryanto

On Wed, Jun 11, 2008 at 10:00 AM, ge <[EMAIL PROTECTED]> wrote:
> I have what I hope is a simple question here.  I do have a working
> solution, but I'd like to know if anyone has any thoughts on cleaner
> or perhaps more proper way to do this.
>
> For simplicities sake, lets assume I am trying to make a blogging
> service that allows users to create their own blogging portal.  The
> portal would allow them point their own domain to my django app, and
> the app would figure out what content to load based on the domain
> requested.  The Sites app wont work, because it pulls the domain from
> the db/settings file.  I need to get the domain from the request and
> choose what content to load.
>
> I created a custom manager that does this, but I have to pass a
> request object (or just the request.get_host()) with every call.  I
> guess what I would like to do is figure out if there is a more elegant
> way to get the domain name as it is in the request object, while
> inside the manager.  This would avoid having to pass a request object
> to it every single time I call it.
>
> If anyone has any other ideas for a different strategy completely, I
> would love to hear those as well.

You might be interested in this:
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

You could extend/replace the middleware to capture the domain (instead
of the user) from the request, then use it in a similar fashion in
your models/managers.

Ronny

--~--~-~--~~~---~--~~
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 handle all DoesNotExist?

2008-06-14 Thread Ronny Haryanto

On Sun, Jun 15, 2008 at 1:40 AM, Szymon <[EMAIL PROTECTED]> wrote:
> What I need to import to handle DoesNotExist in process_exception?
> Because DoesNotExist is part of every single model, so I can't import
> it from model, because I don't know which model raises exception.

from django.db import models

try:
AnyModel.objects.get(pk=nonexistant)
except (models.ObjectDoesNotExist):
do whatever

It should work as long as AnyModel is a subclass of models.Model.

Ronny

--~--~-~--~~~---~--~~
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: CMS application: auto-setting the post author

2008-06-16 Thread Ronny Haryanto

On Tue, Jun 17, 2008 at 9:02 AM, saxon75 <[EMAIL PROTECTED]> wrote:
>
> I'm working on a CMS application and had a question about
> automatically setting certain model fields.
>
> Suppose I have the following model (this is simplified from the actual
> application):
>
> class Item(models.Model):
>author = models.ForeignKey(User)
>created = models.DateTimeField()
>title = models.CharField(max_length=255)
>body = models.TextField()
>
> Now, when I go to create a new Item, whether via the admin site or a
> custom newforms-based form, it requires that I select an author from a
> list of existing users.  What I'd prefer is to leave out the author
> field entirely from the add form and have that field automatically set
> to the current user.  How can I do that?

This is one way to do it:
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

Ronny

--~--~-~--~~~---~--~~
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: CMS application: auto-setting the post author

2008-06-16 Thread Ronny Haryanto

On Tue, Jun 17, 2008 at 9:02 AM, saxon75 <[EMAIL PROTECTED]> wrote:
> I'm working on a CMS application and had a question about
> automatically setting certain model fields.
>
> Suppose I have the following model (this is simplified from the actual
> application):
>
> class Item(models.Model):
>author = models.ForeignKey(User)
>created = models.DateTimeField()
>title = models.CharField(max_length=255)
>body = models.TextField()
>
> Now, when I go to create a new Item, whether via the admin site or a
> custom newforms-based form, it requires that I select an author from a
> list of existing users.  What I'd prefer is to leave out the author
> field entirely from the add form and have that field automatically set
> to the current user.  How can I do that?

D'oh, I pressed Send too soon.

Another way (which I personally prefer because it's more explicit and
clear), is to do it in the view. Don't show the author field in the
form, because we want to automatically add it before saving.

def add_item(request):
...
item.author = request.user
item.save()

The syntax might not be correct, but you get the idea.

Ronny

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



where to run extra SQL when "manage.py reset appname" is run

2006-06-20 Thread Ronny Srnka

hi!

i've discovered django a few days ago and i must say it looks very useful 
and decided to use it for my latest project. i might ask some simple 
questions cause this is new to me, but am going over the documentation (and 
google) before asking.

anyways done to business:

i'd like to use some triggers to increment and decrement fields in the db. 
i've written them up but would like to know if there is somewhere to run 
them when i reset (or the initial syncdb on) an app with manage.py?
i saw that django.core.management.get_sql_all() collects all the SQL to be 
run, but there doesn't seem to be a place for other SQL (like trigger 
declerations).

thanks,
ronny 



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



Re: problem with ImageField does not show me the picture on a template

2013-05-23 Thread Ronny Villarroel Mendoza
Thanks a lot.

I do the following steps:
aggregate an alias to the virtual host of my site:
Alias /media /var/www/fourweb/media/

and modified:

settings.MEDIA_ROOT = '/var/www/fourweb/media/'
settings.MEDIA_URL = 'http://fourweb.com/media/'

it works!.

Cheers
Ronny

El martes, 21 de mayo de 2013 21:10:24 UTC-4, Ronny Villarroel Mendoza 
escribió:
>
> Hi all,
>
> I cant show the picture that I upload from the admin site.
>
>
> settings.py:
>
> MEDIA_ROOT = '/var/www/fourweb/'
>
>
>
> models.py:
>
> class picture(models.Model):
> producto_id = models.ForeignKey(producto)
> description = models.CharField(max_length= 250)
> imagen = models.ImageField(upload_to='photos/%Y/%m/%d', help_text = 
> '100px,150px')
> def __unicode__(self):
> return self.description
>
>
>
> view.py:
>
> def detail(request, item_id):
> p = get_object_or_404(producto, pk=item_id)
> pictures = picture.objects.filter(producto_id = item_id)
> return render_to_response('detail.html', {'item': p, 'photos': 
> pictures })
>
> and in the tamplate(details.html):
>
>
>{% if photos %}
> {% for photo in photos %}
>  width="200" >
> {% endfor %}
>{% else %}
> No hay imagen para el articulo
>{% endif %}
>
> the last html output code is:
>
>  src="photos/2013/05/14/picture_67090.jpg<http://fourweb.com/tienda/2/photos/2013/05/14/picture_67090.jpg>"
>  
> height="200" width="200" >
>
> the problem is that the picture doen't show, the path is broken. What I 
> doing wrong ???.
>
> please your help.
>
> Regards,
> Ronny 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: View pictures from the template via models.FilePathField

2013-05-24 Thread Ronny Villarroel Mendoza
Hi Federico,

Maby is better idea you use the models.ImageField(upload_to= path)

ie:
locandina = models.ImageField(upload_to= path)

then in the template you can get the path:

{{ object.locandina.url }}
 
Also, you need to read some about configuration on settings.MEDIA_ROOT and 
settings.MEDIA_URL, for use the imageField.


Regards,
Ronny


El jueves, 23 de mayo de 2013 03:57:02 UTC-4, Federico Erbea escribió:
>
> I'm not sure this is the correct method to use, so I'm open to suggestions.
> Practically I want to display the image retrieving the path where they are 
> saved from the database.
>
> In a class in models.py I have inserted:
>
> locandina = models.FilePathField( path = "C:/Users/Federico.Erbea/Google 
> Drive/Umore/apps/Database/static/Film/Locandina/", recursive=True)
>
> In the Admin the pull-down menu perfectly recovers the files I'm 
> interested in, allowing me to select the appropriate one
> I didn't understand very well how works FilePathField, so I don't know how 
> to pass the information to the template ... I need help, thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.