ANN: nosedjango 0.8.1

2010-08-22 Thread Jyrki Pulliainen
Hi there,

I'm pleased to announce new version of Django testing plugin for nose:
nosedjango version 0.8.1.

With this plugin you can write standard Nose unit tests for a Django
application. The plugin takes care of finding your applications
settings.py file and creating/tearing down test database. It also has
support for fixtures and it has experimental mechanism that wraps the
tests in transactions to speed up testing. This plugin works with
Django versions 1.0 or newer, though multi-db testing is supported
only when using django.test.TestCase.

The plugin is available in PyPI: http://pypi.python.org/pypi/NoseDjango/0.8.1

For those using Ubuntu, I've made packages available for 10.04 (Lucid
Lynx) in my PPA: https://launchpad.net/~jyrki-pulliainen/+archive/ppa

Source and issue tracker are available in Github: 
http://github.com/inoi/nosedjango

Cheers,
Jyrki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Best practice for auth.User/UserProfile division?

2010-08-22 Thread adambossy
I'm helping build a social networking site which makes heavy use of
django built-in User model and its relationship to other Users on the
site. We created a UserProfile per the django documentation [http://
docs.djangoproject.com/en/dev/topics/auth/#storing-additional-
information-about-users] that links to a single User object. Hence,
each time we make a database call involving a user, we retrieve the
UserProfile model via request.user.get_profile(), which occurs quite
frequently.

This seems rather odd, considering the user is passed to our views by
default, yet has no useful information. I'm no django expert, but my
assumption is that this design decision was made to allow decoupled
apps to work together. Since we're basically writing everything in-
house (generic apps always have *just enough* discrepancies to what we
want to do that we end up rewriting them), perhaps we're not reaping
this benefit. My intuition tells me that we should have ignore
django.contrib.auth.models.User and created our own to which
everything else on our site relates. Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: django-admin.py cleanup large scale

2010-08-22 Thread bfrederi
When I attempt to run a normal cleanup, the cleanup eventually loses
connection to the database and dies. I think I am going to have to
take the manual approach.

One thing that I wanted to point out is that I think you meant the SQL
equivalent is:

DELETE FROM django_session WHERE expire_date < '2010-01-01 1:23:45';

It should be less than, I believe. But that is very helpful, and I
will need to use that to clean up the session table manually.

On Aug 20, 8:44 pm, Russell Keith-Magee 
wrote:
> On Fri, Aug 20, 2010 at 11:51 PM, bfrederi  wrote:
> > I just wanted to know if anyone had an opinion or whether running a
> > django-admin.py cleanup on 40 million session rows might slow down or
> > lock up the database. I would like to do this cleanup ASAP, but I was
> > concerned it might cause some issues.
>
> It depends entirely on your database. If you're using MySQL with
> MyISAM tables, then almost certainly yes due to the table-level
> locking. Other databases may be affected for different reasons.
>
> If you're trying to evaluate the risk, the cleanup command executes
> the following:
>
> Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
>
> Which is the SQL equivalent of:
>
> DELETE FROM django_session WHERE expire_date > '2010-01-01 1:23:45';
>
> inside a the default transaction mode for your database. You'll have
> to consult your database documentation to establish whether that will
> pose a locking risk.
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: overriding the admin save in admin.py?

2010-08-22 Thread Aspontus
Hi.
Why don't you use save() method in model definition? See
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-methods
Maybe this will help you.
Cheers.

On 22 Sie, 14:27, gondor  wrote:
> i'm trying to override the save function so I can add set some values
> that were hidden before saving.  The problem is it doesn't seem to be
> using the save_model?  Does anyone know how this is done
>
> models.py
>
> class Contact(models.Model):
>   user = model.ForeignKey(User, editable=False)
>   notes = TextField('Notes', blank=True)
>
> admin.py
>
> class ContactAdmin(admin.ModelAdmin)
>   def save_model(self, request, obj, form, change):
>     obj.user = request.user
>     obj.save()
>
> Does anyone know how to do this or an alternative?
>
> thanx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Django on Mac OS X

