Re: Validating ImageField width and height in admin site

2008-09-20 Thread Nick

Anybody?  I can't find a simple example of this anywhere so any help
would be great :)

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



DeprecationWarning: Non-ASCII character in models.py

2008-09-30 Thread Nick

Hi,

I've recently noticed that I'm getting the following in my Apache
error log...

DeprecationWarning: Non-ASCII character '\xc2' in file /var/www/django/
newsite/web/models.py on line 101, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details

Line 101 in my models.py file contains...

price_per_week = models.CharField(max_length=100, blank=True,
help_text="Calculate average price per week.  Include
£ prefix.Example: \"£150\",
\"£300-£320\", \"£100+\"")

I'm guessing it's something to do with the help_text, specifically the
£ symbol.

Can anybody shed some light on how I can fix this, presumably I need
to declare an encoding, or there is an encoding mismatch going on
somewhere?

Thanks,
Nick


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



Customising slugify filter

2008-11-19 Thread Nick

Hi,

I have the following strings which is run through the slugify filter
on my site:

"Business/Executives"

and it becomes "businessexecutives".  I'd like this to instead become
"business-executives" (as they are actually two seperate words).

I've tracked down the slugify filter to django/template/
defaultfilters.py, but can't get my head round the regular expressions
required to replace "/" with "-".

Alternatively, instead of changing the core Django install, can I
"extend" slugify in my own app to have this behaviour?

Any help very much appreciated!

Thanks,
Nick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Ad Management System

2008-11-23 Thread Nick

I'm exploring whether or not to use Django for redesigned website and
the only thing I haven't really been able to find out is whether there
is an existing, portable, robust solution for advertising management
on the site. This would need to control what advertising goes where,
track its performance, etc. Does this exist yet for Django? 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-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
-~--~~~~--~~--~--~---



HTTPS and URL form field validation

2008-12-15 Thread Nick

Hello,

My Django 1.0 project is installed on two different servers (one is
development, the other staging, both running Red Hat Linux). The main
page has a form with a URL field, and I'm using the built in Django
field validation, which determines whether the URL is valid by seeing
if it's reachable. My problem involves HTTPS URLs. (Plain old HTTP
URLS work fine on both servers.)

On the development server, an HTTPS URL validates just fine. On the
staging server, with the same URL, Django returns an error, saying
"This URL appears to be a broken link."

Using other facilities on the staging server, such as wget, I am able
to reach the HTTPS URL.

At first we discovered that the staging server was running Python
2.5.2 that had been installed without SSL support. However,
reinstalling with SSL support did not fix the problem. I believe the
system administrator also rebuilt mod_python.

Any ideas on what could be going on?

Thanks.

Nick

--~--~-~--~~~---~--~~
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: Django critter helps us code at the speed of light.

2009-03-12 Thread Nick

On Mar 11, 6:10 pm, Eric Walstad  wrote:
>
> Now you can have your pony AND a Django 
> Critter:http://starship.python.net/~ewalstad/django_critter.html
>

Excellent!  I think I prefer the Critter to the Pony...


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



Admin of an Admin for an E-Commerce Page

2009-07-05 Thread Nick

I'm looking to write an e-commerce page with very minimal admin
functionality, but which also has an extended admin that would
facilitate the rest of the basic admin tasks.  For example, the basic
admin could add products but shouldn't have to know any html or meta-
language to do so.  They just import a few pictures, add a
description, a few tags, and a price, amount in stock, along with
maybe a category and type of layout, then hit the 'add' button.  The
extended admin, would be responsible for creating the different
layouts to be chosen from, along with adding additional categories,
adjusting SEO meta info, portlets, etc...  The default admin module in
Django, along with a few Django e-commerce options I have looked into,
all seem to lump everything into the same admin area.  Is there
anything out there that separates this functionality or should I look
into rolling my own?  And if the answer is roll my own, do you have
any tips as to where to start?  I'm pretty new to python & django so
pardon me if I'm missing something obvious.

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



Django-Storages

2009-09-23 Thread Nick

Hey everyone,

I'm working on setting up an app to upload images to s3.  I am using
David Larlet's djang-storages backends and am running into a pretty
annoying problem.  When I try to save an entry through the admin I get
the following error:

Storage module "backends.s3" does not define a "s3storage" class.

I installed django-storages using python setup.py install.  It created
an egg directory in my site-packages directory (the same place where
my root django directory is located).

I've hooked this thing up every way I know how.  My settings.py file
looks like this:

DEFAULT_FILE_STORAGE = 'backends.s3.S3Storage'
#Access Keye provided by Amazon
AWS_ACCESS_KEY_ID = ''
#Secret Key provided by amazon
AWS_SECRET_KEY_ID = '***'
#Bucket name where files will be stored
AWS_STORAGE_BUCKET_NAME = 'content.newsok.com'
AWS_CALLING_FORMAT = 'REGULAR'

Also not sure if it will accept this Calling Format.

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



Error Message regarding len()

2009-09-25 Thread Nick

I'm using the django-storages backends from David Larlet to upload
images to s3 from inside the admin.  When i try to run everything I
get an error:

object of type 'NoneType' has no len()

Here is my model:

from django.db import models
from django.core.files.storage import default_storage as s3_storage




class StateFair (models.Model):
Content_Choices = (
('photo', 'Photo'),
('video', 'Video'),
('text', 'Text'),
('audio', 'Audio'),
)
Name = models.CharField(max_length=30, blank=False, unique=True)
contentType = models.CharField('Type of Content', max_length=5,
choices=Content_Choices, blank=True)
thumbNailUpload = models.ImageField('Thumbnail Upload',
storage=s3_storage, upload_to='/news', height_field=None,
width_field=None, max_length=100, blank=True, null=True)
ThumbNail = models.CharField('Thumbnail Name', max_length=50,
blank=True)
imageUpload = models.ImageField('Full Size Image Upload',
storage=s3_storage, upload_to='/news, height_field=None,
width_field=None, max_length=100, blank=True, null=True)
Image = models.CharField('Image name (use jpg, png, etc.)',
max_length=30, blank=True)
Cutline = models.TextField('Caption or Cutline', blank=True)
VideoID = models.IntegerField(max_length=30, null=True,
blank=True)
TextBlock = models.TextField('Text Block', blank=True)
AudioID = models.CharField('Audio FileName', max_length=40,
blank=True)
pubDate = models.DateTimeField('updated', blank=True)

class Meta:
ordering = ("?")
--~--~-~--~~~---~--~~
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: Error Message regarding len()

2009-09-25 Thread Nick

something like this?

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/StoryWall/statefair/16/
Django Version: 1.2 pre-alpha SVN-11434
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.admin',
 'MMprojects.StoryWall']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in wrapper
  226. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