2010-08-22 Thread Daniel França
thanks Andrew,
Now I've installed Pinax into a Virtualenv and it's working fine...I
installed only the libs versions that Pinax script install.

On Sat, Aug 21, 2010 at 10:55 PM, AndrewK  wrote:

> I've had the same problem on my Mac just now.
> It seems like this is an issue with django-timezones
>
> Try to install dev version from here:
> pip install -e git://
> github.com/brosner/django-timezones.git#egg=django-timezones
>
> Andrew
>
> On Aug 9, 1:40 pm, Daniel França  wrote:
> > Thanx for all the help,
> > I tried to run on Sqlite3, and I don't if it's bad or good news, but
> there's
> > error even in Sqlite3
> >
> > just when I tried to create the db (syncdb) I get just after I input my
> > users data or when I try to create a user in shell:
> > Traceback (most recent call last):
> >   File "manage.py", line 31, in 
> > execute_from_command_line()
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/__init__.py",
> > line 429, in execute_from_command_line
> > utility.execute()
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/__init__.py",
> > line 379, in execute
> > self.fetch_command(subcommand).run_from_argv(self.argv)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/base.py",
> > line 191, in run_from_argv
> > self.execute(*args, **options.__dict__)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/base.py",
> > line 218, in execute
> > output = self.handle(*args, **options)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/base.py",
> > line 347, in handle
> > return self.handle_noargs(**options)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/commands/syncdb.py",
> > line 103, in handle_noargs
> > emit_post_sync_signal(created_models, verbosity, interactive, db)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/sql.py",
> > line 185, in emit_post_sync_signal
> > interactive=interactive, db=db)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/dispatch/dispatcher.py",
> > line 162, in send
> > response = receiver(signal=self, sender=sender, **named)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/contrib/auth/management/__init__.py",
> > line 44, in create_superuser
> > call_command("createsuperuser", interactive=True)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/__init__.py",
> > line 166, in call_command
> > return klass.execute(*args, **defaults)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/core/management/base.py",
> > line 218, in execute
> > output = self.handle(*args, **options)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/contrib/auth/management/commands/createsuperuser.py",
> > line 134, in handle
> > User.objects.create_superuser(username, email, password)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/contrib/auth/models.py",
> > line 133, in create_superuser
> > u = self.create_user(username, email, password)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/contrib/auth/models.py",
> > line 129, in create_user
> > user.save(using=self._db)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/db/models/base.py",
> > line 435, in save
> > self.save_base(using=using, force_insert=force_insert,
> > force_update=force_update)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/db/models/base.py",
> > line 543, in save_base
> > created=(not record_exists), raw=raw)
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/dispatch/dispatcher.py",
> > line 162, in send
> > response = receiver(signal=self, sender=sender, **named)
> >   File
> > "/Users/danielfranca/workspace/django/view/tint/apps/account/models.py",
> > line 61, in create_account
> > account, created =
> > Account.objects.get_or_create(user=instance,timezone='America/Sao_Paulo')
> >   File
> >
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa
> ges/django/db/models/manager.py",
> > line 135, in get_or_create
> > return self.get_query_set().get_or_creat

What is the best way to manually create an HTML form from a ModelForm

2010-08-22 Thread orokusaki
Normally, I would do something like this:

{% for field in form.fields %}

{% field %}

{% endfor %}

What if I need:


{% one field %}



Some Title

{% another field %}



I want to be able to still use model forms and I don't want to hard
code {% if field == "email" %}Custom Stuff{% endif %}. Is there a good
way to do this, or a convention that I can use to ensure that my HTML
won't stop working when I update Django (I know that there is the
id_field_name convention, but I'm looking for a little more insight if
anyone out there does this alot.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: help with understanding tag cloud code

2010-08-22 Thread Mike Dewhirst

On 23/08/2010 11:17am, John Yeukhon Wong wrote:

Hi, I am confused with this piece of code. This is a code responsible
for building a tag cloud. It lives in the views.py

The part I don't understand is

 # Calculate tag, min and max counts.
 min_count = max_count = tags[0].bookmarks.count()

I never had used this 3 assignments in Python before. I also don't get
why it's tags[0]


x = y = z = 3
 is the same in Python as
z = 3
y = z
x = y

tags[0] is the first element of the tag list. In Python, lists and other 
iterables are zero-based.


hth


According to the book, it is iterating through the tag lists.
I really can't follow the logic there, and this also prevents me from
understanding the rest of the for loop

Thank you for any input!

//code begins

def tag_cloud_page(request):
 MAX_WEIGHT = 5
 tags = Tag.objects.order_by('name')
 # Calculate tag, min and max counts.
 min_count = max_count = tags[0].bookmarks.count()
 for tag in tags:
 tag.count = tag.bookmarks.count()
 if tag.count<  min_count:
  min_count = tag.count
 if max_count<  tag.count:
 max_count = tag.count
 # Calculate count range. Avoid dividing by zero.
 range = float(max_count - min_count)
 if range == 0.0:
 range = 1.0
 # Calculate tag weights.
 for tag in tags:
 tag.weight = int( MAX_WEIGHT * (tag.count - min_count) /
range)
 variables = RequestContext(request, { 'tags': tags })
 return render_to_response('tag_cloud_page.html', variables)

// code ends



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: the body of an http request

2010-08-22 Thread Yangmin Li
you can access from HttpRequest.REQUEST
*it is a dictionary like object.*
*more info, you can refer :
*
 http://docs.djangoproject.com/en/dev/ref/request-response/

On Mon, Aug 23, 2010 at 4:57 AM, Porya Jahandideh  wrote:

> Hi!
> How can I access the body of an http request using an HttpRequest object?
> Thanks in advance.
> --
> PJ
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



help with understanding tag cloud code

2010-08-22 Thread John Yeukhon Wong
Hi, I am confused with this piece of code. This is a code responsible
for building a tag cloud. It lives in the views.py

The part I don't understand is

# Calculate tag, min and max counts.
min_count = max_count = tags[0].bookmarks.count()

I never had used this 3 assignments in Python before. I also don't get
why it's tags[0]

According to the book, it is iterating through the tag lists.
I really can't follow the logic there, and this also prevents me from
understanding the rest of the for loop

Thank you for any input!

//code begins

def tag_cloud_page(request):
MAX_WEIGHT = 5
tags = Tag.objects.order_by('name')
# Calculate tag, min and max counts.
min_count = max_count = tags[0].bookmarks.count()
for tag in tags:
tag.count = tag.bookmarks.count()
if tag.count < min_count:
 min_count = tag.count
if max_count < tag.count:
max_count = tag.count
# Calculate count range. Avoid dividing by zero.
range = float(max_count - min_count)
if range == 0.0:
range = 1.0
# Calculate tag weights.
for tag in tags:
tag.weight = int( MAX_WEIGHT * (tag.count - min_count) /
range)
variables = RequestContext(request, { 'tags': tags })
return render_to_response('tag_cloud_page.html', variables)

// code ends

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Error: No module named tp.urls | Exception Type: ImportError

2010-08-22 Thread AJ
ROOT_URLCONF = 'tp.urls'


Just saw this in my settings.py


--AJ



On Aug 22, 8:33 pm, Aman  wrote:
> I recently installed Django on my personal Ubuntu Dev Server and have
> been trying with mod_wsgi (as mod_python is officially dead). I just
> had some breakthrough where I could see a little progress as a Django
> error and now I am stuck. Could you please tell me what might be wrong
> here?
>
> Debug Message/Trace:
> Environment:
>
> Request Method: GET
> Request URL:http://192.168.1.5/tp/
> Django Version: 1.1.1
> Python Version: 2.6.5
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
> get_response
>   83.                     request.path_info)
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> resolve
>   216.             for pattern in self.url_patterns:
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> _get_url_patterns
>   245.         patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> _get_urlconf_module
>   240.             self._urlconf_module =
> import_module(self.urlconf_name)
> File "/usr/lib/pymodules/python2.6/django/utils/importlib.py" in
> import_module
>   35.     __import__(name)
>
> Exception Type: ImportError at /
> Exception Value: No module named tp.urls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Error: No module named tp.urls | Exception Type: ImportError