inner
  186. return view(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  240. res = func(*args, **kw)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in change_view
  830. self.save_model(request, new_object, form,
change=True)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in save_model
  557. obj.save()
File "C:\Python25\lib\site-packages\django\db\models\base.py" in save
  410. self.save_base(force_insert=force_insert,
force_update=force_update)
File "C:\Python25\lib\site-packages\django\db\models\base.py" in
save_base
  473. values = [(f, None, (raw and getattr
(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
in pre_save
  252. file.save(file.name, file, save=False)
File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
in save
  91. self.name = self.storage.save(name, content)
File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
save
  46. name = self.get_available_name(name)
File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
get_available_name
  71. while self.exists(name):
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\backends\s3.py" in exists
  105. response = self.connection._make_request('HEAD',
self.bucket, name)
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in _make_request
  273. self._add_aws_auth_header(final_headers, method,
bucket, key, query_args)
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in _add_aws_auth_header
  299. "AWS %s:%s" % (self.aws_access_key_id, encode
(self.aws_secret_access_key, c_string))
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in encode
  84. b64_hmac = base64.encodestring(hmac.new
(aws_secret_access_key, str, sha).digest()).strip()
File "C:\Python25\lib\hmac.py" in new
  121. return HMAC(key, msg, digestmod)
File "C:\Python25\lib\hmac.py" in __init__
  64. if len(key) > blocksize:

Exception Type: TypeError at /admin/StoryWall/statefair/16/
Exception Value: object of type 'NoneType' has no len()


On Sep 25, 2:54 pm, Brian McKeever  wrote:
> A stack trace would be more useful.
>
> On Sep 25, 12:07 pm, Nick  wrote:
>
> > I'm using the django-storages backends from David Larlet to upload
> > images to s3 from inside the admin.  When i try to run everything I
> > get an error:
>
> > object of type 'NoneType' has no len()
>
> > Here is my model:
>
> > from django.db import models
> > from django.core.files.storage import default_storage as s3_storage
>
> > class StateFair (models.Model):
> >     Content_Choices = (
> >         ('photo', 'Photo'),
> >         ('video', 'Video'),
> >         ('text', 'Text'),
> >         ('audio', 'Audio'),
> >     )
> >     Name = models.CharField(max_length=30, blank=False, unique=True)
> >     contentType = models.CharField('Type of Content', max_length=5,
> > choices=Content_Choices, blank=True)
> >     thumbNailUpload = models.ImageField('Thum

Re: Error Message regarding len()

2009-09-25 Thread Nick

You were exactly right, it was a sloppy mistake.  Thanks for looking
at this.  Time to move on to the next error I just got.

On Sep 25, 3:40 pm, Brian McKeever  wrote:
> I'd guess that you didn't set AWS_SECRET_ACCESS_KEY correctly in your
> settings.
>
> http://code.welldev.org/django-storages/wiki/S3Storage
>
> On Sep 25, 2:12 pm, Nick  wrote:
>
> > something like this?
>
> > Environment:
>
> > Request Method: POST
> > Request URL:http://localhost:8000/admin/StoryWall/statefair/16/
> > Django Version: 1.2 pre-alpha SVN-11434
> > Python Version: 2.5.4
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'django.contrib.admin',
> >  'django.contrib.admin',
> >  'MMprojects.StoryWall']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   92.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in wrapper
> >   226.                 return self.admin_site.admin_view(view)(*args,
> > **kwargs)
> > File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   44.         response = view_func(request, *args, **kwargs)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
> > inner
> >   186.             return view(request, *args, **kwargs)
> > File "C:\Python25\lib\site-packages\django\db\transaction.py" in
> > _commit_on_success
> >   240.                 res = func(*args, **kw)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in change_view
> >   830.                 self.save_model(request, new_object, form,
> > change=True)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in save_model
> >   557.         obj.save()
> > File "C:\Python25\lib\site-packages\django\db\models\base.py" in save
> >   410.         self.save_base(force_insert=force_insert,
> > force_update=force_update)
> > File "C:\Python25\lib\site-packages\django\db\models\base.py" in
> > save_base
> >   473.                         values = [(f, None, (raw and getattr
> > (self, f.attname) or f.pre_save(self, False))) for f in non_pks]
> > File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> > in pre_save
> >   252.             file.save(file.name, file, save=False)
> > File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> > in save
> >   91.         self.name = self.storage.save(name, content)
> > File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> > save
> >   46.         name = self.get_available_name(name)
> > File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> > get_available_name
> >   71.         while self.exists(name):
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \backends\s3.py" in exists
> >   105.         response = self.connection._make_request('HEAD',
> > self.bucket, name)
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in _make_request
> >   273.             self._add_aws_auth_header(final_headers, method,
> > bucket, key, query_args)
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in _add_aws_auth_header
> >   299.             "AWS %s:%s" % (self.aws_access_key_id, encode
> > (self.aws_secret_access_key, c_string))
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in encode
> >   84.     b64_hmac = base64.encodestring(hmac.new
> > (aws_secret_access_key, str, sha).digest()).strip()
> > File "C:\Python25\lib\hmac.py" in new
> >   121.     return HMAC(key, msg, digestmod)
> > File "C:\Python25\lib\hmac.py" in __init__
> >   64.         if len(key) > blocksize:
>
> > Exception Type: TypeError at /admin/StoryWal

Re: lighttpd + fcgi + FORCE_SCRIPT_NAME = admin grief

2008-08-21 Thread Nick

Hi Malcolm,

Great; James' suggestion does work perfectly (stupidly obvious; it was
of course the one thing I hadn't tried) as suggested. If you're trying
to figure out how I got to this recipe I blindly followed the
instructions here:

http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#ChangedthewayURLpathsaredetermined

Which maybe need to change given that the rest of the config is plain-
vanilla-as-per-the-tutorial?

Regards,

Nick

On Aug 21, 6:08 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-08-21 at 10:02 -0700, James Matthews wrote:
> > Try FORCE_SCRIPT_NAME="" I use it and it works nicely
>
> It's always interesting after landing a feature like this that has a few
> edge cases to see where the problems distribute themselves. Turns out
> there are a lot of people using the lighttpd + fastcgi setup -- and this
> would all be a lot easier if lighttpd had some way of passing through
> the original, un-rewritten URL as well as the rewritten version (Apache
> has this facility, for example).
>
> My point here (I have one! Honest) is that I'm slowly gathering clues as
> to what pieces the documentation needs to make a bit clearer and how to
> tweak the examples to hit some common cases. That being said, I'd also
> like people to *understand* what's going on, rather than having to
> follow a "this is what worked for somebody else, so I tried it with hope
> in my heart" cut-and-paste method of configuration. Over time, we'll
> tweak the docs a bit and maybe change the quiet robustness of the code.
>
> But, for right now: the script name portion should not end in a slash.
> It is appended to the front of every generated URL. The path info
> portion (the bit you mention in Django's URLConf) will always start with
> a slash, although you don't include the leading slash in your URL conf,
> because that's already matched by the controlling URL resolver portion
> (your project's main URLConf file is essentially used as an include() in
> Django's root resolver).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Validating ImageField width and height in admin site

2008-09-09 Thread Nick

Hi,

I'm looking to validate my ImageField images in the admin site.  If
they are a specific size, then the whole record will save - if they
are not, then the user will be returned to the form with a validation
error message.

I've seen get_image_dimensions, but I'm not sure how this would be
used within the save method to prevent the record from saving if the
image size were incorrect.

Any help would be very much appreciated :)

Thanks,
Nick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



localhost:8000 problem

2009-03-28 Thread nick

I am a django newbie.
The first example I tried from django's tutorial "mysite", ran python
manage.py runserver.
Server runs with no errors but my web browser (firefox) get "Firefox
offline mode error" and not django 404 errors.
I tried different localhost ports, but same error. My browser doesn't
seem to communicate with django's lightweight server.
What to 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-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: localhost:8000 problem

2009-03-28 Thread nick

Right after I click "post" to that problem,  I realized that "Work
Offline" was checked.
It works now. Thank you Karen for prompt reply, I appreciate it. I am
sure there are more
to come :-)


On Mar 28, 4:50 pm, Karen Tracey  wrote:
> On Sat, Mar 28, 2009 at 5:44 PM, nick  wrote:
>
> > I am a django newbie.
> > The first example I tried from django's tutorial "mysite", ran python
> > manage.py runserver.
> > Server runs with no errors but my web browser (firefox) get "Firefox
> > offline mode error" and not django 404 errors.
> > I tried different localhost ports, but same error. My browser doesn't
> > seem to communicate with django's lightweight server.
> > What to do?
>
> Go to the Firefox File menu and see if "Work Offline" is checked.  If it is,
> select it, so that it becomes unchecked.  Then Firefox won't stop any
> attempt to connect before even trying.  If "Work offline" is not checked, I
> have no idea.  It sounds like a Firefox problem so I'd probably try a
> different browser, and assuming that works pursue tracking down what the
> problem with Firefox is.
>
> Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django 1.0 Template Book

2009-03-30 Thread nick

Has anyone bought and read "Django 1.0 Template Development" by Scott
Newman? I'd like to know your opinion before I get it.

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



csv download link or views that the modify more than one template...

2009-04-16 Thread Nick

I'm interested in returning both an html view (as a template) and a
link to a csv file (either as a template or using the CSV module) in
response to a query (GET or POST).  Is there a way to both of these
actions simultaneously without hitting a database twice and without
writing a file to disk?  Seems like it should be possible, but all the
view examples I can find only return one modified template at a time.

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



Need to upload outside of MEDIA_ROOT, but I get SuspiciousOperation error

2009-06-22 Thread Nick

Hi,

I need to be able to upload using the admin interface to outside of
MEDIA_ROOT.  For example, my MEDIA_ROOT is "/home/site.com/media/" but
I want to upload to "/home/uploads/".  Whenever I try to do this by
setting an absolute upload path I get a SuspiciousOperation error.
I'd like to do this so all uploaded files are contained outside of
SVN's version control.

Is this possible?  I've tried "chown"ing my uploads directory to
apache:apache but this didn't help.  Any ideas?

Thanks,
Nick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



starting a project in windows xp

2009-10-19 Thread Nick

FYI,

If anyone in general has trouble starting a new project in Windows xp,
this might help you. When I first tried creating a project, I cd'd
into the appropriate directory in a cmd prompt and then typed the path
to the django-admin.py file, then startproject, and the project name.
All this would do is open the django-admin.py file, not actually
execute it.

So, before the path to the django-admin.py file, type the path to
python.exe, a space, and then the path to django-admin.py, then
startproject, then 'project name'.

You have to pass the path to django-admin.py as an argument to
python.exe so it actually executes the file rather than just opening
it.

I hope this helps if it pertains to you.

Nick

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



feedparser import error

2009-12-18 Thread Nick
Hello,

I've installed pydelicious and it seems to work until it imports
feedparser.py. I've installed feedparser.py, and it's in the same
directory as pydelicious. When pydelicious tries to import
feedparser.py my app crashes. I get 'No module named feedparser'. Does
anyone know why feedparser.py isn't importing? Has anyone else had
this problem? I'm using python 26 on windows xp.

Thank you,

Nick

--

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.




Dynamic URL for representatives DB

2010-01-31 Thread Nick
Thanks in advance for anyone answering this thread.

I am building a DB of local government representatives. My goal is to
spit out a general list of the reps and a detailed bio page for each
rep.

The URL structure I would like to have is 'government/reps/list' for a
list of all of the Reps and 'government/reps/
REPSLASTNAME_REPSFIRSTNAME' for the single bio view.

Here is my model:
class Rep(models.model):

Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
First_Name = models.CharField('First Name', max_length=100,
blank=True)
Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
City = models.CharField(max_length=100, blank=True)
Phone = models.CharField(max_length=15, help_text="Use the form
xxx-xxx-", blank=True)
Email = models.EmailField(max_length=100, blank=True)
Contact_URL = models.URLField(max_length=200, blank=True)
DOB = models.DateField('Date of Birth',blank=True, null=True)
Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images/mugs', height_field=None,
width_field=None, max_length=300, blank=True)
Committees = models.ManyToManyField('Committees', blank=True)
Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)

def __unicode__(self):
return u"%s, %s" % (self.Last_Name, self.First_Name)

class Meta:
abstract = False


Here is my view:

from Government.Reps.models import *
from django.shortcuts import render_to_response
from django.http import Http404

def index(request):
rep_list_view = Rep.objects.all().order_by('Last_Name')
return render_to_response('Government/repsAll.html', {'allReps':
rep_list_view})

def detail(request, (Last_Name, First_Name)):
try:
r = Rep.objects.all().order_by('Last_Name', 'First_Name')
except Rep.DoesNotExist:
raise Http404
return render_to_response('Government/repsSingle.html',
{'singleRep': r})


Here is my URL conf:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^Government/', include('Government.foo.urls')),

# Uncomment the admin/doc line below and add
'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^reps/(P?_\d+)/$',
'Government.Reps.views.detail'),

I think that I am either overthinking this or way UNDER thinking it.

This is my first go at a template being called via variables passed in
the URL. I have a good background in templates and the models portion
of django but am sorely lacking in my understanding of views and URL
confs.

Thanks again,
Nick

-- 
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: Dynamic URL for representatives DB

2010-01-31 Thread Nick
Daniel,

Thanks for the quick reply.  I have made the adjustments to the URLS
and the views and am getting a 404 error

Not Found

The requested URL /Government/reps/Prater_David was not found on this
server. (using the entry for David Prater)

I'm not really sure why it isn't picking up the URL.



On Jan 31, 2:05 pm, Daniel Roseman  wrote:
> On Jan 31, 7:29 pm, Nick  wrote:
>
>
>
> > Thanks in advance for anyone answering this thread.
>
> > I am building a DB of local government representatives. My goal is to
> > spit out a general list of the reps and a detailed bio page for each
> > rep.
>
> > The URL structure I would like to have is 'government/reps/list' for a
> > list of all of the Reps and 'government/reps/
> > REPSLASTNAME_REPSFIRSTNAME' for the single bio view.
>
> > Here is my model:
> > class Rep(models.model):
> >  > that I'm ommitting>
> >     Type = models.CharField(max_length=100, choices=Type_Choices,
> > blank=True)
> >     Last_Name = models.CharField('Last Name', max_length=100,
> > blank=True)
> >     First_Name = models.CharField('First Name', max_length=100,
> > blank=True)
> >     Position = models.CharField('Position', help_text="Only used for
> > non-council City and Local officials", max_length=100, blank=True,
> > choices=Position_Choices)
> >     Party = models.CharField(max_length=3, choices=Party_Choices,
> > blank=True)
> >     District = models.IntegerField(help_text="For State, Federal and
> > County Commissioners", blank=True, null=True)
> >     Ward = models.IntegerField(help_text="For City Councils",
> > blank=True, null=True)
> >     City = models.CharField(max_length=100, blank=True)
> >     Phone = models.CharField(max_length=15, help_text="Use the form
> > xxx-xxx-", blank=True)
> >     Email = models.EmailField(max_length=100, blank=True)
> >     Contact_URL = models.URLField(max_length=200, blank=True)
> >     DOB = models.DateField('Date of Birth',blank=True, null=True)
> >     Gender = models.CharField(blank=True, max_length=2,
> > choices=Gender_Choices)
> >     Begin_Serve = models.IntegerField('Began Serving in', blank=True,
> > null=True)
> >     End_Serve = models.IntegerField('Term Limited in', blank=True,
> > null=True)
> >     MugShot = models.ImageField('Mug Shot Upload', help_text="images
> > are to be no larger that 150x200", storage=s3_storage,
> > upload_to='newsok/images/Government/images/mugs', height_field=None,
> > width_field=None, max_length=300, blank=True)
> >     Committees = models.ManyToManyField('Committees', blank=True)
> >     Approp_Committee = models.ManyToManyField('Approp_Committees',
> > blank=True)
>
> >     def __unicode__(self):
> >         return u"%s, %s" % (self.Last_Name, self.First_Name)
>
> >     class Meta:
> >         abstract = False
>
> > Here is my view:
>
> > from Government.Reps.models import *
> > from django.shortcuts import render_to_response
> > from django.http import Http404
>
> > def index(request):
> >     rep_list_view = Rep.objects.all().order_by('Last_Name')
> >     return render_to_response('Government/repsAll.html', {'allReps':
> > rep_list_view})
>
> > def detail(request, (Last_Name, First_Name)):
> >     try:
> >         r = Rep.objects.all().order_by('Last_Name', 'First_Name')
> >     except Rep.DoesNotExist:
> >         raise Http404
> >     return render_to_response('Government/repsSingle.html',
> > {'singleRep': r})
>
> > Here is my URL conf:
>
> > from django.conf.urls.defaults import *
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns('',
> >     # Example:
> >     # (r'^Government/', include('Government.foo.urls')),
>
> >     # Uncomment the admin/doc line below and add
> > 'django.contrib.admindocs'
> >     # to INSTALLED_APPS to enable admin documentation:
> >     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> >     # Uncomment the next line to enable the admin:
> >     (r'^admin/', include(admin.site.urls)),
> >     (r'^reps/(P?_\d+)/$',
> > 'Government.Reps.views.detail'),
>
> > I

Re: Dynamic URL for representatives DB

2010-01-31 Thread Nick
Just checked again and I'm getting the output I was looking for.
Thanks for the help. I guess the server was just taking a little time
to pick up changes to the URL confs.



On Jan 31, 5:58 pm, Nick  wrote:
> Daniel,
>
> Thanks for the quick reply.  I have made the adjustments to the URLS
> and the views and am getting a 404 error
>
> Not Found
>
> The requested URL /Government/reps/Prater_David was not found on this
> server. (using the entry for David Prater)
>
> I'm not really sure why it isn't picking up the URL.
>
> On Jan 31, 2:05 pm, Daniel Roseman  wrote:
>
> > On Jan 31, 7:29 pm, Nick  wrote:
>
> > > Thanks in advance for anyone answering this thread.
>
> > > I am building a DB of local government representatives. My goal is to
> > > spit out a general list of the reps and a detailed bio page for each
> > > rep.
>
> > > The URL structure I would like to have is 'government/reps/list' for a
> > > list of all of the Reps and 'government/reps/
> > > REPSLASTNAME_REPSFIRSTNAME' for the single bio view.
>
> > > Here is my model:
> > > class Rep(models.model):
> > >  > > that I'm ommitting>
> > >     Type = models.CharField(max_length=100, choices=Type_Choices,
> > > blank=True)
> > >     Last_Name = models.CharField('Last Name', max_length=100,
> > > blank=True)
> > >     First_Name = models.CharField('First Name', max_length=100,
> > > blank=True)
> > >     Position = models.CharField('Position', help_text="Only used for
> > > non-council City and Local officials", max_length=100, blank=True,
> > > choices=Position_Choices)
> > >     Party = models.CharField(max_length=3, choices=Party_Choices,
> > > blank=True)
> > >     District = models.IntegerField(help_text="For State, Federal and
> > > County Commissioners", blank=True, null=True)
> > >     Ward = models.IntegerField(help_text="For City Councils",
> > > blank=True, null=True)
> > >     City = models.CharField(max_length=100, blank=True)
> > >     Phone = models.CharField(max_length=15, help_text="Use the form
> > > xxx-xxx-", blank=True)
> > >     Email = models.EmailField(max_length=100, blank=True)
> > >     Contact_URL = models.URLField(max_length=200, blank=True)
> > >     DOB = models.DateField('Date of Birth',blank=True, null=True)
> > >     Gender = models.CharField(blank=True, max_length=2,
> > > choices=Gender_Choices)
> > >     Begin_Serve = models.IntegerField('Began Serving in', blank=True,
> > > null=True)
> > >     End_Serve = models.IntegerField('Term Limited in', blank=True,
> > > null=True)
> > >     MugShot = models.ImageField('Mug Shot Upload', help_text="images
> > > are to be no larger that 150x200", storage=s3_storage,
> > > upload_to='newsok/images/Government/images/mugs', height_field=None,
> > > width_field=None, max_length=300, blank=True)
> > >     Committees = models.ManyToManyField('Committees', blank=True)
> > >     Approp_Committee = models.ManyToManyField('Approp_Committees',
> > > blank=True)
>
> > >     def __unicode__(self):
> > >         return u"%s, %s" % (self.Last_Name, self.First_Name)
>
> > >     class Meta:
> > >         abstract = False
>
> > > Here is my view:
>
> > > from Government.Reps.models import *
> > > from django.shortcuts import render_to_response
> > > from django.http import Http404
>
> > > def index(request):
> > >     rep_list_view = Rep.objects.all().order_by('Last_Name')
> > >     return render_to_response('Government/repsAll.html', {'allReps':
> > > rep_list_view})
>
> > > def detail(request, (Last_Name, First_Name)):
> > >     try:
> > >         r = Rep.objects.all().order_by('Last_Name', 'First_Name')
> > >     except Rep.DoesNotExist:
> > >         raise Http404
> > >     return render_to_response('Government/repsSingle.html',
> > > {'singleRep': r})
>
> > > Here is my URL conf:
>
> > > from django.conf.urls.defaults import *
>
> > > # Uncomment the next two lines to enable the admin:
> > > from django.contrib import admin
> > > admin.autodiscover()
>
> > > urlpatterns = patterns('',
> &g

Re: Dynamic URL for representatives DB

2010-01-31 Thread Nick
I'm definitely going to continue looking into this. But if you have
any advice on how I can store the rest of the fields from the DB to
call up on the individual reps pages I would greatly appreciate it.
Right now I am only pulling in the last name and first name and need
to return all of the object in the Rep table.

Thanks again.

Nick

On Jan 31, 10:08 pm, Nick  wrote:
> Just checked again and I'm getting the output I was looking for.
> Thanks for the help. I guess the server was just taking a little time
> to pick up changes to the URL confs.
>
> On Jan 31, 5:58 pm, Nick  wrote:
>
> > Daniel,
>
> > Thanks for the quick reply.  I have made the adjustments to the URLS
> > and the views and am getting a 404 error
>
> > Not Found
>
> > The requested URL /Government/reps/Prater_David was not found on this
> > server. (using the entry for David Prater)
>
> > I'm not really sure why it isn't picking up the URL.
>
> > On Jan 31, 2:05 pm, Daniel Roseman  wrote:
>
> > > On Jan 31, 7:29 pm, Nick  wrote:
>
> > > > Thanks in advance for anyone answering this thread.
>
> > > > I am building a DB of local government representatives. My goal is to
> > > > spit out a general list of the reps and a detailed bio page for each
> > > > rep.
>
> > > > The URL structure I would like to have is 'government/reps/list' for a
> > > > list of all of the Reps and 'government/reps/
> > > > REPSLASTNAME_REPSFIRSTNAME' for the single bio view.
>
> > > > Here is my model:
> > > > class Rep(models.model):
> > > >  > > > that I'm ommitting>
> > > >     Type = models.CharField(max_length=100, choices=Type_Choices,
> > > > blank=True)
> > > >     Last_Name = models.CharField('Last Name', max_length=100,
> > > > blank=True)
> > > >     First_Name = models.CharField('First Name', max_length=100,
> > > > blank=True)
> > > >     Position = models.CharField('Position', help_text="Only used for
> > > > non-council City and Local officials", max_length=100, blank=True,
> > > > choices=Position_Choices)
> > > >     Party = models.CharField(max_length=3, choices=Party_Choices,
> > > > blank=True)
> > > >     District = models.IntegerField(help_text="For State, Federal and
> > > > County Commissioners", blank=True, null=True)
> > > >     Ward = models.IntegerField(help_text="For City Councils",
> > > > blank=True, null=True)
> > > >     City = models.CharField(max_length=100, blank=True)
> > > >     Phone = models.CharField(max_length=15, help_text="Use the form
> > > > xxx-xxx-", blank=True)
> > > >     Email = models.EmailField(max_length=100, blank=True)
> > > >     Contact_URL = models.URLField(max_length=200, blank=True)
> > > >     DOB = models.DateField('Date of Birth',blank=True, null=True)
> > > >     Gender = models.CharField(blank=True, max_length=2,
> > > > choices=Gender_Choices)
> > > >     Begin_Serve = models.IntegerField('Began Serving in', blank=True,
> > > > null=True)
> > > >     End_Serve = models.IntegerField('Term Limited in', blank=True,
> > > > null=True)
> > > >     MugShot = models.ImageField('Mug Shot Upload', help_text="images
> > > > are to be no larger that 150x200", storage=s3_storage,
> > > > upload_to='newsok/images/Government/images/mugs', height_field=None,
> > > > width_field=None, max_length=300, blank=True)
> > > >     Committees = models.ManyToManyField('Committees', blank=True)
> > > >     Approp_Committee = models.ManyToManyField('Approp_Committees',
> > > > blank=True)
>
> > > >     def __unicode__(self):
> > > >         return u"%s, %s" % (self.Last_Name, self.First_Name)
>
> > > >     class Meta:
> > > >         abstract = False
>
> > > > Here is my view:
>
> > > > from Government.Reps.models import *
> > > > from django.shortcuts import render_to_response
> > > > from django.http import Http404
>
> > > > def index(request):
> > > >     rep_list_view = Rep.objects.all().order_by('Last_Name')
> > > >     return render_to_response('Government/repsAll.html', {'allReps':
> > >

Re: Dynamic URL for representatives DB

2010-02-01 Thread Nick
You are exactly right.  Thanks, this was a learning curve I was having
trouble getting over.  You have been an immense help and are a credit
to this online community.

On Feb 1, 3:42 am, Daniel Roseman  wrote:
> On Feb 1, 4:30 am, Nick  wrote:
>
> > I'm definitely going to continue looking into this. But if you have
> > any advice on how I can store the rest of the fields from the DB to
> > call up on the individual reps pages I would greatly appreciate it.
> > Right now I am only pulling in the last name and first name and need
> > to return all of the object in the Rep table.
>
> > Thanks again.
>
> > Nick
>
> Not entirely sure what you're asking. You're sending the full Rep
> object to the template, so you can access any of its fields from
> there:
>
> {{ singleRep.First_Name }}
> {{ singleRep.Position }}
> {{ singleRep.Party }} (or you might want to use
> {{ singleRep.get_party_choices }} here)
>
> etc.
> --
> DR.

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



URL configuration

2010-07-06 Thread Nick
I currently have several django projects on one server. I am working
with subdomains for some of these projects and I'd like the base URL
to be a little different than the default behavior. I am working with
modwsgi and apache.

I have a project called MyProject.

I have a subdomain set up at myproject.mysite.com

the project's base url is myproejct.mysite.com/myproject
the admin is myproject.mysite.com/myprojects/admin

what I would like is myrpojects.mysite.com/admin

How would I accomplish this

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



Query raises a DoesNotExist error

2010-07-07 Thread Nick
I am working on a form to resend an account activation email for newly
registered users who did not receive their first email.

The form is currently raising a DoesNotExist error and I can't figure
out why:

Here is the activation code:

class resend_activation(forms.Form):
email = forms.EmailField(label="E-Email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
FullProfile.objects.get(email=email)
except FullProfile.DoesNotExist:

 test =
FullProfile.objects.get(email=self.cleaned_data['email'])
 raise forms.ValidationError("%s" % (test))

def send(self):
email = self.cleaned_data['email']
user = FullProfile.objects.get(email=email)
thread = Thread(target=send_activation, args=[user])
thread.setDaemon(True)
thread.start()

Here is the view:

def resend(request):
if request.method == 'POST':
form = resend_activation(request.POST)
if form.is_valid():
resend = form.send()


return HttpResponseRedirect("../activate_message")
else:
form = resend_activation()

return render_to_response("registration/resend.html", {'form':
form })

Everytime I try to use the form I get a "FullProfile matching query
does not exist." error. But in the above code I added a little test to
see if the query was returning any values and it is. I have no clue
why this portion of process is holding up everything else.

-- 
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: Query raises a DoesNotExist error

2010-07-07 Thread Nick
A lot of this is me trying to find out why it's failing. The problem
I'm getting is that there is a FullProfile associated with the email
address. When i go through the steps in the shell it works perfectly.
When I run it through the form it throws an error. If you look at the
custom ValidationError I am checking to see if I can get an error to
spit out any information for that profile that is being submitted in
the form.

Each time I get the error to return the test information without fail.
If I do try to submit an address that isn't in the FullProfile table
then I get a different DoesNotExist error, it jumps right over the
custom validation error.

So the custom ValidationError triggers when there is a profile in the
DB and the default debug page DoesNotExist triggers when there isn't a
FulLProfile associated with the email address.

On Jul 7, 12:42 pm, Nuno Maltez  wrote:
> At a glance:
>
> >        try:
> >            FullProfile.objects.get(email=email)
> >        except FullProfile.DoesNotExist:
>
> >         test =
> > FullProfile.objects.get(email=self.cleaned_data['email'])
> >         raise forms.ValidationError("%s" % (test))
>
> Shouldn't the second FullProfile.objects.get just raise a
> FullProfile.DoesNotExist eception again? It seems you're just catching
> an exception in order to throw it again in the except block...
>
> hth,
> Nuno

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



__init__ custom form validation

2010-07-12 Thread Nick
I am working on a validation that will require a field be filled in if
it is another field enters on of three values:

For example:

I have a form

class myform(forms.Modelform):
field1 = forms.CharField
field2 = forms.Charfield
field3_type = forms.CharField(choices=choices)
field3 = forms.DateTimeField(required=True)

def __init__(self, field3_type, *args, **kwargs):
super(myform, self_.__init__(*args, **kwargs)
if field3_type in ('option 1', 'option 2', 'option 3'):
self.field['field3'] = forms.DateTiemField(required=False)

The view:
if request.method == 'POST':
form = myform(request.POST)
field3_type = form.cleaned_data['field3_type']
if form.is_valid():
# some form processing
else:
   form = myform()

When i try to use the form I get an error at the myform() line stating
that __init__ takes exactyl 2 arguments and only 1 is given.

Any 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: Trouble writing a view for a model

2010-07-12 Thread Nick
I think a choice field is probably best, then you can customize the
presentation in a forms file.

class Question(models.Model):
q_cjoices = (
('choice1', 'choice1'),
('choice2', 'choice2'),
('choice3', 'choice3'),
('choice4', 'choice4'),
('choice5', 'choice5'),
)

title = modelsForeignKey(Title)
choices = models.CharField(choices=q_choices, max_length=100)

In the form declaration you can use this

from models.Questions import q_choices
from django.forms.extras.widgets import RadioSelect

choices = forms.CharField(choices=q_choices, widget=RadioSelect)

That would work unless you want someone to be able add choices based
on individual questions in which case you'll need to use a many to
many field, something like this:

Question(models.Model)
title = models.ForeignKey(Title)
Choice = models.ManyToManyField(Choice)

class Choice(models.CharField)
choice_1 = models.CharField( etc. etc. etc.



On Jul 12, 4:21 pm, rupert  wrote:
> Thanks for replying.
>
> I'm ultimately trying to create a feedback form where there is a list
> of say 10 questions with 5 choices for response to each question. It
> also needs to be editable in the admin (and I can't get forms to be
> editable in the admin).
>
> On Jul 12, 5:11 pm, Rodion Raskolnikiv  wrote:
>
> > Rupert,
> > Without knowing what you are aiming to accomplish, my advice might not
> > be pertinent. However, it looks like your models could be rearranged
> > like this:
>
> > class Question(models.Model):
> >     question = models.CharField(max_length=200)
> >     pub_date = models.DateTimeField('date published')
>
> > class Choice(models.Model):
> >     poll = models.ForeignKey(Question)
> >     choice = models.CharField(max_length=200)
> >     votes = models.IntegerField()
>
> > (Slightly modified from:http://docs.djangoproject.com/en/dev/intro/
> > tutorial01/)
>
> > On Jul 12, 1:49 pm, rupert  wrote:
>
> > > For this code:
>
> > > class Title(models.Model):
> > >         title = models.CharField(max_length=200)
> > >         pub_date = models.DateTimeField('date published')
>
> > >         def __unicode__(self):
> > >                 return self.title
>
> > >         def was_published_today(self):
> > >                 return self.pub_date.date() == datetime.date.today()
>
> > > class Question(models.Model):
> > >         title = models.ForeignKey(Title)
> > >         question = models.CharField(max_length=200)
> > >         choice1 = models.CharField(max_length=200)
> > >         choice2 = models.CharField(max_length=200)
> > >         choice3 = models.CharField(max_length=200)
> > >         choice4 = models.CharField(max_length=200)
> > >         choice5 = models.CharField(max_length=200)
>
> > >         def __unicode__(self):
> > >                 return self.question
>
> > > I'm trying to write a view where it outputs like this
>
> > > Question
>
> > > Choice 1-choice 5 in a radio button

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



formatting values list

2010-07-21 Thread Nick
I would like to format the output of a values_list into something a
little more usable for a CSV.

My view is really simple

def values_view(request)
list = MyModel.objects.values_list('id', 'name', 'type')
template = loader.get_template('mytemp.html')
c = Context({'list': list})
html = t.render(c)
HttpResponse(html)

my template looks like this

{% for item in list %}
{{item}}
{% endfor %}

it spits out a list of things like this:

(u'id', u'name', u'type), (u'id2', u'name2', u'type2)

etc. etc.

How can I format a values_list so I could return something like a
table or csv?

so:

id, name, type
id2, name, type

etc. etc.

Thanks for the help
Nick

-- 
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: formatting values list

2010-07-21 Thread Nick
Perfect, thanks

On Jul 21, 4:50 pm, n3ph  wrote:
>  Definitely the better way..
>
> On 07/21/10 23:42, Franklin Einspruch wrote:
>
> > Nick,
>
> > I think you're looking for this:
>
> >http://docs.djangoproject.com/en/dev/howto/outputting-csv/
>
> > Franklin
>
> > On Wed, Jul 21, 2010 at 5:38 PM, Nick  wrote:
> >> I would like to format the output of a values_list into something a
> >> little more usable for a CSV.
>
> >> My view is really simple
>
> >> def values_view(request)
> >>    list = MyModel.objects.values_list('id', 'name', 'type')
> >>    template = loader.get_template('mytemp.html')
> >>    c = Context({'list': list})
> >>    html = t.render(c)
> >>    HttpResponse(html)
>
> >> my template looks like this
>
> >> {% for item in list %}
> >> {{item}}
> >> {% endfor %}
>
> >> it spits out a list of things like this:
>
> >> (u'id', u'name', u'type), (u'id2', u'name2', u'type2)
>
> >> etc. etc.
>
> >> How can I format a values_list so I could return something like a
> >> table or csv?
>
> >> so:
>
> >> id, name, type
> >> id2, name, type
>
> >> etc. etc.
>
> >> Thanks for the help
> >> Nick
>
> >> --
> >> 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 
> >> athttp://groups.google.com/group/django-users?hl=en.
>
>
>
>  signature.asc
> < 1KViewDownload

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



using the update() method

2010-07-21 Thread Nick
I am trying to loop through a queryset and assign values to a field
based on other values in that entry.

So something like this

readers = Readers.objects.filter(status=active)

for reader in readers:
library = reader.library
book = reader.book

readers.update(sorter="%s%s" % (lirbary, book))

however, when I run the update it assigns the same value to all of the
readers.  I would like this to assign the value to sorter based on
what their individual library and book choices are.

reader.update return and error "reader has no attribute 'update'"

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



values() returning more than values

2010-07-21 Thread Nick
I may be misunderstanding the values method but it is returning
duplicate results when I use the distinct method. I have a query that
pulls the values of a column:

Readers = Readers.objects.values_list('organization').distinct()

The count returns 189 results but when I send it to output to a csv it
returns all of the values, with duplicates which is something like 900
entries.

Any help is appreciated.

-- 
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: values() returning more than values

2010-07-21 Thread Nick
Each reader has an id, name, and organization. There are 900 readers
and about 190 organizations. I'm trying to return all of the
organizations, but instead its returning every id in the table. So I'm
seeing all of the table's entries instead of just a list of
organizations.

On Jul 21, 10:47 pm, Kenneth Gonsalves  wrote:
> On Thursday, July 22, 2010 09:10:31 am Nick wrote:
>
> > Readers = Readers.objects.values_list('organization').distinct()
>
> > The count returns 189 results but when I send it to output to a csv it
> > returns all of the values, with duplicates which is something like 900
> > entries.
>
> by duplicates do you mean the whole row is duplicate or it is duplicate with
> the exception of the id of the row?
> --
> Regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC

-- 
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: values() returning more than values

2010-07-21 Thread Nick
It looks like its returning every organization instance in the table,

There are about 190 organizations and 900 totals entries, each of
which are assigned an organization.

The count on the query is correct, but when I output the actual values
it returns every entry in the table, so I'm seeing multiple duplicate
organizations.

On Jul 21, 10:47 pm, Kenneth Gonsalves  wrote:
> On Thursday, July 22, 2010 09:10:31 am Nick wrote:
>
> > Readers = Readers.objects.values_list('organization').distinct()
>
> > The count returns 189 results but when I send it to output to a csv it
> > returns all of the values, with duplicates which is something like 900
> > entries.
>
> by duplicates do you mean the whole row is duplicate or it is duplicate with
> the exception of the id of the row?
> --
> Regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC

-- 
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: using the update() method

2010-07-22 Thread Nick
That was only returning the F('library') piece of the code for sorter

I rewrote the update like this:

for reader in readers:
reader.sorter = "%s%s" % (reader.library, reader.book)
reader.save()

On Jul 21, 6:08 pm, Santiago Perez  wrote:
> I think that what you want can be accomplished by:
>
> from django.db.models import F
>
> readers = Readers.objects.filter(status=active)
> readers.update(sorter=(F('library') + F('book'))
>
>
>
> On Wed, Jul 21, 2010 at 19:40, Nick  wrote:
>
> > I am trying to loop through a queryset and assign values to a field
> > based on other values in that entry.
>
> > So something like this
>
> > readers = Readers.objects.filter(status=active)
>
> > for reader in readers:
> >    library = reader.library
> >    book = reader.book
>
> > readers.update(sorter="%s%s" % (lirbary, book))
>
> > however, when I run the update it assigns the same value to all of the
> > readers.  I would like this to assign the value to sorter based on
> > what their individual library and book choices are.
>
> > reader.update return and error "reader has no attribute 'update'"
>
> > --
> > 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.



Re: values() returning more than values

2010-07-22 Thread Nick
This is still an issue I'm seeing. I don't know how it can return the
proper count but then when i request the actual values it spits out 9
times as many

On Jul 21, 11:08 pm, Nick  wrote:
> It looks like its returning every organization instance in the table,
>
> There are about 190 organizations and 900 totals entries, each of
> which are assigned an organization.
>
> The count on the query is correct, but when I output the actualvalues
> it returns every entry in the table, so I'm seeing multiple duplicate
> organizations.
>
> On Jul 21, 10:47 pm, Kenneth Gonsalves  wrote:
>
> > On Thursday, July 22, 2010 09:10:31 am Nick wrote:
>
> > > Readers = Readers.objects.values_list('organization').distinct()
>
> > > The count returns 189 results but when I send it to output to a csv it
> > > returns all of thevalues, with duplicates which is something like 900
> > > entries.
>
> > by duplicates do you mean the whole row is duplicate or it is duplicate with
> > the exception of the id of the row?
> > --
> > Regards
> > Kenneth Gonsalves
> > Senior Associate
> > NRC-FOSS at AU-KBC

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



modelformset vs. inlineformset vs. DIY

2010-07-23 Thread Nick
I have inherited a project with a tight deadline and I am lost for how
to proceed.

There are two tables: Canididates and Race.

The race table holds 145 different races with information about
precincts, winners of different stages of the race (primary, runoff,
gneral)

The Candidates table has 1100+ candidates, each one is assigned to a
specific race via a FK and a list of three race vote totals (general,
runoff, primary)

I am supposed to create a way to display each race based on a search
and then return the candidates associated with that race so that the
race vote totals can be updated. I will also need to be able to update
values in the Race table.

It would be highly preferable for this to be seemless for the data
input people. I am looking at producing something like this:

Race 1
precincts reporting input - precincts total (static value)
Candidate 1 primary vote input - Candidate 1 status (active,
eliminated)
Candidate 2 primary vote input - Candidate 2 status (active,
eliminated)

winner of primary (list of candidates)

I have most of the form fields and widgets ready to go, but being able
to edit multiple entries in two different tables seemless has me
stuck.  Is this something that I should handle in inlineformsets since
I am spanning an FK? Would I need modelformsets to display all of the
candidates?

I can easily truncate the Race table and change it so that it has a
many to many relationship to all of the candidates instead of the
Candidates having an FK relationship to the race? Would that give me
more flexibility?

Thanks for the help in figuring this out, this has been an incredibly
stressful project.

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



Custom admin input app

2010-07-26 Thread Nick
Has anyone heard of, see, or used an app that would transform the
table view of the admin into a data entry point, basically jumping the
need to click through to individual entries in order to edit them?

-- 
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: Custom admin input app

2010-07-26 Thread Nick
Completely missed that section. You are always very helpful, Daniel.
Thank you.

On Jul 26, 10:08 am, Daniel Roseman  wrote:
> On Jul 26, 3:56 pm, Nick  wrote:
>
> > Has anyone heard of, see, or used an app that would transform the
> > table view of the admin into a data entry point, basically jumping the
> > need to click through to individual entries in order to edit them?
>
> This is built-in, to an extent - 
> seehttp://docs.djangoproject.com/en/1.2/ref/contrib/admin/#admin-list-ed...
> --
> DR.

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



save a values_list to a charfield

2010-07-27 Thread Nick
I am needing to do some duct taping for a project that is going on
right now. In it I need to take a values_list of id's from a
ManyToMany field and save those values to a varchar field so a mysql
query can access the values. I am working with two different sets of
developers and this is the best we can come up with in such a short
period of time


Here is the model:

Candidate
filing_id = models.IntegerField()
name = models.CharField()

Race:
name = models.CharField()
primary_advance = models.ManyToManyField('Candidate')
primary_advnace_list = models.CahrField()

def(save, *args, **kwargs):
primary_ids = self.primary_advace.values_list('id', flat=True)
if primary_ids.count() > 0:
primary_advance_list = primary_ids
else:
primary_advance_list = []
super(Race, self).save(*args, **kwargs)

I've tried this but I'm coming back with empty values for the list
fields.

-- 
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: save a values_list to a charfield

2010-07-27 Thread Nick
I am getting this to save but I can't get it to output properly

it's outputting as [16L, 451L, 521L] for a list of id's, which it
should according to documentation.  However, how can I output it like
this 16, 451, 521

On Jul 27, 12:11 pm, Nick  wrote:
> I am needing to do some duct taping for a project that is going on
> right now. In it I need to take a values_list of id's from a
> ManyToMany field and save those values to a varchar field so a mysql
> query can access the values. I am working with two different sets of
> developers and this is the best we can come up with in such a short
> period of time
>
> Here is the model:
>
> Candidate
>     filing_id = models.IntegerField()
>     name = models.CharField()
>
> Race:
>     name = models.CharField()
>     primary_advance = models.ManyToManyField('Candidate')
>     primary_advnace_list = models.CahrField()
>
>     def(save, *args, **kwargs):
>         primary_ids = self.primary_advace.values_list('id', flat=True)
>         if primary_ids.count() > 0:
>             primary_advance_list = primary_ids
>         else:
>             primary_advance_list = []
>         super(Race, self).save(*args, **kwargs)
>
> I've tried this but I'm coming back with empty values for the list
> fields.

-- 
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: save a values_list to a charfield

2010-07-27 Thread Nick
It is a bit of a last minute deal and will be changed after today, but
we had a handful of "improvements" handed down to us from management
and this was the fastest thing we could come up with using some old
mysql query logic and several already built templates for output.

I appreciate the help.

On Jul 27, 2:49 pm, ringemup  wrote:
> ', '.join(primary_ids)
>
> The fact that you're doing this with foreign keys, though, suggests to
> me that you may have a database normalization problem.
>
> On Jul 27, 3:26 pm, Nick  wrote:
>
> > I am getting this to save but I can't get it to output properly
>
> > it's outputting as [16L, 451L, 521L] for a list of id's, which it
> > should according to documentation.  However, how can I output it like
> > this 16, 451, 521
>
> > On Jul 27, 12:11 pm, Nick  wrote:
>
> > > I am needing to do some duct taping for a project that is going on
> > > right now. In it I need to take a values_list of id's from a
> > > ManyToMany field and save those values to a varchar field so a mysql
> > > query can access the values. I am working with two different sets of
> > > developers and this is the best we can come up with in such a short
> > > period of time
>
> > > Here is the model:
>
> > > Candidate
> > >     filing_id = models.IntegerField()
> > >     name = models.CharField()
>
> > > Race:
> > >     name = models.CharField()
> > >     primary_advance = models.ManyToManyField('Candidate')
> > >     primary_advnace_list = models.CahrField()
>
> > >     def(save, *args, **kwargs):
> > >         primary_ids = self.primary_advace.values_list('id', flat=True)
> > >         if primary_ids.count() > 0:
> > >             primary_advance_list = primary_ids
> > >         else:
> > >             primary_advance_list = []
> > >         super(Race, self).save(*args, **kwargs)
>
> > > I've tried this but I'm coming back with empty values for the list
> > > fields.

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



updating admin values with other fields

2010-07-27 Thread Nick
I have a save override in my admin file that catches a value from one
field and applies it to another. The values it grabs from a manytomany
field.

I can get it to work, but only when I save twice. It looks like it
needs the manytomany to update with the new values and then it needs
to second save to assigne the values to the other field.

Here is the method override:

 def save_model(self, request, obj, form, change):
obj.primary_winner_r = obj.primary_advance_r.values_list('id',
flat=True)
obj.primary_winner_d = obj.primary_advance_d.values_list('id',
flat=True)
obj.primary_winner_np =
obj.primary_advance_np.values_list('id', flat=True)
obj.save()

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



Override queryset for admin Inline

2010-08-06 Thread Nick
I have an admin set up with three inlines.  I would like to filter the
inline's editable options by a variable that is defined in a settings
file.  I can over ride the actual admin pieces for each of the inlines
(they all have full admin screens of their own). But I can't seem to
get the standard def queryset(self, request): etc. over ride to work
for inlines. I have seen a little talk about how inlines require you
to create a new manager to filter the list of options.

Here is my inline admin code:

class CandidateInline(admin.TabularInline):
 model = Candidate

fields = ['%s_vote' % (race_type)]

extra = 0

 ordering = ('party', 'last_name')

## here is where the trouble is starting, I'd like to get rid of
everything that isn't status 1 ###

 def queryset(self, request):
 qs = super(CandidateInline, self).queryset(request)
return qs.filter(status="1").exclude(party="Independent")


and here is the primary admin model that this inline is attached to:

class RaceAdmin(admin.ModelAdmin):


 inlines = [
CandidateInline,
PrecinctInline,
]


form = RaceForm

 fieldsets = (
 ('General Race Information', {

'fields': ('name', 'office_name', 'type', 'county',
'general_winner')
 }),
   ('Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
   'fields': ('runoff_winner_d', 'runoff_winner_r',
'primary_advance_d', 'primary_advance_r'),
}),
('Non Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
'fields': ('runoff_winner_np',)
}),
 )
   list_display = ('name', 'type', 'county', )
list_filter = ('type', 'office_name', 'county')
ordering = ['name']


 # redefine the queryset to get rid of finals
def queryset(self, request):
qs = super(RaceAdmin, self).queryset(request)
return qs.filter(type="2")

-- 
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-tables with ID

2010-08-10 Thread Nick
You could just write the table out in full in the template and use
JavaScript to sort the rows.



On Aug 10, 2:55 pm, "Mike W."  wrote:
> Hi,
>
> I'm trying to use django-tables to display the output in a grid-like
> view.  I'd like a user to be able to choose a row and send it to a
> detail page.
>
> I've tried to look for a way to pass the ID across, but I can't seem
> to find much about it.  Is it possible, and if so, how?  Is there
> something else out there that might work better?
>
> 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: forms tutorials

2010-08-11 Thread Nick
The best option would be to break off of the tutorials for a bit and
try to build something out on your own. The documentation for forms is
quite extensive.

I recommend getting comfortable with inlines and formsets

http://docs.djangoproject.com/en/1.1/topics/forms/


On Aug 11, 1:39 pm, Jagdeep Singh Malhi 
wrote:
> Hi...
>
> I done the 
> tutorialshttp://docs.djangoproject.com/en/dev/intro/tutorial04/#intro-tutorial04
> for create the form using database.
>
> Now i want to study more tutorials/examples which is helpful for me to
> create the forms using database.
> if anybody know about the links/websites/other sources related Django
> forms.
> Please post.
>
> Thanks
>
> Regards,
> Jagdeep Singh

-- 
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: overwrite the save method

2010-08-11 Thread Nick
You override the save in two places, in the form itself or in the
view. Either one would work, you could combine the two as well.

the form save override would look something like

def save(self):
formatform = super(FormFormat, self).save(commit=False)
if formatform.boolean1 and formatform.boolean2:
formatform.myBoolean = True
formformat.save()

in the view:

form = FormFormat(request.POST)
if form.is_valid():
form_save = form.save(commit=False)
if form_save.boolean1 == True and form_save.boolean2 == True:
form_save.myBoolean = True
form_save.save()
On Aug 11, 2:08 pm, Roald de Vries  wrote:
> On Aug 11, 2010, at 7:25 PM, refreegrata wrote:
>
>
>
> > My code
> > --
> > class Format(models.Model):
> >    name = models.CharField(max_length=5, unique=True)
> >    myBoolean = models.BooleanField(default=False)
>
> > class FormFormat(forms.ModelForm):
> >    boolean1 = forms.BooleanField(required=False)
> >    boolean2 = forms.BooleanField(required=False)
>
> >    class Meta:
> >        model = Format
> >        fields = ['name']
>
> > FormsetFormFormat = forms.models.modelformset_factory(Format,
> > max_num=0,form=FormFormat)
> > --
> > The idea is this:
>
> > if boolean1=True and boolean2=True the field myBoolean must to be True
> > if boolean1=True and boolean2=False the field myBoolean must to be
> > False
> > ...
> > My question is, how i can do this?
> > overwriting the save method?
>
> Possible, but I have a feeling there might be a nicer solution. What  
> do you want to happen if boolean1 is false?
>
> > I don't have idea, because boolean1 and boolean2 are form fields not
> > model fields. Can i pass custom parameters to the save method?
>
> Yes, you can.

-- 
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: filter users by group

2010-08-11 Thread Nick
You can subclass the User admin and then unregister the default admin
and register your new subclassy admin (subclassy is a word)

in admin.py:

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

class MyNewUserAdmin(UserAdmin):
list_filter = UserAdmin.list_filter + ('groups',)

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


On Aug 11, 9:42 am, Wim Feijen  wrote:
> Hello,
>
> I am banging my brain against the wall but it doesn't help and all I
> get is brain damage. Maybe you can help me find a solution for the
> following problem?
>
> How can I add a filter to the django admin User interface (/admin/auth/
> user/) so I can filter Users by Group?
>
> What I have thought of, is:
> 1. Alter the template templates/admin/auth/user/change_list.html and
> edit it to add a list of existing groups as links.
> 2. Redirect to ?group_id=1. THIS STEP FAILS!
> 3. Write a custom UserAdmin and overwrite the queryset method to show
> only users of a group, thus:
>
> class UserAdmin(admin.ModelAdmin):
>     model = User
>
>     def queryset(self, request):
>         group_id = request.GET.get('group_id', '')
>         if group_id:
>             return Group.objects.get(id=group_id).user_set.all()
>         else:
>             return super(UserAdmin, self).queryset(request)
>
> try:
>     admin.site.unregister(User)
> except admin.sites.Unregistered:
>     pass
> admin.site.register(User, UserAdmin)
>
> The missing link is step 2. How on earth do I get a request.GET
> parameter through django's normal filtering process/ how can I combine
> it. When I try '/admin/auth/user/?group_id=1', django redirects me to
> '/admin/auth/user/?e=1'
>
> Any help and tips will be very much appreciated, thank you!
>
> If someone's has ever done this, I'd really like to know!
>
> Wim

-- 
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: dynamic forms and custom methods

2010-08-11 Thread Nick
Are you trying to create a save function that evaluates all the
weights and returns an error if they are more than 1?

On Aug 10, 3:17 pm, lingrlongr  wrote:
> I 'm trying to create a form dynamically.  This works just fine, but
> there's no way for the form to offer any customized validation, by way
> of the clean() method.
>
> def get_dept_weight_form(store):
>     fields = {}
>     s = Store.objects.get(pk=store.id)
>     for d in store.department_set.all():
>         fields['id_%d' % d.id] = forms.DecimalField(
>             label = d.name,
>             initial = d.weight
>         )
>     return type('WeightForm', (forms.BaseForm,), {'base_fields':
> fields})
>
> Basically, this form spits out a label showing the department name and
> the weight for you to enter in a textbox.  The weights for all
> departments should total 1.0.  Should a clean() method handle this?
>
> I already use an overridden version of save() on the store model, but
> that just prints out a warning to stdout.  Also, I have this
> validation for the admin part by overriding the clean method for my
> declared ModelForm.
>
> Perhaps I should just use the functionality I already created in
> models.py and just raise a ValidationError?
>
> Thx

-- 
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: dynamic forms and custom methods

2010-08-12 Thread Nick
I think jquery may be the right way to go for this. It will allow you
to evaluate the weights in real time so you won't have to submit the
form before any validation errors would be returned.

Working it at the model level may get tricky, for ease I would handle
it at the form or view level.

On Aug 12, 9:30 am, Steve Holden  wrote:
> On 8/12/2010 8:36 AM, lingrlongr wrote:
>
>
>
> > Hi Nick,
>
> > Thanks for the reply.  Yes, the department weights will be used in a
> > grading scheme.  One department may be 25% (0.25), etc...  But in the
> > end, the weights should total 1.0.  For example, in my Store model:
>
> > class Store(models.Model):
> >   #...etc...
>
> >   def _get_total_dept_weight(self):
> >     return self.department_set.all().aggregate(Sum('weight'))
> > ['weight_sum']
>
> >   def save(self, *args, **kwargs):
> >     if self._get_total_dept_weight() <> Decimal('1.0'):
> >       # fail
> >     super(Store, self).save(*args, **kwargs)
>
> > So in the case of my custom form, I was thinking about raising a
> > validation error if the totals submitted in the form don't total 1.0.
> > But I was thinking over the weekend, maybe this isn't the best place
> > for it after all. Maybe it should stay in the model because why does
> > the form care if the weights is 1.0?  The model does...  Perhaps
> > instead, raise a ValidationError exception from the Store's save()
> > method?
>
> Yes, you could do that - and even if you used JavaScript on the client
> side to enforce the total it would still be necessary to avoid malicious
> clients.
>
> > What are your thoughts?
>
> Alternatively, you could just normalize the weights after the user
> submits them, or even leave them as they are and normalize them when you
> use them. Surely the important thing is the weightings and their
> relative values. You can simply divide each weighting by the sum of all
> weightings before you apply them.
>
> regards
>  Steve
>
>
>
>
>
> > On Aug 11, 3:58 pm, Nick  wrote:
> >> Are you trying to create a save function that evaluates all the
> >> weights and returns an error if they are more than 1?
>
> >> On Aug 10, 3:17 pm, lingrlongr  wrote:
>
> >>> I 'm trying to create a form dynamically.  This works just fine, but
> >>> there's no way for the form to offer any customized validation, by way
> >>> of the clean() method.
>
> >>> def get_dept_weight_form(store):
> >>>     fields = {}
> >>>     s = Store.objects.get(pk=store.id)
> >>>     for d in store.department_set.all():
> >>>         fields['id_%d' % d.id] = forms.DecimalField(
> >>>             label = d.name,
> >>>             initial = d.weight
> >>>         )
> >>>     return type('WeightForm', (forms.BaseForm,), {'base_fields':
> >>> fields})
>
> >>> Basically, this form spits out a label showing the department name and
> >>> the weight for you to enter in a textbox.  The weights for all
> >>> departments should total 1.0.  Should a clean() method handle this?
>
> >>> I already use an overridden version of save() on the store model, but
> >>> that just prints out a warning to stdout.  Also, I have this
> >>> validation for the admin part by overriding the clean method for my
> >>> declared ModelForm.
>
> >>> Perhaps I should just use the functionality I already created in
> >>> models.py and just raise a ValidationError?
>
> >>> Thx
>
> --
> DjangoCon US 2010 September 7-9http://djangocon.us/

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



Django psycopg2 installation issue

2010-08-13 Thread Nick
This is actually related to psycopg2, OS X and Postgres but I was
hoping someone in here has seen the same issue.

I recently installed PostgresPlus 8.4, Django dev (1.4?), and psycop2
version 2.2.0 on my imac OS X 10.6.4

When i try to run dbshell from the command line I get an error that
reads

raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2
module: dlopen(/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: /
usr/local/pgsql/lib/libpq.4.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/site-packages/psycopg2/_psycopg.so
  Reason: image not found

I've tracked the problem down to this line:

ibrary not loaded: /usr/local/pgsql/lib/libpq.4.dylib

The reason that library didn't load is because it doesn't exist
anywhere. I installed psycop via these instructions:

http://blog.jonypawks.net/2008/06/20/installing-psycopg2-on-os-x/

I've been through several threads and have still not been able to
figure out the issue

-- 
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 queryset get only one result for one column pair

2010-08-14 Thread Nick
http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct

Distinct() may be what you're looking for to returns distinct values
for each problem.

Or, petter yet, you could use .latest()

So Submission.objects.all().latest('problem').distinct()

http://www.djangoproject.com/documentation/models/get_latest/
On Aug 14, 8:04 am, Rohan Jain  wrote:
> Actually there may be many submissions with a user-problem pair but i
> want to list only the last one per user - problem pair.
> Like:
>
> let p1 be two problems , u1, u2 be two users and s1,s2 two submissions
> by user u1 on problem and s3,s4 by u2.
>
> so i want to get a queryset with only the last submission by u1,u2 on
> p1.
>
> On Aug 14, 5:57 pm, Kenneth Gonsalves  wrote:
>
>
>
> > On Sat, 2010-08-14 at 05:45 -0700, Rohan Jain wrote:
> > > I have a field 'submission' which has a 'user' and a 'problem'.
> > > How can i get a django queryset search result which will give a list
> > > of only one result per user-problem pair.
>
> > does your model not have a unique_together for user and problem?
> > --
> > regards
> > Kenneth Gonsalves

-- 
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: query evaluation problem

2010-08-16 Thread Nick
How about using an autofield?

http://docs.djangoproject.com/en/dev/ref/models/fields/#autofield

On Aug 16, 12:25 pm, Alec Shaner  wrote:
> Regarding your issue with get_next, could be because you're invoking the
> method when you define default=get_next(). Try it with just the bare method
> name get_next.
>
> You could also use the aggregate function instead of creating a new model:
>
> http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#topics-db...
>
> Just define get_next to call the Max aggregate on your Newspaper model's
> number field.
>
> On Mon, Aug 16, 2010 at 12:39 PM, bagheera  wrote:
> > Hi, i have "number" field in "newspaper" model.  I want assign to it
> > dynamically a default value, witch would be a incremented by 1 highest value
> > so far.
> > So i managed to make a little workaround, since i can't query for last
> > value of "number" field of model from model itself.
>
> > I have created new model, witch has only 1 field any 1 record, witch stores
> > current highest value.
> > I wrote two functions:
>
> > #-*- coding: utf-8 -*-
> > from nml.options.models import Wydanie_opt
>
> > def set_next(value):
> >    try:
> >        option = Wydanie_opt.objects.all()[0]
> >        if value > option.nr_wydania_next:
> >            option.nr_wydania_next = value
> >            option.save()
> >    except:
> >        option = Wydanie_opt(nr_wydania_next = value)
> >        option.save()
>
> > def get_next():
> >    try:
> >        option = Wydanie_opt.objects.all()[0]
> >        value = option.nr_wydania_next
> >    except:
> >        return 0
> >    else:
> >        return value + 1
>
> > Here's code of "newspaper" model:
>
> > from nml.options.utils import get_next
>
> > class Wydanie(models.Model):
> >    nr_wydania = models.PositiveIntegerField(verbose_name = "Numer wydania",
> > unique = True, default = get_next(),
> >        help_text = "Unikalny numer wydania.")
>
> > The problem is, set_next is working as intended, but get_next() does NOT,
> >  default value stays the same until i restart dev server. Why? Query isn't
> > evaluated? get_next() function isn't called at all?
> > Mb there is a better way to implement auto-incrementation.
> > Keep in mind that, "nr_wydania" field must be visible and editable, since
> > first entered value is unknown, some values may be skipped, and there is no
> > order of adding it.
> > --
> > Linux user
>
> > --
> > 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.



Foreignkeys and variables in a view

2010-08-16 Thread Nick
I have a view that handles elections/races. That view takes a request
object and then based on that object sends the information to a
specific template.

For each election/race there is a subset of candidates based on the
initial candidate_set from that race. I would like to know how to
filter that set in a view. Here is what I have so far:

Models.py:

Candidate
name = charfield
id = integer
race = ForeignKey(Race)

Race
name = charfield
type = integerfield

Views.py

def races_output(request, type): # the type is a number that equates
to general (3), runoff (2) or primary (1)
if type == 2:
 r = "runoff"
 t = loader.get_template("Government/race_output_2.html")
 state_races = Race.objects.select_related().filter(type=type)
 for race in state_races:
candidates = race.candidate_set.filter(status="runoff")

if type == 3:
 r = "general"
 t = loader.get_template("Government/race_output_3.html")
 state_races = Race.objects.select_related().filter(type=type)
 for race in state_races:
candidates = race.candidate_set.filter(status="general")

c = Context({'state_races': state_races, 'candidates': candidates,
'r':r})
html = t.render(c)

template

{% for race in state_races %}

{{race.name}} - {{race.type}}

{% for cand in candidates %}
{{ cand.name }} - {{cand.id }}
{% endfor %}

{% endif %}

The problem is the candidate for loop returns the exact same
candidates for every single race. How do I get it so that the
candidates query is specific to the race in the for loop?

-- 
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: Foreignkeys and variables in a view

2010-08-17 Thread Nick
Thanks, Steve. I'll implement this today and see what happens.

On Aug 16, 9:46 pm, Steve Holden  wrote:
> On 8/16/2010 10:30 PM, Nick Tankersley wrote:> Thank you again for your 
> replies. They've been full of usefull
> > information about how to clean up an otherwise pretty sloppy bit of code.
>
> No problem. I hope you don't mind me keeping this dialog on the list (I
> see you didn't copy django-users, perhaps not realizing that a "Reply
> All" would be required to do so).
>
> > By the way, type 1 races passed about a month ago so it doesn't come
> > into play.
>
> Thanks! That cleared up a mystery.
>
> > I can see how you misunderstand my goal. After I get the initial query
> > for the races I want to filter each races candidate_set to include only
> > those candidates with a specific status. That is where I am getting stuck.
>
> > What I meant by saying that the template for loop is working properly is
> > that based on my flawed query logic it is returning exactly what is
> > should, a list of candidates in the last entry.
>
> Ah! Penny drops! I wasn't really looking at the templates. So what you
> are really asking is how can you make the template work for every race,
> and not just the last one?
>
> A solution I have used in the past is to add attributes to the top-level
> objects that I can then use in the template. This would in your case
> involve doing something like
>
>     for race in state_races:
>         race.cands = race.candidate_set.filter(status="runoff")
>
> in the view. Then the template would look like this:
>
> {% for race in state_races %}
>
> {{race.name}} - {{race.type}}
>
> {% for cand in race.cands %}
> {{ cand.name }} - {{cand.id }}
> {% endfor %}
>
> {% endif %}
>
> I am pretty sure this isn't the recommended way to proceed, but with
> luck someone on the list will advise us as to what is ...
>
> regards
>  Steve
>
>
>
> > On Aug 16, 2010 9:21 PM, "Steve Holden"  > <mailto:holden...@gmail.com>> wrote:
> >> On 8/16/2010 9:30 PM, Nick wrote:
>
> >>> Thanks for the reply.
>
> >>> I assume the problem is coming from the views since the template 'for'
> >>> loop is technically doing what it's supposed to.
>
> >> I find that hard to believe - you appear to be saying that you only want
> >> the candidates for the *last* state_race. In which case why bother to
> >> compute the candidates for the others?
>
> >> As far as I can see your code
>
> >> for race in state_races:
> >> candidates = race.candidate_set.filter(status="runoff")
>
> >> should give exactly the same result at
>
> >> candidates = state_races[-1].candidate_set.filter(status="runoff")
>
> >> but of course I could be mistaken.
>
> >> Ignoring that for the moment you might want to simplify a little bit -
> >> it looks as though you were heading along this road but didn't quite go
> >> all the way.
>
> >> racetypes = {"2": "runoff",
> >> "3": "general"} # What happened to "1"?
>
> >> def races_output(request, rtyp) # type() is a Python built-in!
> >> r = racetypes(rtyp)
> >> t = loader.get_template("Government/race_output_%s.html" % rtyp)
> >> state_races = Race.objects.select_related().filter(type=rtyp)
> >> # then whatever you decide needs to be done with the races
>
> >> Hope this helps.
>
> >> regards
> >> Steve
>
> >>> How do I limit the candidate_set(s) for each race to the statuses
> >>> mentioned above? I have a very duct taped solution in my template but
> >>> it's very unwieldly and confusing (many many if's). Can I move this
> >>> filtering to the view to clean up the template?
>
> >> That's almost certainly the right approach. Whenever your templates get
> >> clogged up with logic it indicates you need to migrate the logic to
> >> views. This makes your templates much more readable too!
>
> >>> On Aug 16, 7:41 pm, Steve Holden  > <mailto:holden...@gmail.com>> wrote:
> >>>> On 8/16/2010 5:40 PM, Nick wrote:
>
> >>>>> I have a view that handles elections/races. That view takes a request
> >>>>> object and then based on that object sends the information to a
> >>>>> specific template.
>
> >>>>> For each election/race there is a subset of candidates b

Re: Foreignkeys and variables in a view

2010-08-17 Thread Nick
This appears to be working. Thanks a lot Steve, I really appreciate
the help.

On Aug 17, 9:07 am, Nick  wrote:
> Thanks, Steve. I'll implement this today and see what happens.
>
> On Aug 16, 9:46 pm, Steve Holden  wrote:
>
> > On 8/16/2010 10:30 PM, Nick Tankersley wrote:> Thank you again for your 
> > replies. They've been full of usefull
> > > information about how to clean up an otherwise pretty sloppy bit of code.
>
> > No problem. I hope you don't mind me keeping this dialog on the list (I
> > see you didn't copy django-users, perhaps not realizing that a "Reply
> > All" would be required to do so).
>
> > > By the way, type 1 races passed about a month ago so it doesn't come
> > > into play.
>
> > Thanks! That cleared up a mystery.
>
> > > I can see how you misunderstand my goal. After I get the initial query
> > > for the races I want to filter each races candidate_set to include only
> > > those candidates with a specific status. That is where I am getting stuck.
>
> > > What I meant by saying that the template for loop is working properly is
> > > that based on my flawed query logic it is returning exactly what is
> > > should, a list of candidates in the last entry.
>
> > Ah! Penny drops! I wasn't really looking at the templates. So what you
> > are really asking is how can you make the template work for every race,
> > and not just the last one?
>
> > A solution I have used in the past is to add attributes to the top-level
> > objects that I can then use in the template. This would in your case
> > involve doing something like
>
> >     for race in state_races:
> >         race.cands = race.candidate_set.filter(status="runoff")
>
> > in the view. Then the template would look like this:
>
> > {% for race in state_races %}
>
> > {{race.name}} - {{race.type}}
>
> > {% for cand in race.cands %}
> > {{ cand.name }} - {{cand.id }}
> > {% endfor %}
>
> > {% endif %}
>
> > I am pretty sure this isn't the recommended way to proceed, but with
> > luck someone on the list will advise us as to what is ...
>
> > regards
> >  Steve
>
> > > On Aug 16, 2010 9:21 PM, "Steve Holden"  > > <mailto:holden...@gmail.com>> wrote:
> > >> On 8/16/2010 9:30 PM, Nick wrote:
>
> > >>> Thanks for the reply.
>
> > >>> I assume the problem is coming from the views since the template 'for'
> > >>> loop is technically doing what it's supposed to.
>
> > >> I find that hard to believe - you appear to be saying that you only want
> > >> the candidates for the *last* state_race. In which case why bother to
> > >> compute the candidates for the others?
>
> > >> As far as I can see your code
>
> > >> for race in state_races:
> > >> candidates = race.candidate_set.filter(status="runoff")
>
> > >> should give exactly the same result at
>
> > >> candidates = state_races[-1].candidate_set.filter(status="runoff")
>
> > >> but of course I could be mistaken.
>
> > >> Ignoring that for the moment you might want to simplify a little bit -
> > >> it looks as though you were heading along this road but didn't quite go
> > >> all the way.
>
> > >> racetypes = {"2": "runoff",
> > >> "3": "general"} # What happened to "1"?
>
> > >> def races_output(request, rtyp) # type() is a Python built-in!
> > >> r = racetypes(rtyp)
> > >> t = loader.get_template("Government/race_output_%s.html" % rtyp)
> > >> state_races = Race.objects.select_related().filter(type=rtyp)
> > >> # then whatever you decide needs to be done with the races
>
> > >> Hope this helps.
>
> > >> regards
> > >> Steve
>
> > >>> How do I limit the candidate_set(s) for each race to the statuses
> > >>> mentioned above? I have a very duct taped solution in my template but
> > >>> it's very unwieldly and confusing (many many if's). Can I move this
> > >>> filtering to the view to clean up the template?
>
> > >> That's almost certainly the right approach. Whenever your templates get
> > >> clogged up with logic it indicates you need to migrate the logic to
> > >> views. This makes your templates much more readable too!
>
> > >>

Re: How to create custom form widgets ?

2010-08-18 Thread Nick
Here's an example:

http://joshourisman.com/2008/11/19/custom-fields-and-widgets-django-forms/

Another good way to go would be to look at the django widgets in the
source code and  follow their example

On Aug 18, 1:44 pm, ydjango  wrote:
> I am using a 3rd party javascript library with some custom components
> like combo box.
>
> I want to use this 3rd party combo box instead of  the default combo
> box that
> django forms modelchoicefield(widget= forms.select(...),...)
> displays.
>
> I guess I will have to create another widget replace widget=
> form.select(...) by that.
>
> How do I create another widget? Any links to how to documentation
> would appreciated. I searched for it, not sure why I could not find
> it.
>
> I am on django 1.1.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.



Re: adding a summary field to a model

2010-08-19 Thread Nick
You need to look at overriding the model's save method in order to add
data from one field to another dynamically.

http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods




On Aug 19, 2:03 am, djnubbio  wrote:
> Sorry for wasting your preciuose time. I'm very newby in django.
>
> I have de following
>
> class Commessa(models.Model):
>     commessa = models.CharField(max_length=20)
>      quota_oraria=models.DecimalField(max_digits=5, decimal_places=2)
>   ...
>
> class Diario(models.Model):
>     data= models.DateField('data inizio')
>     commessa = models.ForeignKey(Commessa)
>     ore=models.IntegerField()
> ...
>
> I want to add a column to Commessa containg the result of:
>
> quota_oraria * sum(ore)
>
> for each item in commessa.
>
> any suggestion will be greatly appreciated; tank vwry much in advance

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



Strange problem accessing JS for admin

2010-08-24 Thread Nick
I have a model set up to use collapsable inlines but for some reason
the path to my js files is acting very strange.

I can find the core.js at http://mysite.com/media/js/core.js  but when
i try to reach any other js http://mysite.com/media/js/inline.min.js I
get a server error

"/media/js/inlines.min.js was not found on this server"

I checked the directories and all the js files are in the right place.
Anyone encounter this before?

-- 
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: Strange problem accessing JS for admin

2010-08-25 Thread Nick
Stranger still, I can get to the /media/js/admin/
RelatedObjectLookups.js but not the jquery library


On Aug 24, 4:51 pm, Nick  wrote:
> I have a model set up to use collapsable inlines but for some reason
> the path to my js files is acting very strange.
>
> I can find the core.js athttp://mysite.com/media/js/core.js but when
> i try to reach any other jshttp://mysite.com/media/js/inline.min.jsI
> get a server error
>
> "/media/js/inlines.min.js was not found on this server"
>
> I checked the directories and all the js files are in the right place.
> Anyone encounter this before?

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



prepopulated_fields problem (+admin CSS issues)

2010-09-14 Thread Nick
Hello,

I'm running django 1.2.3 on a local server and am still quite new to
django. I was working with the "practical django projects second
edition" book and implemented the prepopulated_fields option to auto
populate slugs from titles.

It works when I add a new post but it does not work when I edit the
post, is this working as intended or broken? It seems for this option
to be useful it must update on change as well. If that's not a
supported option what can I do to hack it in?

The code I am using is (admin.py):

class CategoryAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }

class EntryAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }

class LinkAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }

admin.site.register(Category, CategoryAdmin)
admin.site.register(Entry, EntryAdmin)
admin.site.register(Link, LinkAdmin)

I also tried using the django documentation's syntax with no luck, it
resulted in the same broken functionality. I tried it with Opera 10.x
and IE8, same results.

Also there appears to be a massive problem with the CSS when using the
filter sidebar. The admin is designed to be fluid width and
automatically generates the proper fluid width of columns but it fails
to make the column widths fluid when the filter sidebar is enabled.

Is there a known hack to correct this? It looks very awkward when you
have a 1600 width screen and 3 or 4 columns are shrunken to 75-100
pixels wide with a 1000 pixel white space before it shows the sidebar.

Thanks,
Nick

-- 
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: prepopulated_fields problem (+admin CSS issues)

2010-09-14 Thread Nick
Yeah that makes sense. I guess we just need to be more careful when
adding live posts. Maybe it wouldn't be a bad idea to add the
functionality on change if a post is anything but live. This way the
slug stays relevant to the title for drafts if the editor feels like
experimenting with different titles.

As for my second question. Can you not help because you haven't
experienced this issue, or is it something you just don't have a
problem with?

On Sep 14, 11:20 am, "nick.l...@gmail.com" 
wrote:
> Nick,
>
> I can answer you first question...but not really the second...hopefully
> someone else will come and explain that one to you...
>
> re slugs: The prepopulated_fields are working as intended.
>
> The reason being, say you've written a blog post. You've send that link out
> to thousands and millions of people. Then you realize that you wanted to
> change a word in your title (hence changing the slug).
>
> As soon as you change that slug, you've broken a link on the internet that
> was previously NOT broken before. Even if you change the title, don't change
> the slug.
>
> Django can figure out the "absolute_url" for what ever slug you pick. But
> once the link has been published _outside_ your site, you don't want to have
> broken links. Remember it's just a slug...just a url...the real title can be
> what ever you want it to be.
>
> BUT if you want django to behave the way you're expecting, the great thing
> about django is you can change it to behave that way. All it takes is a
> little customization of the change_view for the admin of your blog app (or
> what ever app you want to change the behavior of).
>
> Hope that helps
>
> Nick (also)
>
> On Tue, Sep 14, 2010 at 3:10 PM, Nick 
>
>
>
>
> > wrote:
> > Hello,
>
> > I'm running django 1.2.3 on a local server and am still quite new to
> > django. I was working with the "practical django projects second
> > edition" book and implemented the prepopulated_fields option to auto
> > populate slugs from titles.
>
> > It works when I add a new post but it does not work when I edit the
> > post, is this working as intended or broken? It seems for this option
> > to be useful it must update on change as well. If that's not a
> > supported option what can I do to hack it in?
>
> > The code I am using is (admin.py):
>
> > class CategoryAdmin(admin.ModelAdmin):
> >    prepopulated_fields = { 'slug': ['title'] }
>
> > class EntryAdmin(admin.ModelAdmin):
> >    prepopulated_fields = { 'slug': ['title'] }
>
> > class LinkAdmin(admin.ModelAdmin):
> >    prepopulated_fields = { 'slug': ['title'] }
>
> > admin.site.register(Category, CategoryAdmin)
> > admin.site.register(Entry, EntryAdmin)
> > admin.site.register(Link, LinkAdmin)
>
> > I also tried using the django documentation's syntax with no luck, it
> > resulted in the same broken functionality. I tried it with Opera 10.x
> > and IE8, same results.
>
> > Also there appears to be a massive problem with the CSS when using the
> > filter sidebar. The admin is designed to be fluid width and
> > automatically generates the proper fluid width of columns but it fails
> > to make the column widths fluid when the filter sidebar is enabled.
>
> > Is there a known hack to correct this? It looks very awkward when you
> > have a 1600 width screen and 3 or 4 columns are shrunken to 75-100
> > pixels wide with a 1000 pixel white space before it shows the sidebar.
>
> > Thanks,
> > Nick
>
> > --
> > 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.
>
> --
> Guadajuko! Vamos a correr!
>  -"Cool! we are going to run!"

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



contrib.comments, admin section [unable to see comments]

2010-09-14 Thread Nick
Hello,

I tried to troubleshoot this with Google and #django on IRC but I'm
coming up empty. I've been following the practical django projects
second edition book using django 1.2.3 on a local server.

I have added 'django.contrib.comments' to my settings file + adjusted
my urls.py file just like the book said and ran syncdb. The admin
section is picking up the comments "model" fine. I can post comments
fine and they are visible within the post, great.

When I goto the admin section and click comments, then click comments
again I'm presented with what should be a page to allow me to see the
available comments and admin them (edit, delete, etc.). The issue is
that the rows are empty for each comment. Instead it just gives me a
count of the number of comments which makes it impossible to manage
the comments.

Here is a screenshot:
 http://i51.tinypic.com/awfjes.jpg

The URL is: http://localhost:8080/admin/comments/comment/ (I'm
developing it locally obviously)

Someone on IRC said this might actually be a bug but I can't imagine
it's a bug. I mean, this is a serious issue and surely would have been
found before releasing this build to the public.

My admin templates are unmodified too so it's not that.

What the heck is going on?

-- 
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: contrib.comments, admin section [unable to see comments]

2010-09-14 Thread Nick
Thank you Karen, I never would have thought to look for something like
this.

Here's the situation though, there was invalid data however it's
related to contrib.comments due to how contrib.comments is structured.

My comments were displaying perfectly fine in the threads they
belonged to (not in the admin). They were pointing to the correct PKs
and all of the data was there. The problem is contrib.comments has a
"site_id" column which defaults to 1 but I didn't have contrib.sites
setup or installed (didn't feel it was necessary).

After I installed contrib.sites then it works as intended after adding
a site. I tried to set the site_id to 0 before installing
contrib.sites but that didn't fix it (random shot in the dark :D).

Perhaps contrib.comments depending on contrib.sites is a design flaw /
issue, especially with it not being documented. I'm a Django newbie
(I've been watching djangocon videos, reading community sites, reading
books, poking around the documentation in small doses) but after using
Django for only a few hours I'm already scared. Stuff like this which
can't really be Googled successfully is a newbie's worst nightmare.

On Sep 14, 8:19 pm, Karen Tracey  wrote:
> On Tue, Sep 14, 2010 at 12:52 PM, Nick <
>
>
>
>
>
> iregisteratwebsiteswitht...@gmail.com> wrote:
> > Hello,
>
> > I tried to troubleshoot this with Google and #django on IRC but I'm
> > coming up empty. I've been following the practical django projects
> > second edition book using django 1.2.3 on a local server.
>
> > I have added 'django.contrib.comments' to my settings file + adjusted
> > my urls.py file just like the book said and ran syncdb. The admin
> > section is picking up the comments "model" fine. I can post comments
> > fine and they are visible within the post, great.
>
> > When I goto the admin section and click comments, then click comments
> > again I'm presented with what should be a page to allow me to see the
> > available comments and admin them (edit, delete, etc.). The issue is
> > that the rows are empty for each comment. Instead it just gives me a
> > count of the number of comments which makes it impossible to manage
> > the comments.
>
> > Here is a screenshot:
> >  http://i51.tinypic.com/awfjes.jpg
>
> > The URL is:http://localhost:8080/admin/comments/comment/(I'm
> > developing it locally obviously)
>
> > Someone on IRC said this might actually be a bug but I can't imagine
> > it's a bug. I mean, this is a serious issue and surely would have been
> > found before releasing this build to the public.
>
> > My admin templates are unmodified too so it's not that.
>
> > What the heck is going on?
>
> When I have seen this type of thing before, it has been due to some invalid
> data in the database, see for 
> example:http://code.djangoproject.com/ticket/11460.
>
> Karen
> --http://tracey.org/kmt/

-- 
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: Tools to ease template/ui development

2010-09-15 Thread Nick
I would go with PyCharm. Unfortunately it's not free but for $49 I
don't think you'll find anything better. It has really solid template
highlighting and code complete along with the best Python/Django
support I've seen yet.

I'm still new to Django but I did spend a fair bit of time looking for
an IDE and all of them had issues. PyCharm isn't perfect but for a
beta that's being actively developed I'm sure its issues will be
resolved in time. Alternatively you can give IntelliJ (same company as
PyCharm, with the Python plugin it's basically PyCharm+supports other
languages too) a 30 day trial and hope PyCharm hits 1.0 final before
the trial runs out.

On Sep 14, 11:20 am, payala  wrote:
> Hello everybody!
>
> This is my first post over here, I'll briefly introduce myself saying
> that I am an electronic engineer fiddling with a little bit of web
> development. After trying asp and other nasty stuff, I have discovered
> Django and I am LOVING it, it is just incredible.
>
> As I said, I've been learning Django for a couple of months, and it
> makes web development really easy... to the point that template/UI
> design has become the hard part in my opinion.
>
> What resources do you guys use to ease the pain of doing a nice user
> interface??
>
> Thank you all!
> Pedro

-- 
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: syncdb problem - windows, sqlite

2010-09-15 Thread Nick
This seems to happen when you specify an incorrect path to the
database in NAME.

Fix:
Use the correct path. :D

It looks like you spelled 'frameworks' incorrectly.

On Sep 15, 12:03 pm, Aju  wrote:
> Hi,
>
> I am using the Django tutorial (Windows xp, python 2.5.4, django 1.2.3) and
> am facing a problem at the point where I have to run syncdb.
>
> python manage.py syncdb
>
> Error message (full error in the end):
>
> *  File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlite3­\base.py",
> line 174, in _cursor*
> *    self.connection = Database.connect(**kwargs)*
> *    sqlite3.OperationalError: unable to open database file*
>
> Steps taken to debug:
> 1) made sure "name" in the settings file has full path to db file.
> 2) made sure currently logged in user has full permission to containing
> folder and files.
>
> Here is the relevant portion of my setting.py file:
>
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.sqlite3',
>         'NAME': 'C:/utils/framworks/dlab2/sqlite3.db',
>         'USER': '',                      # Not used with sqlite3.
>         'PASSWORD': '',                  # Not used with sqlite3.
>         'HOST': '',                      # Set to empty string for
> localhost. Not used with sqlite3.
>         'PORT': '',                      # Set to empty string for default.
> Not used with sqlite3.
>     }
>
> }
>
> your help on this issue would be appreciated.
>
> thanks!
> Aj
> ---­--
> full error:
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
>     execute_manager(settings)
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_
> _init__.py", line 438, in execute_manager
>     utility.execute()
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\_
> _init__.py", line 379, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b
> ase.py", line 191, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b
> ase.py", line 220, in execute
>     output = self.handle(*args, **options)
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\b
> ase.py", line 351, in handle
>     return self.handle_noargs(**options)
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\core\management\c
> ommands\syncdb.py", line 52, in handle_noargs
>     cursor = connection.cursor()
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\__ini
> t__.py", line 75, in cursor
>     cursor = self._cursor()
>   File
> "C:\utils\frameworks\Python254\Lib\site-packages\django\db\backends\sqlit
> e3\base.py", line 174, in _cursor
>     self.connection = Database.connect(**kwargs)
> sqlite3.OperationalError: unable to open database file

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



Django and third party python apps, best practices for path locations?

2010-09-15 Thread Nick
Let's say you have Python installed to D:/dev/python2.6

Is it wise/common practice to put django and other third party python
libraries (like pygments or markdown) in the python2.6/Lib/site-
packages/ directory while putting your actual projects in a completely
separate location off the python path?

I ask because I want to get used to placing my python install, django
install, third party python libs, django projects, and django
applications in a familiar/standard path structure so migrating to
various web hosts will be as painless as possible plus well organized.

-- 
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 and third party python apps, best practices for path locations?

2010-09-15 Thread Nick
Yes and no. I'm familiar with the term but haven't read up on it
enough to wrap my head around installing it and getting it setup. Is
it absolutely essential to get used to working with virtualenv if you
plan to develop on a Windows machine but your production servers are
running *nix?

On Sep 15, 9:50 pm, "nick.l...@gmail.com"  wrote:
> Nick,
>
> yes...and no.
>
> Have you looked at using Virtualenv?http://pypi.python.org/pypi/virtualenv
>
> On Thu, Sep 16, 2010 at 1:44 AM, Nick 
>
>
>
>
> > wrote:
> > Let's say you have Python installed to D:/dev/python2.6
>
> > Is it wise/common practice to put django and other third party python
> > libraries (like pygments or markdown) in the python2.6/Lib/site-
> > packages/ directory while putting your actual projects in a completely
> > separate location off the python path?
>
> > I ask because I want to get used to placing my python install, django
> > install, third party python libs, django projects, and django
> > applications in a familiar/standard path structure so migrating to
> > various web hosts will be as painless as possible plus well organized.
>
> > --
> > 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.
>
> --
> Guadajuko! Vamos a correr!
>  -"Cool! we are going to run!"

-- 
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 and third party python apps, best practices for path locations?

2010-09-15 Thread Nick
Ok thanks, so I guess it's a 99% standard to have libraries installed
into the /site-packages/ because that's where setup.py installs them
to?

I never actually used that before. When I installed django I just
grabbed the zip off the site and extracted the /django/ folder
directly to /site-packages/ because I saw references to that folder in
the documentation. When time came to install markdown and pygments
(from James' book) the Python interpreter was throwing a hissy fit
because it couldn't import them. I originally placed them in a
different location other than /site-packages/ and simply referencing
the path in my IDE's settings wasn't enough (it worked for code
complete, but not running the the server).

Version control is also something I plan to get into. Fortunately the
recent djangocon videos already set me on the right path for that.
Just need to get around to setting it up and learning how to use it.

On Sep 15, 11:01 pm, Mike Dewhirst  wrote:
> On 16/09/2010 12:06pm, Nick wrote:
>
> > Yes and no. I'm familiar with the term but haven't read up on it
> > enough to wrap my head around installing it and getting it setup. Is
> > it absolutely essential to get used to working with virtualenv if you
> > plan to develop on a Windows machine but your production servers are
> > running *nix?
>
> I do that and it works ok  but I don't know whether it is
> best practice.
>
> I don't use virtualenv although it seems like a good way to segregate
> stuff for different python versions. I don't currently have a need for
> it so it is on the future list for me. Back to your "Is it absolutely
> essential" question ...
>
> No.
>
> I always install third party apps with "setup.py install" which puts
> them in the correct respective site-packages directories on both Windows
> and Linux and they "just work".
>
> I use my own source directory on Windows for my own django apps and they
> all play together on both platforms without much current thought on my part.
>
> The trick is to automate delivery of your own source to the linux web
> server directory you have chosen. I think it would complicate things
> incredibly to try and manage third party source delivery at the same time.
>
> I use subversion hook scripts to trigger svn export into the chosen
> directory every time I commit a source change on Windows. At this point
> I must say the linux machine I'm using is a staging server not a
> production server. It doesn't matter if something goes belly-up. In fact
> when the unit tests fail it is usually because I haven't installed or
> updated a third party package on the linux machine.
>
> Finally, I put a shortcut to the site-packages directory in the same
> directory as my settings.py file so I can visit third-party source
> whenever I feel like it.
>
> hth
>
> Mike
>
>
>
>
>
> > On Sep 15, 9:50 pm, "nick.l...@gmail.com"  wrote:
> >> Nick,
>
> >> yes...and no.
>
> >> Have you looked at using Virtualenv?http://pypi.python.org/pypi/virtualenv
>
> >> On Thu, Sep 16, 2010 at 1:44 AM, Nick
> >>> wrote:
> >>> Let's say you have Python installed to D:/dev/python2.6
>
> >>> Is it wise/common practice to put django and other third party python
> >>> libraries (like pygments or markdown) in the python2.6/Lib/site-
> >>> packages/ directory while putting your actual projects in a completely
> >>> separate location off the python path?
>
> >>> I ask because I want to get used to placing my python install, django
> >>> install, third party python libs, django projects, and django
> >>> applications in a familiar/standard path structure so migrating to
> >>> various web hosts will be as painless as possible plus well organized.
>
> >>> --
> >>> 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 >>>  groups.com>
> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/django-users?hl=en.
>
> >> --
> >> Guadajuko! Vamos a correr!
> >>   -"Cool! we are going to run!"

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



Why does extending a class create so much overhead?

2010-09-19 Thread Nick
I'm still a newbie to django but I think I want to start working on my
first real project and I'm kind of confused about extending another
application's features without creating overhead.

I started to investigate flat pages because I planned to have a few
flat pages however I wanted to add a few fields like meta keywords and
a meta description.

In this post:
http://stackoverflow.com/questions/1021487/add-functionality-to-django-flatpages-without-changing-the-original-django-app

One of the comment authors said that doing it this way will create
some overhead and from a newbie's POV the original method listed
seemed like the most intuitive solution. It pretty much follows the
same path as most of the tutorials/books.

Then I decided to poke around the contrib.FlatPages app and realized
the meat of the functionality is just a basic model. That makes me
believe that perhaps I should just roll my own FlatPages, maybe even
with a parent->child structure for menu items (future projects).

But then I thought I can see myself wanting to use meta keywords/
description in every single page, no question about it. Then I asked
myself what the real difference is between adding those options
directly in the django source and extending it and I couldn't answer
it beyond the obvious problems like upgrading django may cause
problems, so I'm posting it here.

The comment author hinted that it creates a new table for all extended
options but I'm curious why the new model fields can't just be added
to the original table when you sync db?

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



Manual ordering

2010-10-20 Thread Nick
I am working on the output for some data and I would like to manually
assign the order as there is no field that I can order by that will
give me the desired output. Is there a way to manually declare the
order of output based on the PKs of an entry?

-- 
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: Manual ordering

2010-10-20 Thread Nick
Worked like a charm. This was a limited case so I won't be needing any
checks to ensure that the ID's are all in the queryset since there are
only 5 or 6. Thanks again.

On Oct 20, 10:44 am, Shawn Milochik  wrote:
> Given a tuple/list of primary keys named ordered_ids and a queryset named 
> records:
>
> results = [records.get(pk = x) for x in ordered_ids]
>
> This is a naive example, as it assumes that ordered_ids will never have IDs 
> which don't exist in the queryset, but it gives a simple way to do what 
> you're asking for.
>
> 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-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.



Deciding how to start building a search form

2010-02-23 Thread Nick
I have seen many messages about this but I am at a loss for what to
do.  Currently I am building a DB of state representatives.  This DB
has to other tables besides that of the actual representative. Those
tables are for committees those members are part off.  I use
manytomany and foreign key relationships to match Reps to their
committees.

What I am looking to do is build a search form that will allow me to
query against the DB with several advanced search options for "type of
representative (senate or congress)" "home town" "district" "last
name".  A few of these will be boolean/checkbox fields and some will
be text fields.

Anyways, what I'm wondering is, should I build this up by hand or
should I use something like haystack?  I am only querying against a DB
and not en entire site.

Thanks in advance,

Nick

-- 
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: two different models, order by date

2010-02-23 Thread Nick
In the view set up something like

all = [Books.objects.all() & Movies.objects.all()].orderby('date')

On Feb 23, 2:22 pm, ds  wrote:
> Hello group,
>
> i have a simple question here, i've been trying to found the answer
> but somehow i got confused if this is wheter possible or not:
>
> I have two django models, movies and books , i want to get all the
> objects from both models and order them by date, getting result_set
> that
> might look like this:
>
> movie1
> movie2
> book1
> movie3
> book2
>
> is this possible?
> if so, where should i be reading to learn how to?
>
> thanks!
>
> damian

-- 
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: Deciding how to start building a search form

2010-02-23 Thread Nick
Thanks adam, that was the direction I was looking for.

On Feb 23, 4:57 pm, Andy McKay  wrote:
> On 2010-02-23, at 12:50 PM, Nick wrote:
>
> > Anyways, what I'm wondering is, should I build this up by hand or
> > should I use something like haystack?  I am only querying against a DB
> > and not en entire site.
>
> Doing a search on one model is pretty straightforward. If however you need to 
> do full text searches or searches on more than one model at a time, then you 
> will need something like haystack.
> --
>   Andy McKay, @clearwind
>  http://clearwind.ca/djangoski

-- 
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 search project beginneth

2010-02-26 Thread Nick
I am working on a search form for a project. I think I have down how
django handles forms (on a simple level). I am using an thml form
written in a template and passing it through a view.  I tried to write
this out as a form in a form.py file but something screwball was
happening with the file and I gave it up for the time being.

Here is my Model:


Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
First_Name = models.CharField('First Name', max_length=100,
blank=True)
Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
City = models.CharField(max_length=100, blank=True)
Phone = models.CharField(max_length=15, help_text="Use the form
xxx-xxx-", blank=True)
Email = models.EmailField(max_length=100, blank=True)
Contact_URL = models.URLField(max_length=200, blank=True)
DOB = models.DateField('Date of Birth',blank=True, null=True)
Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images', height_field=None,
width_field=None, max_length=300, blank=True)
Committees = models.ManyToManyField('Committees', blank=True)
Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)

Here are  my (still in progress, just testing things) form and views:



Button Check





def search(request):
error = False
if 'q' in request.GET:
q = request.GET['q']
party = request.GET['party']
if not q:
error = True
else:
reps =
Rep.objects.filter(Last_Name__icontains=q).filter(Party__icontains=party)
return render_to_response('Government/
search_results.html',
{'reps': reps, 'query': q})
return render_to_response('Government/search.html', {'error':
error})


What I am looking to do is create a form that has a general search
field that queries against the last and first names and then a series
of checkboxes and radio buttons (some can have multiple selections and
some can't) to filter the search based on type of representative,
district, city. etc.

I'm throwing this out as I battle through the forms processing part of
the Django book.

Thanks,
Nick

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



building a form with multiple filters

2010-03-03 Thread Nick
I am trying to build a search form with multiple filters/input
objects. Basically, i want to be able to allow for a simple searhc
based on one criteria or multiple. So if someone searches the name
field(q) they can filter by political party, or city, etc.  Also, I
would like to be able to return results without a search in the name
field(q)

Here is my model:

class Rep(models.Models):

Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
First_Name = models.CharField('First Name', max_length=100,
blank=True)
Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
City = models.CharField(max_length=100, blank=True)
Phone = models.CharField(max_length=15, help_text="Use the form
(xxx) xxx-", blank=True)
Email = models.EmailField(max_length=100, blank=True)
Contact_URL = models.URLField(max_length=200, blank=True)
DOB = models.DateField('Date of Birth',blank=True, null=True)
Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images', height_field=None,
width_field=None, max_length=300, blank=True)
Committees = models.ManyToManyField('Committees', blank=True)
Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)

my view (the search view):


def search(request):
error = False
if 'q' in request.GET:
q = request.GET.['q']
reps = Rep.objects.filter(Last_Name__contains=q)
if 'party' in request.GET:
party = request.GET.['party']
reps = reps.filter(Party__contains=party)
return render_to_response('Government/search_results.html',
{'reps': reps, 'query': q})
return render_to_response('Government/search.html', {'error':
error})


my tpl:


{% if error %}
Please submit a valid search
{% endif %}


Party

Democrat

Republican





It is set up now where I can search against the "q" and filter it
based on the "party" but I can't go beyond that. I'd like to add
district, city, and term limited in fields and have them all build on
one another. But the way I have it now I don't think I can do that.

-- 
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: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
If I'm understanding what you're asking, it should be as simple as
adding an entry per user that designates the template/theme you'd like
to use and then passing that as a variable (ex. {{ MEDIA_URL }}
{{ templatename }} where template name would be the directory name of
the template.  Let me know if I have that right.

On Mar 3, 5:17 pm, gdup  wrote:
> Hello all,
>
> I would really aprreciate it if someone could point me in the right
> direction of creating a themeing and template layer for an application
> written in django, similar to what tumblar and shopify do.
>
> I can almost put my finger on the whole concept. I know u can somehow
> serve the MEDIA_URL variable per user to serve static files, but what
> about themeing (and views)? Would u create your own tags  or just use
> djangos?
>
> Knowing django, I wont be surprised if there is already an app for
> this. Any direction would be greatly appreciated.

-- 
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: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
Ideally what you'd want to do is handle all of this

On Mar 3, 6:12 pm, gdup  wrote:
> O crap! that sounds about right. I was thinking of media_url in terms
> of only static files, didnt think of {{ templatename }} variable.
>
> As for the templating part in an app like shopify , i am not familar
> with rails, but i assume it allows you to create custom template tags
> like django. I doubt this is the method they are using? Are they
> probably just using a custom template system from scratch?
>
> On Mar 3, 5:30 pm, Nick  wrote:
>
> > If I'm understanding what you're asking, it should be as simple as
> > adding an entry per user that designates the template/theme you'd like
> > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > {{ templatename }} where template name would be the directory name of
> > the template.  Let me know if I have that right.
>
> > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > Hello all,
>
> > > I would really aprreciate it if someone could point me in the right
> > > direction of creating a themeing and template layer for an application
> > > written in django, similar to what tumblar and shopify do.
>
> > > I can almost put my finger on the whole concept. I know u can somehow
> > > serve the MEDIA_URL variable per user to serve static files, but what
> > > about themeing (and views)? Would u create your own tags  or just use
> > > djangos?
>
> > > Knowing django, I wont be surprised if there is already an app for
> > > this. Any direction would be greatly appreciated.

-- 
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: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
It seems like this would be best handled at the view level, you could
pass a url variable in the render_to_response portion, maybe something
like

def theme(request):
# a bunch of view display stuff
   theme = ThemeModel.objects.get('template__name')
   if theme:
   render_to_response('%s' u'path', {'dictionary': dictionary}
   else:
   render the default theme

The path is the directory extension of theme.  Probably just make a
foreign key relationship in the blogs settings Model and link it to a
template Model with name, thumbnail, etc. etc. etc..


On Mar 3,u 6:12 pm, gdup  wrote:
> O crap! that sounds about right. I was thinking of media_url in terms
> of only static files, didnt think of {{ templatename }} variable.
>
> As for the templating part in an app like shopify , i am not familar
> with rails, but i assume it allows you to create custom template tags
> like django. I doubt this is the method they are using? Are they
> probably just using a custom template system from scratch?
>
> On Mar 3, 5:30 pm, Nick  wrote:
>
> > If I'm understanding what you're asking, it should be as simple as
> > adding an entry per user that designates the template/theme you'd like
> > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > {{ templatename }} where template name would be the directory name of
> > the template.  Let me know if I have that right.
>
> > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > Hello all,
>
> > > I would really aprreciate it if someone could point me in the right
> > > direction of creating a themeing and template layer for an application
> > > written in django, similar to what tumblar and shopify do.
>
> > > I can almost put my finger on the whole concept. I know u can somehow
> > > serve the MEDIA_URL variable per user to serve static files, but what
> > > about themeing (and views)? Would u create your own tags  or just use
> > > djangos?
>
> > > Knowing django, I wont be surprised if there is already an app for
> > > this. Any direction would be greatly appreciated.

-- 
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: best practices for creating a template/theming layer for users in a django app

2010-03-04 Thread Nick
sorry, let me rewrite that last part

render_to_response ('%s/index.html' u'theme', {'dictionary':
dictionary})

On Mar 4, 12:11 am, Nick  wrote:
> It seems like this would be best handled at the view level, you could
> pass a url variable in the render_to_response portion, maybe something
> like
>
> def theme(request):
>     # a bunch of view display stuff
>    theme = ThemeModel.objects.get('template__name')
>    if theme:
>        render_to_response('%s' u'path', {'dictionary': dictionary}
>    else:
>        render the default theme
>
> The path is the directory extension of theme.  Probably just make a
> foreign key relationship in the blogs settings Model and link it to a
> template Model with name, thumbnail, etc. etc. etc..
>
> On Mar 3,u 6:12 pm, gdup  wrote:
>
> > O crap! that sounds about right. I was thinking of media_url in terms
> > of only static files, didnt think of {{ templatename }} variable.
>
> > As for the templating part in an app like shopify , i am not familar
> > with rails, but i assume it allows you to create custom template tags
> > like django. I doubt this is the method they are using? Are they
> > probably just using a custom template system from scratch?
>
> > On Mar 3, 5:30 pm, Nick  wrote:
>
> > > If I'm understanding what you're asking, it should be as simple as
> > > adding an entry per user that designates the template/theme you'd like
> > > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > > {{ templatename }} where template name would be the directory name of
> > > the template.  Let me know if I have that right.
>
> > > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > > Hello all,
>
> > > > I would really aprreciate it if someone could point me in the right
> > > > direction of creating a themeing and template layer for an application
> > > > written in django, similar to what tumblar and shopify do.
>
> > > > I can almost put my finger on the whole concept. I know u can somehow
> > > > serve the MEDIA_URL variable per user to serve static files, but what
> > > > about themeing (and views)? Would u create your own tags  or just use
> > > > djangos?
>
> > > > Knowing django, I wont be surprised if there is already an app for
> > > > this. Any direction would be greatly appreciated.

-- 
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: modify date in django twitter app

2010-03-08 Thread Nick
I think this may help

http://www.magpiebrain.com/2005/08/21/formatting-dates-with-django/

try using strftime and formatting from there.

On Mar 8, 3:16 pm, "het.oosten"  wrote:
> I forgot to mention that my desired output of the date is:
> 2010-02-22 20:46:03
>
> On 8 mrt, 22:13, "het.oosten"  wrote:
>
> > I am getting somewhere now:
>
> > import datetime
> > import time
> > import twitter
>
> > tweet  = twitter.Api().GetUserTimeline('username', count=3)
> > for s in tweet:
> >         s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
> > %b %d %H:%M:%S + %Y" )[0:6]))
> > print [x.text for x in tweet]
> > print [y.date for y in tweet]
>
> > However the output is now:
> > [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
> > 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]
>
> > I still miss a little thing to completeanybody a little hint?

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



Extending a custom built API

2010-03-08 Thread Nick
I am working on an api that outputs a list of JSON based on certain
criteria.  Currently if someone enters http://example.mysite/slideshows/api?id=1
it returns a JSON serialized output of the slideshow with that ID.

What I would like to do is allow for multiple ids, so
http://example.mysite/slideshows/api?id=1,2,5,9,10 will pull in JSON
values for each of those slideshows.

I'd like to keep from using a third party API solution, I have checked
them out and I like the customization with the hand built process

I am doing everything through a get process in a view, here it is:


def slideshowAPI2(request):
error = False
if 'id' in request.GET and request.GET['id']:
id = request.GET['id']
object = slideshow.objects.get(pk=id)
return render_to_response('slideshow.json',
{'object': object, 'id':id})
if 'year' in request.GET and request.GET['year']:
year = request.GET['year']
object = serializers.serialize("json",
slideshow.objects.filter(publishdate__year=year))
html = "%s" % object
return HttpResponse(html)
else:
error = True
return render_to_response('slideshow.json', {'error': True})

-- 
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: Extending a custom built API

2010-03-08 Thread Nick
Thanks, I did a little changing around but what you recommended was
spot on. Here is the final view

def slideshowAPI2(request):
error = False
if 'id' in request.GET and request.GET['id']:
id = request.GET.get('id')
ids = id.split(',')
object = slideshow.objects.filter(id__in=ids)
return render_to_response('slideshow.json', {'object':
object})
if 'year' in request.GET and request.GET['year']:
year = request.GET['year']
object = serializers.serialize("json",
slideshow.objects.filter(publishdate__year=year))
html = "%s" % object
return HttpResponse(html)
else:
error = True
return render_to_response('slideshow.json', {'error': True})


On Mar 8, 5:18 pm, felix  wrote:
> you are already basically there
>
> id = request.GET.get('id')
> if id:
>   ids = id.split(',')
>   slideshows = slideshow.objects.filter(id__in=ids)
>
> then returns that as json however you like
>
> On Mar 8, 11:41 pm, Nick  wrote:
>
> > I am working on an api that outputs a list of JSON based on certain
> > criteria.  Currently if someone 
> > entershttp://example.mysite/slideshows/api?id=1
> > it returns a JSON serialized output of the slideshow with that ID.
>
> > What I would like to do is allow for multiple ids, 
> > sohttp://example.mysite/slideshows/api?id=1,2,5,9,10willpull in JSON
> > values for each of those slideshows.
>
> > I'd like to keep from using a third party API solution, I have checked
> > them out and I like the customization with the hand built process
>
> > I am doing everything through a get process in a view, here it is:
>
> > def slideshowAPI2(request):
> >     error = False
> >     if 'id' in request.GET and request.GET['id']:
> >         id = request.GET['id']
> >         object = slideshow.objects.get(pk=id)
> >         return render_to_response('slideshow.json',
> >             {'object': object, 'id':id})
> >     if 'year' in request.GET and request.GET['year']:
> >         year = request.GET['year']
> >         object = serializers.serialize("json",
> > slideshow.objects.filter(publishdate__year=year))
> >         html = "%s" % object
> >         return HttpResponse(html)
> >     else:
> >         error = True
> >         return render_to_response('slideshow.json', {'error': True})

-- 
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: Extending a custom built API

2010-03-09 Thread Nick
Thanks for the reference and critique, Tom. Currently this is an
internal API to connect two systems together. The query structure was
requested from one set of developers. I am planning on setting up an
external API for another project and this will be helpful in creating
a standard structure.

On Mar 9, 11:03 am, Tom Evans  wrote:
> On Mon, Mar 8, 2010 at 10:41 PM, Nick  wrote:
> > I am working on an api that outputs a list of JSON based on certain
> > criteria.  Currently if someone 
> > entershttp://example.mysite/slideshows/api?id=1
> > it returns a JSON serialized output of the slideshow with that ID.
>
> > What I would like to do is allow for multiple ids, so
> >http://example.mysite/slideshows/api?id=1,2,5,9,10will pull in JSON
> > values for each of those slideshows.
>
> > I'd like to keep from using a third party API solution, I have checked
> > them out and I like the customization with the hand built process
>
> > I am doing everything through a get process in a view, here it is:
>
> > def slideshowAPI2(request):
> >    error = False
> >    if 'id' in request.GET and request.GET['id']:
> >        id = request.GET['id']
> >        object = slideshow.objects.get(pk=id)
> >        return render_to_response('slideshow.json',
> >            {'object': object, 'id':id})
> >    if 'year' in request.GET and request.GET['year']:
> >        year = request.GET['year']
> >        object = serializers.serialize("json",
> > slideshow.objects.filter(publishdate__year=year))
> >        html = "%s" % object
> >        return HttpResponse(html)
> >    else:
> >        error = True
> >        return render_to_response('slideshow.json', {'error': True})
>
> Just a mild critique:
>
> http://example.mysite/slideshows/api?id=1,2,5,9,10
>
> This is not the usual or typical way to pass a list of values into a
> url query string. Typically, you would specify the id argument
> multiple times in the query string. This is how your browser, a JS
> framework, django or anything that is designed to parse query strings
> would expect to receive a list of values. Eg:
>
> http://example.mysite/slideshows/api?id=1&id=2&id=5&id=9&id=10
>
> In django, you can retrieve a list of values passed in a query string
> like this with the getlist() method on QueryDict[1]. Eg:
>
> if 'id' in request.POST:
>   ids = request.POST.getlist('id')
>
> Cheers
>
> Tom
>
> [1]http://docs.djangoproject.com/en/1.1/ref/request-response/#django.htt...

-- 
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: making query using filter()

2010-03-10 Thread Nick
Sounds like what you want is something like:

MyCategories = Category.objects.exclude(name!='mycateogry')

only problem is, django doesn't support the != operator so you're
going to have to go with a query object:

add this to your view

from django.db.models import Q (importing the Q object
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects,
here's another good article on Q objects 
http://www.djangozen.com/blog/the-power-of-q)

mycategory=Category.objects.exclude(~Q(name='mycategoy') (the ~Q is
equivalent to "this query DOES NOT EQUAL)



I don't have a model like this set up anywhere so I don't know if this
will properly filter those results with both 'mycategory' and other
categories as well.

On Mar 10, 6:24 am, rebus_  wrote:
> On 10 March 2010 12:06, jimgardener  wrote:
>
>
>
> > Hi
> > I need to make a query as follows
> > Select all entries where categories=mycategory
>
> > In the db there are entries and categories as follows
> > Category.objects.all() -->[ , > hiscategory>,]
>
> > MyEntry.objects.all() --> [  , > [u'mycategory',u'hiscategory' ]>, ]
>
> > I tried like this
> > mycategory=Category.objects.get(name='mycategory')
> > MyEntry.objects.filter(categories=mycategory)
>
> > But this returns entries where the categories field contains
> > 'mycategory' and 'hiscategory' also.
> > How do I mention to retrieve only 'mycategory'.
>
> > I went through the Queryset docs ..but couldn't figure it out...
> > Any help would be appreciated
> > thanks
> > jim
>
> > p.s:
>
> > My models are
> > class MyEntry(models.Model):
> >    categories=models.ManyToManyField(Category)
>
> > class Category(models.Model):
> >    name=models.CharField(unique=True,max_length=50)
>
> > --
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> [  , 
>
> Well that's what it is supposed to do, both Entry objects have
> relation to "mycategory".

-- 
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: if statement with url

2010-03-10 Thread Nick
Just pop this into your template:

{% url Path.to.a.view.for.this.template as the_url %}
# you are importing a view's url structure right here and then storing
it as "the_url". Since you're not looking for anything dynamic we can
end that definition here (more here 
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url)
then
{% ifequal the_url "/the/url/to/check" %} pretty self explanatory
this is the result if that is true
{% endifequal %}

It might be a good idea to check this before adding any conditional
statement:


{% url Path.to.a.view.for.this.template as the_url %}
{{ the_url }} should output the relative URL (django calls relative
paths absolute paths for some reason)





On Mar 10, 3:42 pm, HARRY POTTRER  wrote:
> maybe try request.path?
>
> On Mar 10, 1:51 pm, Daxal  wrote:
>
> > Hey,
>
> > I wanted to use a if statement with a url like ...
>
> > if you are on "/cm/add/"
> > ..
> > endif
> > .
> > option 1:
> > I was wondering if anyone knows how to code that statement. if can
> > compare string variables like {% ifequal somevariable url %} where
> > "url" can be hard coded like "/cm/add" and somevariable would have to
> > store the url which i think is too complex.
>
> > option 2:
> > some if statement that directly compares the url like {% if {url} == "/
> > cm/add/" %}
>
> > any thoughts and ideas guys?
>
> > Thank you for all your replies. :)

-- 
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: Filtering by another object's ManyToMany properties

2010-03-10 Thread Nick
try search__questions.id

the __ spans the many to many relationship

On Mar 10, 4:38 pm, Laereom  wrote:
> I have two models, we'll call them 'Question' and 'Search'.
>
> Search has a many to many field called 'questions' which contain,
> naturally, a set of questions.
>
> I want to retrieve a Question which is associated with a particular
> Search through that many to many field.
>
> It seemed straightforward -- I wrote something like this:
>
> search = Search.objects.get(myCriteria)
> question = Question.objects.filter(id=search.questions.id)
>
> However, I'm getting an AttributeError:
>
> 'ManyRelatedManager' object has no attribute 'id'
>
> Any advice?

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



SQL Server 2008 and django

2010-03-11 Thread Nick
I am working on a new project that has a Microsoft SQL Server 2008 for
storing data. Can I bind Python and Django with this DB? Are there any
performance issues involved? What sort of server configuration needs
to be done?

This is for a job and so I can't really use something that's not been
tested and is reliable.

Thanks in advance for any responses.

Nick

-- 
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: SQL Server 2008 and django

2010-03-12 Thread Nick
Thanks for the info, glad there weren't any major issues that popped
up that would derail this development path. Since we have a windows
box that is hosting the DB I think we're going to run with mssql, it
appears to properly handle the multi-db issue.

On Mar 12, 1:26 am, David  wrote:
> As the stackoverflow link states, pyodbc is the most advanced sql
> server library for python. Quite a few libraries use it like
> sqlalchemy. If you are using Django on Linux, your only options are
> django-pyodbc or use sqlalchemy outside of the Django ORM. If your
> environment is on Windows, you can also use django-mssql. I am
> currently using django-pyodbc on a project with Django 1.2b and I
> can't exactly call django-pyodbc stable with multiple databases. In
> testing, I didn't have any problems with django-pyodbc with Django
> 1.1.
>
> On Mar 11, 8:29 pm, Sam Lai  wrote:
>
> >http://stackoverflow.com/questions/842831/using-sql-server-with-djang...
>
> > Might help. No personal experience though.
>
> > On 12 March 2010 12:16, Nick  wrote:
>
> > > I am working on a new project that has a Microsoft SQL Server 2008 for
> > > storing data. Can I bind Python and Django with this DB? Are there any
> > > performance issues involved? What sort of server configuration needs
> > > to be done?
>
> > > This is for a job and so I can't really use something that's not been
> > > tested and is reliable.
>
> > > Thanks in advance for any responses.
>
> > > Nick
>
> > > --
> > > 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 
> > > athttp://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.



Modifying admin to filter choices

2010-03-16 Thread Nick
I am working on a project that has a portion of the admin with three
different "choices" options.  The section of the model that this
thread is concerned with looks like this:

Department_Choices = (
('Advertising', 'Advertisinf'),
('NIC', 'NIC'),
('Production', 'Production'),
)

Department_Groups = ( #Advertising has three groups, NIC has 5,
Produciton has 5
('Auto Sales', 'Auto Sales'),
('Print Production', 'Print Production'),
)

Subgroups = ( #some groups have sub-groups (ex. Auto Sales has print
and online subgroups)
('Online', 'Online'),
('Print', 'Print'),
)

# model

department = models.Charfield(choices=Department_Choices)
group = models.CharField(choices=Department_Goups)
subgroup - models.CharField(choices=Subgroups)

I would like to have something in place that filters the groups and
subgroups based on the department. So, if I choose Advertising in
departments it brings up applicable groups, if I bring up Auto in
groups it brings up applicable subgroups.

Does Django have a built in way of handling this, do I need to modify
the admin template? Do I need to forget about entering this in the
admin and create a form with a bunch of AJAX involved?

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



RSS feeds of model instances by tag

2010-04-04 Thread Nick
I have a question about RSS feeds for objects by tag.

I'm using this statement currently in a feed class items method, which
accepts a tag as an 'obj' parameter:

return Model.objects.filter(tags__icontains=obj.name).order_by('-
pub_date')[:10]

This statement works, but I get mixed results in my QuerySet based on
whether I filter by 'icontains' or 'exact'.

For example, filtering for the tag 'test' matches 'test', 'tag-
testing', and 'testing'. I only want objects tagged with 'test'. If I
use the 'exact' lookup, if the field contains more than one tag, it
won't find the tag at all.

I know there's a good generic view for this, tagged_object_list, but I
need a request object to use it, and my feed class doesn't accept or
create request objects that I know of.

How would I translate the following sql query into a chained QuerySet
statement:

select *
from model m
inner join taggeditem ti
on m.id = ti.object_id
inner join tag t
on ti.tag_id = t.id
where t.name = obj.name

Is there a better way to do this? The problem with the TagField() is
it can be multivalued.

Is there a way to split a tag field and then do a match on each item
in the list?

Any suggestions?

I'm scripting in Django 1.1, using postgreSQL, and Windows XP.

Thank you very much.

Nick

-- 
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: admin page will not display

2010-04-13 Thread Nick
try resetting your server

On Apr 13, 4:50 pm, NicMAN  wrote:
> Hi all, i recently tried to open my admin page and it won't let me
> open it keeps saying
>
> Caught an exception while rendering: Tried create_user in module
> applications.views. Error was: 'module' object has no attribute
> 'create_user'
>
> but i don't have a my create_user code anymore, i deleted it because i
> didn't need it, then it is giving out about the base.html page saying
> there is an error in that and i haven't modified the admin base.html
> page at all. here is the error on LINE 30
>
> 20          
> 21          
> 22              
> 23              {% block branding %}{% endblock %}
> 24              
> 25              {% if user.is_authenticated and user.is_staff %}
> 26              
> 27                  {% trans 'Welcome,' %}
> 28                  {% firstof user.first_name user.username %} strong>.
> 29                  {% block userlinks %}
> 30                      {% url django-admindocs-docroot as docsroot %}
> ##error here
> 31                      {% if docsroot %}
> 32                          {% trans
> 'Documentation' %} /
> 33                      {% endif %}
> 34                      {% url admin:password_change as password_change_url
> %}
> 35                      {% if password_change_url %}
> 36                          
> 37                      {% else %}
> 38                          
> 39                      {% endif %}
> 40                      {% trans 'Change password' %} /
>
> if anyone could help me i would be very grateful, 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: Running django on IIS

2010-04-21 Thread Nick
Hiya

I have exactly the same problem as described here.

Did you (or anyone) find a fix or workaround for this?

Cheers!
Nick.



On Apr 14, 12:24 pm, Paweł Roman  wrote:
> > I suspect it is trying to import Http but can't.
>
> > Fire up python (Start -> Python Interactive Shell, or Start -> Run ->
> > cmd -> type python), and type:
>
> > import Http
> > If that doesn't work, you haven't installed it properly. See the
> > following quote from the Django wiki:
>
> > "•Go to c:\pyisapie\source\PyISAPIe\Python\ and copy the entire Http
> > folder to c:\python25\lib\site-packages. Note: the Http folder is case
> > sensitive. Saving in 'http' (or any other variation) will not work
> > [SF]. "
>
> I've copied Http to site-packeges. "import Http" works OK.
>
> Interesting thing is that running "from Http import *"  fails
> (AttributeError: 'module' object has no attribute 'Read'), but I guess
> this has something to do with the fact that Http's __init__.py tries
> to set __all__ (in other words: import) modules that are not in the
> filesystem, but somewhere in the pyisapie.dll (?), like the mentioned
> 'Read'. There is even a comment line that says #From DLL. I don't know
> how this is supposed to work, i.e. how python can import modules from
> dll (?), I even included tha path to the DLL in the pytonpath, just in
> case, but it didnt help.

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



send_mail being a royal jerk

2010-04-21 Thread Nick
I am working on a form that takes a little data and throws it in a
database, but before all that jazz it sends an email to a list/tuple
of recipients. This is going very well except the send_mail process is
raising a very annoying and persistent error:

"to" argument must be a list or tuple

Here is the view:

def short_form(request):
if request.method == 'POST':
form = ArtistFormFinal(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data['name']
year_created = form.cleaned_data['year_created']
home_city = form.cleaned_data['home_city']
home_state = form.cleaned_data['home_state']
genre = form.cleaned_data['genre']
email_address = form.cleaned_data['email_address']
phone_number = form.cleaned_data['phone_number']
website = form.cleaned_data['website']
audio = form.cleaned_data['audio_file']
recipients = ['ntankers...@opubco.com']
send_mail(name, year_created, home_city, home_state,
recipients)
form.save()
return HttpResponseRedirect('thanks')
else:
form = ArtistFormFinal()
return render_to_response('static/artist_short.html',
{'form':form})

Now, it looks like it is getting hung up on recipients. This is a
tuple, one value. What am I missing here?

-- 
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: send_mail being a royal jerk

2010-04-21 Thread Nick
Thanks, Karen. Looks like I was a little cart before the horse on this
portion of the project.

On Apr 21, 6:28 pm, Karen Tracey  wrote:
> On Wed, Apr 21, 2010 at 6:09 PM, Nick  wrote:
> > I am working on a form that takes a little data and throws it in a
> > database, but before all that jazz it sends an email to a list/tuple
> > of recipients. This is going very well except the send_mail process is
> > raising a very annoying and persistent error:
>
> > "to" argument must be a list or tuple
>
> > Here is the view:
>
> > def short_form(request):
> > [snip]
>
>    recipients = ['ntankers...@opubco.com']
>
> >            send_mail(name, year_created, home_city, home_state,
> > recipients)
> > [snip]
>
> Now, it looks like it is getting hung up on recipients. This is a> tuple, one 
> value. What am I missing here?
>
> Perhttp://docs.djangoproject.com/en/dev/topics/email/#send-mailthe "To:"
> field is the 4th positional parameter to send_mail, you've specified
> recipients as the 5th. (It isn't exactly clear that some of the earlier ones
> match up in meaning to what they are supposed to be either, even if they are
> OK as far as datatype goes.)
>
> Karen
>
> --
> 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 
> athttp://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.



Retrieving an ID from a posted form

2010-04-22 Thread Nick
I am working on a form process with multiple levels of submission. The
first is a front facing form with a general set of questions that are
to be followed up by someone after the form is submitted (the form
submits and entry to the DB).  To cut down on the amount of hunting
that those who will be reviewing the forms have to do I'd like to be
able to retrieve the ID for the newly created DB entry and attach it
to a url that points directly to that entry in the django admin.

I have the email logic set up so that the form submits all of the
information via email to an individual. In the email is the link to
the admin. So far it just goes to a full list of entries:

ex. http://mydjango.site.com/admin/projects/app/model_name/ID

I can easily send everything up to the ID. How do i retrieve the ID
from the submitted form. Since this is adding an entry to the DB it
has to be creating an ID somewhere.  Here is my view:

def short_form(request):
if request.method == 'POST':
form = ArtistFormFinal(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data['name']
year_created = form.cleaned_data['year_created']
home_city = form.cleaned_data['home_city']
home_state = form.cleaned_data['home_state']
genre = form.cleaned_data['genre']
email_address = form.cleaned_data['email_address']
phone_number = form.cleaned_data['phone_number']
website = form.cleaned_data['website']
audio = form.cleaned_data['audio_file']
subject = 'Static artists submission from %s' % (name)
message = render_to_string('static/short_email.txt', {
'name': name,
'year_created': year_created,
'home_city': home_city,
'genre': genre,
'home_state': home_state,
'email_address': email_address,
'phone_number': phone_number,
'website': website,
'audio': audio
})
recipients = ['ntankers...@opubco.com',
'crobi...@opubco.com']
send_mail(subject, message, email_address, recipients,
fail_silently=False)
form.save()
return HttpResponseRedirect('thanks')
else:
form = ArtistFormFinal()
return render_to_response('static/artist_short.html',
{'form':form})

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



  1   2   3   4   5   6   7   >