2010-08-22 Thread AJ
ROOT_URLCONF: 'tp.urls'

I just saw that line in my settings.py

--AJ
`

On Aug 22, 8:33 pm, Aman  wrote:
> I recently installed Django on my personal Ubuntu Dev Server and have
> been trying with mod_wsgi (as mod_python is officially dead). I just
> had some breakthrough where I could see a little progress as a Django
> error and now I am stuck. Could you please tell me what might be wrong
> here?
>
> Debug Message/Trace:
> Environment:
>
> Request Method: GET
> Request URL:http://192.168.1.5/tp/
> Django Version: 1.1.1
> Python Version: 2.6.5
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
> get_response
>   83.                     request.path_info)
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> resolve
>   216.             for pattern in self.url_patterns:
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> _get_url_patterns
>   245.         patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
> File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
> _get_urlconf_module
>   240.             self._urlconf_module =
> import_module(self.urlconf_name)
> File "/usr/lib/pymodules/python2.6/django/utils/importlib.py" in
> import_module
>   35.     __import__(name)
>
> Exception Type: ImportError at /
> Exception Value: No module named tp.urls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Error: No module named tp.urls | Exception Type: ImportError

2010-08-22 Thread Aman
I recently installed Django on my personal Ubuntu Dev Server and have
been trying with mod_wsgi (as mod_python is officially dead). I just
had some breakthrough where I could see a little progress as a Django
error and now I am stuck. Could you please tell me what might be wrong
here?


Debug Message/Trace:
Environment:

Request Method: GET
Request URL: http://192.168.1.5/tp/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
get_response
  83. request.path_info)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
resolve
  216. for pattern in self.url_patterns:
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
_get_url_patterns
  245. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in
_get_urlconf_module
  240. self._urlconf_module =
import_module(self.urlconf_name)
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py" in
import_module
  35. __import__(name)

Exception Type: ImportError at /
Exception Value: No module named tp.urls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



the body of an http request

2010-08-22 Thread Porya Jahandideh
Hi!
How can I access the body of an http request using an HttpRequest object?
Thanks in advance.
-- 
PJ

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



A replacement for fixtures

2010-08-22 Thread Mark Sandstrom
Hello all,

I've created a test fixtures replacement named
factory_boybased on thoughtbot's
factory_girl for Ruby. Factories are extremely
maintainable and can make tests more readable. The framework can be used for
any Python project, and Django support is included.

- Have you ever added a field to a model and then realized that you needed
to update a bunch of tests because you were creating model instances in your
test setUp methods because dealing with fixtures can be really painful?
- Have you ever wondered what model values caused a method to return "April
1, 2010", and you couldn't tell from looking at the tests?
- Have you ever needed several slight variations of a model to test against
and you ended up duplicating the same fixture multiple times (which is now
somewhat hard to maintain)?
- Have you ever wondered if a certain example setup already exists in your
fixtures?

factory_boy is here to help alleviate some of these pains. I've found this
framework to be very useful and I wanted to share it with everyone. You may
find the framework especially useful if you're coming from Ruby/Rails and
you're missing that factory love. Interestingly, I'm not really from the
Ruby/Rails world... but I do appreciate good tools.

You can find documentation for factory_boy on the github page:
http://github.com/dnerdy/factory_boy

Getting started is as easy as:

easy_install factory_boy, or
pip install factory_boy

...which installs a package named 'factory'.

Enjoy!

- Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Stucked in Tutorial 3

2010-08-22 Thread Timothy Makobu
Also, if you haven't already, read all of this
http://docs.python.org/tutorial/index.html first before diving into Django.
A firm grip on Python is needed to learn Django and write good applications.

On Sun, Aug 22, 2010 at 8:53 PM, Nick  wrote:

> the problem is on the return HttpResponse (t.render(c)) line. Check
> that your indentation is correct
>
> On Aug 22, 9:51 am, craphunter  wrote:
> > Hi,
> >
> > I am very new in Django and Python. I am stucked in Tutorial 3 in part
> > "Write views that actually do something".
> >
> > I don't get it to run the index.html.
> >
> > I have copied: "
> > from django.template import Context, loader
> > from mysite.polls.models import Poll
> > from django.http import HttpResponse
> >
> > def index(request):
> > latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
> > t = loader.get_template('polls/index.html')
> > c = Context({
> > 'latest_poll_list': latest_poll_list,
> > })
> > return HttpResponse(t.render(c))
> > "
> > in my views.py.
> >
> > My setting file looks like this:
> > "TEMPLATE_DIRS = ("/home/username/dtest/mysite/templates"
> > # Put strings here, like "/home/html/django_templates" or "C:/www/
> > django/templates".
> > # Always use forward slashes, even on Windows.
> > # Don't forget to use absolute paths, not relative paths.
> > )
> >
> > I get this answer if I type this in my browser "http://127.0.0.1:8000/
> > polls":
> >
> >   File "/home/username/dtest/mysite/../mysite/polls/views.py", line 13
> >
> > return HttpResponse(t.render(c))
> >
> > SyntaxError: 'return' outside function
> >
> > What is wrong?
> >
> > Thanks for help!!!
> >
> > Craphunter
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Extract ForeignKey value from QuerySet

2010-08-22 Thread Goran
I'm Django novice and trying to get some search page. I'm lost almost
all day trying to extract ForeignKey value from my QuerySet without
success. Have city name which is ForeignKey in MyModel and I always
get result = []. Here is my last view.

from django.db.models import Q
from django.shortcuts import render_to_response
from Education.models import Cities, University

def search(request):
query = request.GET.get('q', '')
gquery = request.GET.get('g', '')  # This is city name
cities_list = Cities.objects.all()
if query:
qset = (
Q(field1__icontains=query) |
Q(field2__icontains=query) |
Q(field3__icontains=query)
)
results = University.objects.filter(qset).distinct()
results = results.select_related().get(city=gquery)
else:
results = []
return render_to_response('search/search.html',
{ 'query': query,
  'gquery': gquery,
  'cities_list': cities_list,
   'results': results })

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: gettext on windows - not up to date documentation on django site

2010-08-22 Thread Ramiro Morales
On Sun, Aug 22, 2010 at 5:17 PM, Jonathan  wrote:
> Right, my bad.
>
> Now that I installed it, the project which works great on Linux with
> translations and all, still does not have translations on Windows.
> What else should be configured?  (yes, I updated the system PATH
> correctly)

We will need more real technical details about what steps yo've
performed so far and at what point things started to fail to be able to
help you.

Regards,

-- 
Ramiro Morales  |  http://rmorales.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: gettext on windows - not up to date documentation on django site

2010-08-22 Thread Jonathan
Right, my bad.

Now that I installed it, the project which works great on Linux with
translations and all, still does not have translations on Windows.
What else should be configured?  (yes, I updated the system PATH
correctly)



On Aug 22, 9:42 pm, Baurzhan Ismagulov  wrote:
> On Sun, Aug 22, 2010 at 10:03:33AM -0700, Jonathan wrote:
> > Inhttp://docs.djangoproject.com/en/1.1/topics/i18n/localization/#gettex...
> > it says "Extract the contents of the bin\ directories in both files to
> > the same folder on your system".
> > I downloaded gettext-0.17.tar from the link provided and it did not
> > have a bin directory in it.
>
> > What should I do?
>
> Download gettext-runtime-X.zip and gettext-tools-X.zip.
>
> With kind regards,
> Baurzhan.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: installing DB engine

2010-08-22 Thread Reinout van Rees

On 08/22/2010 04:54 PM, matches wrote:

I'm trying to install the mySQL db adapter. Do I really need to
compile it before I can get it to work? Is there an easier way?


You ought to be able to grab an installer for your OS.  So
"aptitude install python-mysqldb" for ubuntu, for instance. I'm sure 
windows also has a clicky-clicky installer.



Reinout

--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: gettext on windows - not up to date documentation on django site

2010-08-22 Thread Baurzhan Ismagulov
On Sun, Aug 22, 2010 at 10:03:33AM -0700, Jonathan wrote:
> In 
> http://docs.djangoproject.com/en/1.1/topics/i18n/localization/#gettext-on-windows
> it says "Extract the contents of the bin\ directories in both files to
> the same folder on your system".
> I downloaded gettext-0.17.tar from the link provided and it did not
> have a bin directory in it.
> 
> What should I do?

Download gettext-runtime-X.zip and gettext-tools-X.zip.

With kind regards,
Baurzhan.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Stucked in Tutorial 3

2010-08-22 Thread Nick
the problem is on the return HttpResponse (t.render(c)) line. Check
that your indentation is correct

On Aug 22, 9:51 am, craphunter  wrote:
> Hi,
>
> I am very new in Django and Python. I am stucked in Tutorial 3 in part
> "Write views that actually do something".
>
> I don't get it to run the index.html.
>
> I have copied: "
> from django.template import Context, loader
> from mysite.polls.models import Poll
> from django.http import HttpResponse
>
> def index(request):
>     latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
>     t = loader.get_template('polls/index.html')
>     c = Context({
>         'latest_poll_list': latest_poll_list,
>     })
>     return HttpResponse(t.render(c))
> "
> in my views.py.
>
> My setting file looks like this:
> "TEMPLATE_DIRS = ("/home/username/dtest/mysite/templates"
>     # Put strings here, like "/home/html/django_templates" or "C:/www/
> django/templates".
>     # Always use forward slashes, even on Windows.
>     # Don't forget to use absolute paths, not relative paths.
> )
>
> I get this answer if I type this in my browser "http://127.0.0.1:8000/
> polls":
>
>   File "/home/username/dtest/mysite/../mysite/polls/views.py", line 13
>
>     return HttpResponse(t.render(c))
>
> SyntaxError: 'return' outside function
>
> What is wrong?
>
> Thanks for help!!!
>
> Craphunter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



gettext on windows - not up to date documentation on django site

2010-08-22 Thread Jonathan
In 
http://docs.djangoproject.com/en/1.1/topics/i18n/localization/#gettext-on-windows
it says "Extract the contents of the bin\ directories in both files to
the same folder on your system".
I downloaded gettext-0.17.tar from the link provided and it did not
have a bin directory in it.

What should I do?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Touch-ing django.wsgi doesn't reliably reload source code

2010-08-22 Thread Jim

> Graham

Thank you; that solved my problem.  That was a big help to me.  I
bought a couple of things from your wish list -- I hope that your
child enjoys them.

Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Stucked in Tutorial 3

2010-08-22 Thread craphunter
Hi,

I am very new in Django and Python. I am stucked in Tutorial 3 in part
"Write views that actually do something".

I don't get it to run the index.html.

I have copied: "
from django.template import Context, loader
from mysite.polls.models import Poll
from django.http import HttpResponse

def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(t.render(c))
"
in my views.py.

My setting file looks like this:
"TEMPLATE_DIRS = ("/home/username/dtest/mysite/templates"
# Put strings here, like "/home/html/django_templates" or "C:/www/
django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

I get this answer if I type this in my browser "http://127.0.0.1:8000/
polls":

  File "/home/username/dtest/mysite/../mysite/polls/views.py", line 13

return HttpResponse(t.render(c))

SyntaxError: 'return' outside function

What is wrong?

Thanks for help!!!

Craphunter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: searching stackedinline fields via search_fields in admin

2010-08-22 Thread ringemup
To add a filter that works with a related field, you have to write a
custom filterspec (which isn't really documented anywhere AFAIK).


To add the search on the related fields you just need to do what I
described above:

class CarAdmin(admin.ModelAdmin)
search_fields = ['model', 'radio_set__name']
...



On Aug 21, 4:49 pm, gondor  wrote:
> Here is what i'm trying to do:  I've looked at my code and I don't
> have a foreign key out reference from my model thus cannot find the
> inline fields.   reverse reference doens't seem to work either
>
> class CarRadio(modesl.Model):
>   name = models.ForeignKey('Car');
>   id = models.CharField(max_length='10', blank=True)
>
> class Car(models.Model):
>   owner = CharField(max_length='10')
>   name = CharField(max_length='10')
>   model = CharField(max_length='10')
>   typeofwheels = CharField(max_length='10')
>   ...
>
> class CarAdmin(admin.Model):
>   list_filter = {'model', 'name', 'typeofwheels'}    < --  I want to
> add list_filter from CarRadioInline here
>   search_fileds = {'model', 'name',}    < --  I wanted to add search
> fields from CarRadioInline here
>   inlines = [ CarRadioInline, ]
>
> class CarRadioInline(admin.StackedInline):
>   model = CarRadio
>   extra = 1
>   fieldset = ((None, {'fields': (('name', 'id'))})
>
> thanx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



installing DB engine

2010-08-22 Thread matches
I'm trying to install the mySQL db adapter. Do I really need to
compile it before I can get it to work? Is there an easier way?

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-us...@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: check email duplication at registration

2010-08-22 Thread John Yeukhon Wong
Hi, thank you for pointing out the problem!
Solved! Thank you!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Loop over a form's choices (radio button) and render it

2010-08-22 Thread Andreas Pfrengle
Hello Bill,

thanks for the code. It took half the weekend, but finally I built
upon this to get a radiobutton-iterator. This was a bit more
complicated, since the RadioInput widget has no own render-method, so
I needed to introduce a helper class that derives from RadioInput.
I've put the code here:


Would you mind testing it in your app to see if it also still behaves
like it should (the filter that should return the same as your
original version is called "checkboxiterator_named")?
Btw: Your version seems also to work fine on Django 1.2.1.

Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



overriding the admin save in admin.py?

2010-08-22 Thread gondor
i'm trying to override the save function so I can add set some values
that were hidden before saving.  The problem is it doesn't seem to be
using the save_model?  Does anyone know how this is done

models.py

class Contact(models.Model):
  user = model.ForeignKey(User, editable=False)
  notes = TextField('Notes', blank=True)


admin.py

class ContactAdmin(admin.ModelAdmin)
  def save_model(self, request, obj, form, change):
obj.user = request.user
obj.save()

Does anyone know how to do this or an alternative?

thanx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: defining models for unit testing only

2010-08-22 Thread Atamert Ölçgen
Hi,

> I wrote a django 'app', thats basically just a class that takes a
> Queryset, some other information, and then outputs an HttpResponse
> object (it does some other things too). How do I write unit tests for
> this class? The app itself does not contain any models, yet the
> functionality of the class depends on a model. The testing docs do not
> mention anything about this.

If you define some models in your tests.py file they will be available (only) 
when you run your tests.


-- 
Saygılarımla,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com
mu...@jabber.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Need some help with URL layout

2010-08-22 Thread Uwe Schuerkamp
Hi folks,

one more thing: In order to allow chaning of countries / regions, I
was thinking of adding a bit of html to the top of each page where a
user can select the country in the first popup, then the region popup
populates (pun intended ;-) the the regions for the selected country,
and one "submit" button that sets the new area of interest.

Naturally, all of the navigation urts on the left side of the page
would have to change as well, say from ranking/gr/ back to ranking/def/
hf/

How could that be accomplished? My Javascript-Fu is rather weak, and
I'd like to keep the mechanisms on the pages as simple as possible.

All the best & thanks again in advance for your comments & ideas,

Uwe

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Django-Cms Installation Error

2010-08-22 Thread Jagdeep Singh Malhi


On Aug 21, 10:17 pm, Marek Dudek  wrote:
> You have django 1.2.1, now I noticed
> I wasn't able to install any version of django-cms with django 1.2.1 and
> I tried 2.0.0, 2.0.1, 2.0.2 and 2.1.0-beta3
> Most up-to-date combination that I successfully installed is django
> 1.1.1 with django-cms 2.0.2.
> Hope this helps

Thanks
Is any version of Django -Cms is working with Django 1.2.1 ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.