Customising slugify filter
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
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
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: lighttpd + fcgi + FORCE_SCRIPT_NAME = admin grief
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
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 -~--~~~~--~~--~--~---
Re: Validating ImageField width and height in admin site
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
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 -~--~~~~--~~--~--~---
Re: Django critter helps us code at the speed of light.
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 -~--~~~~--~~--~--~---
Need to upload outside of MEDIA_ROOT, but I get SuspiciousOperation error
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 -~--~~~~--~~--~--~---
Admin of an Admin for an E-Commerce Page
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 -~--~~~~--~~--~--~---
localhost:8000 problem
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
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
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...
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 -~--~~~~--~~--~--~---
Django-Storages
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()
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()
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()
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
starting a project in windows xp
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
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.
Re: Running django on IIS
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
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
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
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.
Re: Retrieving an ID from a posted form
works like a charm, thanks Ian. On Apr 22, 10:02 am, Ian Lewis wrote: > Nick, > > Because you won't get an id for your newly created object before you > save it you'll need to send the email after you save the form. I'm > assuming that ArtistFormFinal is a ModelForm but you can get the id > using something like the following: > > myobj = form.save() > send_mail(subject, "Your id is %d!" % myobj.id, email_address, recipients) > > I hope that's what you were looking for. > > Ian > > > > On Thu, Apr 22, 2010 at 11:39 PM, Nick wrote: > > 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 > > athttp://groups.google.com/group/django-users?hl=en. > > -- > === > 株式会社ビープラウド イアン・ルイス > 〒150-0021 > 東京都渋谷区恵比寿西2-3-2 NSビル6階 > email: ianmle...@beproud.jp > TEL:03-6416-9836 > FAX:03-6416-9837http://www.beproud.jp/ > === > > -- > 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.
Re: Template composition: Rendering based on permissions
The bible for user authentication is found here http://docs.djangoproject.com/en/1.1/topics/auth/ The quick answer to number 2 is to check for authentication in a template tag: {% if user.is_authenticated %} Welcome back you rotten jerk {% else %} Log in, you rotten jerk {% endif %} On Apr 28, 2:46 pm, Thomas Allen wrote: > I think that template context processors are the answer to my first > question. As for my second question, I could certainly check for > permission membership in the provided PermWrapper, but I'm very > interested in a way to check this based on the view permission > requirement (implicitly). > > Thomas > > -- > 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.
Setting readonly_fields dynamically
Hi, I would like to set some fields to be readonly in the Admin app based on some logic, and would like to use the new readonly_fields attribute of ModelAdmin if possible (rather than some other sort of hack). I'm trying to access readonly_fields, but get the error "'GalleryForm' object has no attribute 'readonly_fields'" My code is currently as follows: class GalleryAdminForm(forms.ModelForm): class Meta: model = Gallery def __init__(self, *args, **kwargs): super(GalleryAdminForm, self).__init__(*args, **kwargs) print self.readonly_fields Any help on how I can access readonly_fields from the ModelForm to override it would be really helpful! 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: Setting readonly_fields dynamically
Yes that works, totally missed the get_readonly_fields method - thanks! Nick On Apr 29, 4:40 pm, Daniel Roseman wrote: > On Apr 29, 3:43 pm, Nick wrote: > > > > > > > Hi, > > > I would like to set some fields to be readonly in the Admin app based > > on some logic, and would like to use the new readonly_fields attribute > > of ModelAdmin if possible (rather than some other sort of hack). > > > I'm trying to access readonly_fields, but get the error "'GalleryForm' > > object has no attribute 'readonly_fields'" > > > My code is currently as follows: > > > class GalleryAdminForm(forms.ModelForm): > > class Meta: > > model = Gallery > > def __init__(self, *args, **kwargs): > > super(GalleryAdminForm, self).__init__(*args, **kwargs) > > print self.readonly_fields > > > Any help on how I can access readonly_fields from the ModelForm to > > override it would be really helpful! > > > Thanks, > > Nick > > I haven't played with it myself, but surely readonly_fields is an > attribute of the ModelAdmin subclass, not the form? > > It looks like there's a get_readonly_fields method on the base > ModelAdmin class, which takes the request as a parameter, so you > should be able to override that and return a customised tuple as > required. > -- > 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 > 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.
Working out some custom API stuff
Here's the deal. I'm working on a custom API for moving information about. I am stuck at a point in creating my view. It might be best just to get into the details. Here is the model: class entry(models.Model): question = models.CharField('Question', max_length=200, blank=False) answer = models.TextField('Answer', blank=False) answerer = models.CharField("Expert's Name", max_length=100, blank=False) credentials = models.CharField ("Expert's Credentials", max_length=100, blank=False) published = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) site = models.ForeignKey(Site) section = TagField() Once a site is picked the feed is narrowed down by id (whether single id, list or range), then by section (single or multiple) and finally some pagination and count params (I'm not worried about that right now). Currently, I am stuck on the section portion. I may be going about this all wrong. What I would like is for some URL like: http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME to produce a JSON output of Questions and Answers under that site with that section name. Here is my view: def QandAAPI(request, site): quest = entry.objects.filter(site__name__icontains=site) if 'id' in request.GET: id = request.GET.get('id','') id = id.split(',') else: id = quest.values_list('id', flat=True) if 'sect' in request.GET: sect = request.GET.get('sect','') else: sect = '' quest = quest.filter(id__in=id, section=sect) object = serializers.serialize("json", quest) json = "%s" % object return HttpResponse(json) Basically, I would like the "else: sect=" to be a WILDCARD so if the sect portion of the API isn't explicitly stated then it just pulls everything. What do you think? Raw SQL? I'm a complete bonehead? All opinions/ advice are welcome. -- 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: Working out some custom API stuff
Thanks for the help on that portion, it is working wonderfully. I've been able to power through most of the requests for this project but there is one outstanding element in regards to pagination. Here is my view: def QandAAPI(request, site): quest = entry.objects.filter(site__name__icontains=site) if 'id' in request.GET: ids = request.GET.getlist('id') quest = quest.filter(id__in=ids) if 'sect' in request.GET: sect = request.GET.getlist('sect') quest = TaggedItem.objects.get_by_model(quest, sect) if 's' in request.GET: s = request.GET['s'] search_query = ( Q(question__icontains=s) | Q(answer__icontains=s) | Q(answerer__icontains=s) ) quest = quest.filter(search_query) if 'count' in request.GET and not 'page' in request.GET: count = request.GET['count'] quest = quest[:count] if 'count' in request.GET and 'page' in request.GET: page = int(request.GET['page']) count = request.GET['count'] paginator = Paginator(quest, count) try: page = paginator.page(page) except ValueError: page = 1 json = serializers.serialize("json", quest) return HttpResponse(json) I am getting the following error when I try to plug a page=1 into the URL coercing to Unicode: need string or buffer, int found I'm not entirely sure how to fix this error, I've tried many times. The final view should do the following: Check to see if 'page' and 'coutn' are part of the url. If they are, then pull up the results of that page with the count declared in the URL. There will be another component that will skip the 'count' if it isn't declared but I haven't got there yet. On May 5, 4:11 am, Daniel Roseman wrote: > On May 5, 4:46 am, Nick wrote: > > > > > Here's the deal. I'm working on a customAPIfor moving information > > about. I am stuck at a point in creating my view. > > It might be best just to get into the details. > > > Here is the model: > > > class entry(models.Model): > > question = models.CharField('Question', max_length=200, > > blank=False) > > answer = models.TextField('Answer', blank=False) > > answerer = models.CharField("Expert's Name", max_length=100, > > blank=False) > > credentials = models.CharField ("Expert's Credentials", > > max_length=100, blank=False) > > published = models.DateTimeField(auto_now_add=True) > > updated = models.DateTimeField(auto_now=True) > > site = models.ForeignKey(Site) > > section = TagField() > > > Once a site is picked the feed is narrowed down by id (whether single > > id, list or range), then by section (single or multiple) and finally > > some pagination and count params (I'm not worried about that right > > now). Currently, I am stuck on the section portion. I may be going > > about this all wrong. What I would like is for some URL like: > > >http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME > > > to produce a JSON output of Questions and Answers under that site with > > that section name. Here is my view: > > > def QandAAPI(request, site): > > quest = entry.objects.filter(site__name__icontains=site) > > if 'id' in request.GET: > > id = request.GET.get('id','') > > id = id.split(',') > > else: > > id = quest.values_list('id', flat=True) > > if 'sect' in request.GET: > > sect = request.GET.get('sect','') > > else: > > sect = '' > > quest = quest.filter(id__in=id, section=sect) > > object = serializers.serialize("json", quest) > > json = "%s" % object > > return HttpResponse(json) > > > Basically, I would like the "else: sect=" to be a WILDCARD so if the > > sect portion of theAPIisn't explicitly stated then it just pulls > > everything. > > > What do you think? Raw SQL? I'm a complete bonehead? All opinions/ > > advice are welcome. > > I wouldn't call you a bonehead, but the method you're using to get all > the objects when no id is passed in is... well... special. > > The key to doing this sort of filtering is to remember that QuerySets > are lazy, and successive filters can be applied to them without > hitting the database, until the time comes to actually evaluate them. > So w
Re: Working out some custom API stuff
Never mind this, I got it figured out. Thanks again On May 6, 12:51 pm, Nick wrote: > Thanks for the help on that portion, it is working wonderfully. > > I've been able to power through most of the requests for this project > but there is one outstanding element in regards to pagination. > > Here is my view: > > def QandAAPI(request, site): > quest = entry.objects.filter(site__name__icontains=site) > if 'id' in request.GET: > ids = request.GET.getlist('id') > quest = quest.filter(id__in=ids) > if 'sect' in request.GET: > sect = request.GET.getlist('sect') > quest = TaggedItem.objects.get_by_model(quest, sect) > if 's' in request.GET: > s = request.GET['s'] > search_query = ( > Q(question__icontains=s) | Q(answer__icontains=s) | > Q(answerer__icontains=s) > ) > quest = quest.filter(search_query) > if 'count' in request.GET and not 'page' in request.GET: > count = request.GET['count'] > quest = quest[:count] > if 'count' in request.GET and 'page' in request.GET: > page = int(request.GET['page']) > count = request.GET['count'] > paginator = Paginator(quest, count) > try: > page = paginator.page(page) > except ValueError: > page = 1 > json = serializers.serialize("json", quest) > return HttpResponse(json) > > I am getting the following error when I try to plug a page=1 into the > URL > > coercing to Unicode: need string or buffer, int found > > I'm not entirely sure how to fix this error, I've tried many times. > > The final view should do the following: > > Check to see if 'page' and 'coutn' are part of the url. If they are, > then pull up the results of that page with the count declared in the > URL. > > There will be another component that will skip the 'count' if it isn't > declared but I haven't got there yet. > > On May 5, 4:11 am, Daniel Roseman wrote: > > > > > On May 5, 4:46 am, Nick wrote: > > > > Here's the deal. I'm working on a customAPIfor moving information > > > about. I am stuck at a point in creating my view. > > > It might be best just to get into the details. > > > > Here is the model: > > > > class entry(models.Model): > > > question = models.CharField('Question', max_length=200, > > > blank=False) > > > answer = models.TextField('Answer', blank=False) > > > answerer = models.CharField("Expert's Name", max_length=100, > > > blank=False) > > > credentials = models.CharField ("Expert's Credentials", > > > max_length=100, blank=False) > > > published = models.DateTimeField(auto_now_add=True) > > > updated = models.DateTimeField(auto_now=True) > > > site = models.ForeignKey(Site) > > > section = TagField() > > > > Once a site is picked the feed is narrowed down by id (whether single > > > id, list or range), then by section (single or multiple) and finally > > > some pagination and count params (I'm not worried about that right > > > now). Currently, I am stuck on the section portion. I may be going > > > about this all wrong. What I would like is for some URL like: > > > >http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME > > > > to produce a JSON output of Questions and Answers under that site with > > > that section name. Here is my view: > > > > def QandAAPI(request, site): > > > quest = entry.objects.filter(site__name__icontains=site) > > > if 'id' in request.GET: > > > id = request.GET.get('id','') > > > id = id.split(',') > > > else: > > > id = quest.values_list('id', flat=True) > > > if 'sect' in request.GET: > > > sect = request.GET.get('sect','') > > > else: > > > sect = '' > > > quest = quest.filter(id__in=id, section=sect) > > > object = serializers.serialize("json", quest) > > > json = "%s" % object > > > return HttpResponse(json) > > > > Basically, I would like the "else: sect=" to be a WILDCARD so if the > > > sect portion of theAPIisn't ex
Paginating search results
I'm trying to paginate results from a search with multiple options. The only problem is, once I hit the next button it clears the query and I'm left paginating all the objects in the DB. Here is my view: def filter_search(request): if request.POST: reps = Rep.objects.all() else: reps = [] query = request.POST if 'q' in request.POST: q = request.POST.get('q', '') qset = ( Q(Last_Name__icontains=q) | Q(First_Name__icontains=1) ) reps = reps.filter(qset) else: q = [] if len(q): qlist = q else: qlist = [] if 'party' in request.POST: party = request.POST.getlist('party') reps = reps.filter(Party__in=party) else: party = [] if len(party): plist = party else: plist = [] paginator = Paginator(reps, 15) results = paginator.count try: page = int(request.POST.get('page', '1')) except: page = 1 try: repList = paginator.page(page) except (EmptyPage, InvalidPage): repList = paginator.page(paginator.num_pages) finalq = request.POST return render_to_response("Government/search.html", { 'reps': repList, 'query': query, 'plist': plist, 'qlist': qlist, 'results': results, 'finalq': finalq }) Here is my tpl: Democrat Republican {% if query %} Your search for {% if qlist %} {{ qlist}} {% endif %} {% if plist %} {% for p in plist %} {% if forloop.first %} Party ({{ p }}) {% else %} & Party ({{p}}) {% endif %} {% endfor %}{% endif %} returned {{ reps.paginator.count }} result(s) {% for object in reps.object_list %} {{ object.Position }} {{ object.First_Name }} {{ object.Last_Name }} http://django.newsok.com/government/ reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more {% endfor %} {% if reps.has_previous %} Previous {% else %} Previous {% endif %} {% if reps.has_next %} Next {% else %} Next {% endif %} That href is the cause of the problem, how do I pass a page to the url without resetting the query? -- 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: How to define different user types?
Yeah, this is built in to django. You are on the right track with user.contrib.auth. If you are doing this all from the admin then it's as simple as creating a few groups, giving them the permisions you want and then assigning users to those groups. If you are doing it on a front facing site, then there are many template tags and view for checking permissions. I hate to just point you at the documentation but it's pretty thorough in this topic and without specific examples it would be difficult to work through any examples. http://docs.djangoproject.com/en/1.1/topics/auth/ On May 10, 6:18 am, signallock wrote: > Hi all, I'm a Python n00b but find Django very useful for me. However, > there is a problem in my recent project which needs several user > roles. For example, the 'user' role can browse some information and > submit some register forms, the 'admin' role can view and verify these > forms and/or modify them, the 'manager' role can add or delete 'admin' > users. All users need to login in order to specify their roles. I've > read some documentations about django.contrib.auth and django- > authorization all day but still confused... Is there any way to > implement this? Or, can django.contrib.auth do this? I really want to > use decorations in views.py to authenticate different types of users > or verify different permissions of users if it is possible. > I'm sorry to post this low-level thread but I've really read the > documentation first. Maybe there aren't many examples, or maybe I feel > a little bit hard to understand English :-[ > Thank you! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > 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.
Re: Paginating search results
The POST thing was the result of late night meltdowns and desperation. I tend to just try stupid things when i'm working through an issue like this, just seeing what the application is capable of doing. I've switched it all back to GET. I found the answer around 1 this morning. You are exactly right, I needed to capture the query string and place it in the "next" and "previous" page links. Here's how I went about doing that, just in case someone else runs into this issue: query_string = request.GET.copy() and then in the dict: 'query_string': query_string.urlencode() On May 11, 4:46 am, Nuno Maltez wrote: > You need to pass the current search paramters in your query string > (?party=D&q=&page= ) when you create the links to all the > pages, and you need to be able to retrieve them from request.GET in > order to recreate the object list (reps) when rendering a specific > page (any particular reason why are you using POST in the search > form?). > > hth, > Nuno > > > > On Tue, May 11, 2010 at 1:58 AM, Nick wrote: > > I'm trying to paginate results from a search with multiple options. > > The only problem is, once I hit the next button it clears the query > > and I'm left paginating all the objects in the DB. > > > Here is my view: > > > def filter_search(request): > > if request.POST: > > reps = Rep.objects.all() > > else: > > reps = [] > > query = request.POST > > if 'q' in request.POST: > > q = request.POST.get('q', '') > > qset = ( > > Q(Last_Name__icontains=q) | Q(First_Name__icontains=1) > > ) > > reps = reps.filter(qset) > > else: > > q = [] > > if len(q): > > qlist = q > > else: > > qlist = [] > > if 'party' in request.POST: > > party = request.POST.getlist('party') > > reps = reps.filter(Party__in=party) > > else: > > party = [] > > if len(party): > > plist = party > > else: > > plist = [] > > paginator = Paginator(reps, 15) > > results = paginator.count > > try: > > page = int(request.POST.get('page', '1')) > > except: > > page = 1 > > try: > > repList = paginator.page(page) > > except (EmptyPage, InvalidPage): > > repList = paginator.page(paginator.num_pages) > > finalq = request.POST > > return render_to_response("Government/search.html", { > > 'reps': repList, > > 'query': query, > > 'plist': plist, > > 'qlist': qlist, > > 'results': results, > > 'finalq': finalq > > }) > > > Here is my tpl: > > > > > > > Democrat > > Republican > > > > > > > {% if query %} > > Your search for {% if qlist %} {{ qlist}} {% endif %} > > {% if plist %} {% for p in plist %} {% if forloop.first %} Party > > ({{ p }}) {% else %} & Party ({{p}}) {% endif %} > > {% endfor %}{% endif %} returned {{ reps.paginator.count }} > span> result(s) > > > > {% for object in reps.object_list %} > > {{ object.Position }} {{ object.First_Name }} > > {{ object.Last_Name }} http://django.newsok.com/government/ > > reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more > > {% endfor %} > > > > > > > {% if reps.has_previous %} > > > href="&page={{ reps.previous_page_number }}">Previous > > {% else %} > > Previous > > {% endif %} > > > {% if reps.has_next %} > > Next > a> > > {% else %} > > Next > > {% endif %} > > > > > That href is the cause of the problem, how do I pass a page to the url > > without resetting the query? > > > -- > > 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 > 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.
Re: Paginating search results
It's all firing well, thanks for the heads up and the help. On May 11, 9:26 am, Nuno Maltez wrote: > Great, Just make sure you don't end up with multiple "page" arguments > on your query string when navigating through the results (click next; > click next again...). > > Nuno > > > > On Tue, May 11, 2010 at 2:41 PM, Nick wrote: > > The POST thing was the result of late night meltdowns and desperation. > > I tend to just try stupid things when i'm working through an issue > > like this, just seeing what the application is capable of doing. I've > > switched it all back to GET. > > > I found the answer around 1 this morning. You are exactly right, I > > needed to capture the query string and place it in the "next" and > > "previous" page links. Here's how I went about doing that, just in > > case someone else runs into this issue: > > > query_string = request.GET.copy() > > > and then in the dict: > > > 'query_string': query_string.urlencode() > > > On May 11, 4:46 am, Nuno Maltez wrote: > >> You need to pass the current search paramters in your query string > >> (?party=D&q=&page= ) when you create the links to all the > >> pages, and you need to be able to retrieve them from request.GET in > >> order to recreate the object list (reps) when rendering a specific > >> page (any particular reason why are you using POST in the search > >> form?). > > >> hth, > >> Nuno > > >> On Tue, May 11, 2010 at 1:58 AM, Nick wrote: > >> > I'm trying to paginate results from a search with multiple options. > >> > The only problem is, once I hit the next button it clears the query > >> > and I'm left paginating all the objects in the DB. > > >> > Here is my view: > > >> > def filter_search(request): > >> > if request.POST: > >> > reps = Rep.objects.all() > >> > else: > >> > reps = [] > >> > query = request.POST > >> > if 'q' in request.POST: > >> > q = request.POST.get('q', '') > >> > qset = ( > >> > Q(Last_Name__icontains=q) | Q(First_Name__icontains=1) > >> > ) > >> > reps = reps.filter(qset) > >> > else: > >> > q = [] > >> > if len(q): > >> > qlist = q > >> > else: > >> > qlist = [] > >> > if 'party' in request.POST: > >> > party = request.POST.getlist('party') > >> > reps = reps.filter(Party__in=party) > >> > else: > >> > party = [] > >> > if len(party): > >> > plist = party > >> > else: > >> > plist = [] > >> > paginator = Paginator(reps, 15) > >> > results = paginator.count > >> > try: > >> > page = int(request.POST.get('page', '1')) > >> > except: > >> > page = 1 > >> > try: > >> > repList = paginator.page(page) > >> > except (EmptyPage, InvalidPage): > >> > repList = paginator.page(paginator.num_pages) > >> > finalq = request.POST > >> > return render_to_response("Government/search.html", { > >> > 'reps': repList, > >> > 'query': query, > >> > 'plist': plist, > >> > 'qlist': qlist, > >> > 'results': results, > >> > 'finalq': finalq > >> > }) > > >> > Here is my tpl: > > >> > > >> > > >> > Democrat > >> > Republican > >> > > >> > > > >> > {% if query %} > >> > Your search for {% if qlist %} {{ qlist}} {% endif %} > >> > {% if plist %} {% for p in plist %} {% if forloop.first %} Party > >> > ({{ p }}) {% else %} & Party ({{p}}) {% endif %} > >> > {% endfor %}{% endif %} returned {{ reps.paginator.count }} >> > span> result(s) > >> > > >> > {% for object in reps.object_list %} > >> > {{ object.Position }} {{ object.First_Name }} > >> > {{ object.Last_Name }} http://django.newsok.co
Taking on a NoneType error
I am using a custom template tag called calculate age to produce an age in numbers based on a filter for a template tag. Here is the tag: def age(bday, d=None): if d is None: d = datetime.datetime.now() return (d.year - bday.year) - int((d.month, d.day) < (bday.month, bday.day)) register.filter('age', age) here is how it is used in a template: {{ entry.DOB|age }} # that produces an age Here is the problem, not all of the entries in my DB have a date of birth (henceforth known as DOB). This raises and error. I have tried to get around this many different ways. Here are few: {% ifequal entry.DOB None %} N/A {% else %} {{ entry.DOB|age }} {% endif %} {% ifequal entry.DOB "None" %} N/A {% else %} {{ entry.DOB|age }} {% endif %} {% if entry.DOB == None #I have custom operators set up and this logic works in the shell but not in the template %} N/A {% else %} {{ entry.DOB|age }} {% endif %} {% if entry.DOB == 'None' %} N/A {% else %} {{ entry.DOB|age }} {% endif %} I've even tried it in my view: def detail(request, last_name, first_name): r = get_object_or_404(Rep, Last_Name=last_name, First_Name=first_name) if r.DOB == None: r.DOB = NULLage return render_to_response('Government/repsSingle.html', {'entry': r, 'NULLage': NULLage}) The in the template: {% if NULLage %} This is a good grief sort of error and is making my brain blood boil. -- 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: Taking on a NoneType error
Well, I am embarrassed to admin that this issue was 100% user error. I recently set up a dev and production server and copied everything from the old production server to the two new servers. I was testing the search results page on dev, that's the page that generates the links to the pages that I'm having issue with (they appear in a pop up, BTW). While the search results page was on dev the actual page that was having the age issue was on production. So as I edited the templates for the age pages on dev it was not updating production so that's why i couldn't get the simple "if" statements to work. I had full absolute URLS to the age pages, they've been changed to relative URLS to prevent this from happening. There is, however, a bright side to my ignorance. The suggestions to update the template tag filter were right on. I use this filter a lot so it makes more since to have a built in fail safe rather than checking in the templates each time. Thanks a bunch, Dummy On May 12, 12:46 pm, Karen Tracey wrote: > On Wed, May 12, 2010 at 1:06 PM, Nick wrote: > > I am using a custom template tag called calculate age to produce an > > age in numbers based on a filter for a template tag. > > > Here is the tag: > > > def age(bday, d=None): > > if d is None: > > d = datetime.datetime.now() > > return (d.year - bday.year) - int((d.month, d.day) < (bday.month, > > bday.day)) > > > register.filter('age', age) > > > here is how it is used in a template: > > > {{ entry.DOB|age }} # that produces an age > > > Here is the problem, not all of the entries in my DB have a date of > > birth (henceforth known as DOB). > > > This raises and error. > > [snip remainder] > > Why not just handle it in the age filter itself: > > def age(bday, d=None): > if not bday: > return 'N/A' > if d is None: > d = datetime.datetime.now() > ... remainder of filter ... > > ? > > 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 > 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.
Re: Pluggable Q&A app?
I actually just got done writing a QandA app. It's very basic. I don't have it open yet but I would turn over the source to you if you wanted. Here are the features: Question Answer Answerer Answerer's credentials site specific QandA (using django.contrib sites) tagging (using django-tagging) creation date update date It outputs a json api based on several filters site (required) general search (optional) id, id list (optional) pub_date (optional) tags (optional) On May 14, 9:20 am, "bax...@gretschpages.com" wrote: > Can anyone give me any suggestions for a relatively simple, pluggable > Q&A app? I'm looking for something sorta Stack-Overflow-ish, but I'm > OK with handling voting, authentication, search, etc. separately. > > What I've found so far (OSQA, Askbot, soclone) are far from pluggable. > I don't want a whole other site, just an app. > > 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 > 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.
send_mail not firing
I am having an issue with an authentication app I am writing. The app saves the form appropriately but doesn't send the confirmation email. I am using the same email_host settings as with other application that send email messages but with no results. Here is the process. First a form processes the information: from django.contrib.auth.forms import UserCreationForm from django import forms from django.contrib.auth.models import User from activate import send_activation class RegisterForm(UserCreationForm): email = forms.EmailField(label="E-Email") class Meta: model = User fields = ("username", "email") def clean_email(self): email = self.cleaned_data["email"] try: User.objects.get(email=email) except User.DoesNotExist: return email raise forms.ValidationError("A user with that email address already exists.") def save(self): user = super(RegisterForm, self).save(commit=False) send_activation(user) user.is_active = False user.save() the activate.py file: from django.core.mail import send_mail from hashlib import md5 from django.template import loader, Context from Obits.settings import BASE_URL as base_url def send_activation(user): code = md5(user.username).hexdigest() url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, code) template = loader.get_template('obits/eactivate.html') context = ({ 'username': user.username, 'url': url, }) send_mail('Activate account at super site', 'this is a test', 'myem...@mydomain.com, [user.email], fail_silently=False) The form saves to the DB, it hits all of the conditions but fails to send an email. I can't get any error messages so I'm really at a loss. -- 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 not firing
I get the same result. I dropped into the shell and ran this >>> user = User(username="test", email="t...@test.com") >>>send_activation(user) 1 I don't really know what that 1 means, though. On May 18, 5:08 pm, "ge...@aquarianhouse.com" wrote: > what happens if you set fail_silently to True? > > On May 19, 12:05 am, Nick wrote: > > > > > I am having an issue with an authentication app I am writing. The app > > saves the form appropriately but doesn't send the confirmation email. > > I am using the same email_host settings as with other application that > > send email messages but with no results. Here is the process. > > > First a form processes the information: > > > from django.contrib.auth.forms import UserCreationForm > > from django import forms > > from django.contrib.auth.models import User > > from activate import send_activation > > > class RegisterForm(UserCreationForm): > > email = forms.EmailField(label="E-Email") > > > class Meta: > > model = User > > fields = ("username", "email") > > > def clean_email(self): > > email = self.cleaned_data["email"] > > > try: > > User.objects.get(email=email) > > except User.DoesNotExist: > > return email > > > raise forms.ValidationError("A user with that email address > > already exists.") > > > def save(self): > > user = super(RegisterForm, self).save(commit=False) > > send_activation(user) > > user.is_active = False > > user.save() > > > the activate.py file: > > > from django.core.mail import send_mail > > from hashlib import md5 > > from django.template import loader, Context > > from Obits.settings import BASE_URL as base_url > > > def send_activation(user): > > code = md5(user.username).hexdigest() > > url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, > > code) > > template = loader.get_template('obits/eactivate.html') > > context = ({ > > 'username': user.username, > > 'url': url, > > }) > > send_mail('Activate account at super site', 'this is a test', > > 'myem...@mydomain.com, [user.email], fail_silently=False) > > > The form saves to the DB, it hits all of the conditions but fails to > > send an email. I can't get any error messages so I'm really at a loss. > > > -- > > 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 > 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.
Re: send_mail not firing
I get the same results. I dropped into the shell and tried it out >>> user = User(username="nick", email="t...@test.com") >>> send_activation(user) 1 I think the 1 means that it passed but I don't get any emails sent On May 18, 5:08 pm, "ge...@aquarianhouse.com" wrote: > what happens if you set fail_silently to True? > > On May 19, 12:05 am, Nick wrote: > > > > > I am having an issue with an authentication app I am writing. The app > > saves the form appropriately but doesn't send the confirmation email. > > I am using the same email_host settings as with other application that > > send email messages but with no results. Here is the process. > > > First a form processes the information: > > > from django.contrib.auth.forms import UserCreationForm > > from django import forms > > from django.contrib.auth.models import User > > from activate import send_activation > > > class RegisterForm(UserCreationForm): > > email = forms.EmailField(label="E-Email") > > > class Meta: > > model = User > > fields = ("username", "email") > > > def clean_email(self): > > email = self.cleaned_data["email"] > > > try: > > User.objects.get(email=email) > > except User.DoesNotExist: > > return email > > > raise forms.ValidationError("A user with that email address > > already exists.") > > > def save(self): > > user = super(RegisterForm, self).save(commit=False) > > send_activation(user) > > user.is_active = False > > user.save() > > > the activate.py file: > > > from django.core.mail import send_mail > > from hashlib import md5 > > from django.template import loader, Context > > from Obits.settings import BASE_URL as base_url > > > def send_activation(user): > > code = md5(user.username).hexdigest() > > url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, > > code) > > template = loader.get_template('obits/eactivate.html') > > context = ({ > > 'username': user.username, > > 'url': url, > > }) > > send_mail('Activate account at super site', 'this is a test', > > 'myem...@mydomain.com, [user.email], fail_silently=False) > > > The form saves to the DB, it hits all of the conditions but fails to > > send an email. I can't get any error messages so I'm really at a loss. > > > -- > > 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 > 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.
Re: send_mail not firing
OK, it's all fixed. I updated the template rendering to actually use Context, if you look at activate.py I just put "context = ({". That's not helping anything out. I also added a default_host_email to the settings file. I don't know if that was the problem, but I'm leaving it in. On May 18, 5:19 pm, Nick wrote: > I get the same results. > > I dropped into the shell and tried it out > > >>> user = User(username="nick", email="t...@test.com") > >>> send_activation(user) > > 1 > > I think the 1 means that it passed but I don't get any emails sent > > On May 18, 5:08 pm, "ge...@aquarianhouse.com" > > > > wrote: > > what happens if you set fail_silently to True? > > > On May 19, 12:05 am, Nick wrote: > > > > I am having an issue with an authentication app I am writing. The app > > > saves the form appropriately but doesn't send the confirmation email. > > > I am using the same email_host settings as with other application that > > > send email messages but with no results. Here is the process. > > > > First a form processes the information: > > > > from django.contrib.auth.forms import UserCreationForm > > > from django import forms > > > from django.contrib.auth.models import User > > > from activate import send_activation > > > > class RegisterForm(UserCreationForm): > > > email = forms.EmailField(label="E-Email") > > > > class Meta: > > > model = User > > > fields = ("username", "email") > > > > def clean_email(self): > > > email = self.cleaned_data["email"] > > > > try: > > > User.objects.get(email=email) > > > except User.DoesNotExist: > > > return email > > > > raise forms.ValidationError("A user with that email address > > > already exists.") > > > > def save(self): > > > user = super(RegisterForm, self).save(commit=False) > > > send_activation(user) > > > user.is_active = False > > > user.save() > > > > the activate.py file: > > > > from django.core.mail import send_mail > > > from hashlib import md5 > > > from django.template import loader, Context > > > from Obits.settings import BASE_URL as base_url > > > > def send_activation(user): > > > code = md5(user.username).hexdigest() > > > url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, > > > code) > > > template = loader.get_template('obits/eactivate.html') > > > context = ({ > > > 'username': user.username, > > > 'url': url, > > > }) > > > send_mail('Activate account at super site', 'this is a test', > > > 'myem...@mydomain.com, [user.email], fail_silently=False) > > > > The form saves to the DB, it hits all of the conditions but fails to > > > send an email. I can't get any error messages so I'm really at a loss. > > > > -- > > > 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 > > 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 > 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.
Re: send_mail not firing
Actually, I've fixed the problem with send_activation. If i go via the form it still doesn't trigger the email. On May 18, 5:19 pm, Nick wrote: > I get the same results. > > I dropped into the shell and tried it out > > >>> user = User(username="nick", email="t...@test.com") > >>> send_activation(user) > > 1 > > I think the 1 means that it passed but I don't get any emails sent > > On May 18, 5:08 pm, "ge...@aquarianhouse.com" > > > > wrote: > > what happens if you set fail_silently to True? > > > On May 19, 12:05 am, Nick wrote: > > > > I am having an issue with an authentication app I am writing. The app > > > saves the form appropriately but doesn't send the confirmation email. > > > I am using the same email_host settings as with other application that > > > send email messages but with no results. Here is the process. > > > > First a form processes the information: > > > > from django.contrib.auth.forms import UserCreationForm > > > from django import forms > > > from django.contrib.auth.models import User > > > from activate import send_activation > > > > class RegisterForm(UserCreationForm): > > > email = forms.EmailField(label="E-Email") > > > > class Meta: > > > model = User > > > fields = ("username", "email") > > > > def clean_email(self): > > > email = self.cleaned_data["email"] > > > > try: > > > User.objects.get(email=email) > > > except User.DoesNotExist: > > > return email > > > > raise forms.ValidationError("A user with that email address > > > already exists.") > > > > def save(self): > > > user = super(RegisterForm, self).save(commit=False) > > > send_activation(user) > > > user.is_active = False > > > user.save() > > > > the activate.py file: > > > > from django.core.mail import send_mail > > > from hashlib import md5 > > > from django.template import loader, Context > > > from Obits.settings import BASE_URL as base_url > > > > def send_activation(user): > > > code = md5(user.username).hexdigest() > > > url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, > > > code) > > > template = loader.get_template('obits/eactivate.html') > > > context = ({ > > > 'username': user.username, > > > 'url': url, > > > }) > > > send_mail('Activate account at super site', 'this is a test', > > > 'myem...@mydomain.com, [user.email], fail_silently=False) > > > > The form saves to the DB, it hits all of the conditions but fails to > > > send an email. I can't get any error messages so I'm really at a loss. > > > > -- > > > 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 > > 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 > 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.
Re: send_mail not firing
It looks like the problem isn't with send_mail, its the save override on the form, the is_active = False isn't setting that option in the DB either, so it is skipping over the save options. Here they are again: forms.py: class RegisterForm(UserCreationForm): email = forms.EmailField(label="E-Email") class Meta: model = User fields = ("username", "email") def clean_email(self): email = self.cleaned_data["email"] try: User.objects.get(email=email) except User.DoesNotExist: return email raise forms.ValidationError("A user with that email address already exists.") def save(self): user = super(RegisterForm, self).save(commit=False) send_activation(user) user.is_active = False user.save() and the view: def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): new_user = form.save() return HttpResponseRedirect("/obits/") else: form = RegisterForm() return render_to_response("obits/register.html", {'form': form }) So, the username and all of that are saving by the user.is_active and send_mail are getting skipped On May 19, 4:37 am, Nuno Maltez wrote: > Anything it the mail server's logs? Any trace of your app trying tosendthe > message? Any errors? > > Nuno > > > > On Tue, May 18, 2010 at 11:42 PM, Nick wrote: > > Actually, I've fixed the problem with send_activation. If i go via the > > form it still doesn't trigger the email. > > > On May 18, 5:19 pm, Nick wrote: > >> I get the same results. > > >> I dropped into the shell and tried it out > > >> >>> user = User(username="nick", email="t...@test.com") > >> >>> send_activation(user) > > >> 1 > > >> I think the 1 means that it passed but I don't get any emails sent > > >> On May 18, 5:08 pm, "ge...@aquarianhouse.com" > > >> wrote: > >> > what happens if you set fail_silently to True? > > >> > On May 19, 12:05 am, Nick wrote: > > >> > > I am having an issue with an authentication app I am writing. The app > >> > > saves the form appropriately but doesn'tsendthe confirmation email. > >> > > I am using the same email_host settings as with other application that > >> > >sendemail messages but with no results. Here is the process. > > >> > > First a form processes the information: > > >> > > from django.contrib.auth.forms import UserCreationForm > >> > > from django import forms > >> > > from django.contrib.auth.models import User > >> > > from activate import send_activation > > >> > > class RegisterForm(UserCreationForm): > >> > > email = forms.EmailField(label="E-Email") > > >> > > class Meta: > >> > > model = User > >> > > fields = ("username", "email") > > >> > > def clean_email(self): > >> > > email = self.cleaned_data["email"] > > >> > > try: > >> > > User.objects.get(email=email) > >> > > except User.DoesNotExist: > >> > > return email > > >> > > raise forms.ValidationError("A user with that email address > >> > > already exists.") > > >> > > def save(self): > >> > > user = super(RegisterForm, self).save(commit=False) > >> > > send_activation(user) > >> > > user.is_active = False > >> > > user.save() > > >> > > the activate.py file: > > >> > > from django.core.mail import send_mail > >> > > from hashlib import md5 > >> > > from django.template import loader, Context > >> > > from Obits.settings import BASE_URL as base_url > > >> > > def send_activation(user): > >> > > code = md5(user.username).hexdigest() > >> > > url = "%sactivate/?user=%s&code=%s" % (base_url, user.username, > >> > > code) > >> > > template = loader.get_template('obits/eactivate.html') > >> > > context = ({ > >> > > 'username': user.username,
Re: send_mail not firing
Welp, indentation error: def save(self): needed to unindent so it was called when the form was process, instead it was waiting for an error to trigger it, which it wouldn't do because the error halts the form from processing. There goes 13 hours of my life I'm never getting back. On May 19, 10:07 am, Nick wrote: > It looks like the problem isn't with send_mail, its the save override > on the form, the is_active = False isn't setting that option in the DB > either, so it is skipping over the save options. Here they are again: > > forms.py: > class RegisterForm(UserCreationForm): > email = forms.EmailField(label="E-Email") > > class Meta: > model = User > fields = ("username", "email") > > def clean_email(self): > email = self.cleaned_data["email"] > > try: > User.objects.get(email=email) > except User.DoesNotExist: > return email > > raise forms.ValidationError("A user with that email address > already exists.") > > def save(self): > user = super(RegisterForm, self).save(commit=False) > send_activation(user) > user.is_active = False > user.save() > > and the view: > > def register(request): > if request.method == 'POST': > form = RegisterForm(request.POST) > if form.is_valid(): > new_user = form.save() > > return HttpResponseRedirect("/obits/") > else: > form = RegisterForm() > > return render_to_response("obits/register.html", {'form': form }) > > So, the username and all of that are saving by the user.is_active and > send_mail are getting skipped > > On May 19, 4:37 am, Nuno Maltez wrote: > > > > > Anything it the mail server's logs? Any trace of your app trying tosendthe > > message? Any errors? > > > Nuno > > > On Tue, May 18, 2010 at 11:42 PM, Nick wrote: > > > Actually, I've fixed the problem with send_activation. If i go via the > > > form it still doesn't trigger the email. > > > > On May 18, 5:19 pm, Nick wrote: > > >> I get the same results. > > > >> I dropped into the shell and tried it out > > > >> >>> user = User(username="nick", email="t...@test.com") > > >> >>> send_activation(user) > > > >> 1 > > > >> I think the 1 means that it passed but I don't get any emails sent > > > >> On May 18, 5:08 pm, "ge...@aquarianhouse.com" > > > >> wrote: > > >> > what happens if you set fail_silently to True? > > > >> > On May 19, 12:05 am, Nick wrote: > > > >> > > I am having an issue with an authentication app I am writing. The app > > >> > > saves the form appropriately but doesn'tsendthe confirmation email. > > >> > > I am using the same email_host settings as with other application > > >> > > that > > >> > >sendemail messages but with no results. Here is the process. > > > >> > > First a form processes the information: > > > >> > > from django.contrib.auth.forms import UserCreationForm > > >> > > from django import forms > > >> > > from django.contrib.auth.models import User > > >> > > from activate import send_activation > > > >> > > class RegisterForm(UserCreationForm): > > >> > > email = forms.EmailField(label="E-Email") > > > >> > > class Meta: > > >> > > model = User > > >> > > fields = ("username", "email") > > > >> > > def clean_email(self): > > >> > > email = self.cleaned_data["email"] > > > >> > > try: > > >> > > User.objects.get(email=email) > > >> > > except User.DoesNotExist: > > >> > > return email > > > >> > > raise forms.ValidationError("A user with that email address > > >> > > already exists.") > > > >> > > def save(self): > > >> > > user = super(RegisterForm, self).save(commit=False) > > >> > > send_activation(user) > > >> > > user.is_active = False > > >>
If is first time logging in
I'm trying to figure out a way to see if it is a users first time logging in after registering on the site. If it is then I will pass them through some formsets, otherwise I let them go to their profile page. I tried using date_joined == last_login but that doesn't work, as the last login date changes the second you log in. Anyone ever done anything like this? 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: If is first time logging in
I have an expanded user form right now. Here is the sign up process. user registers using username, email, password It sends and activation link to that email. User clicks on the link and they are activated User logs in Here is where I would like the extended profile to pop up the first time. When they pass through the login screen to their home page (each user has a home page with a selection of different actions). I can kind of see where you are going with what you have, I'm adding a field to check to make sure the forms are finished? I'm not too worried about users not filling out the profile, this is a site built for submitted obituaries and the users will be funeral homes so filling out the form is a necessary part of their job. I just want to know how to make it really obvious to them the first time they login. On May 19, 4:36 pm, Dejan Noveski wrote: > Best will be if you make Useraccount model that will inherit from User, add > field formsets_passed = BooleanField(initial = False) > > The reason why i think this is better idea is, user might leave the page > before finishing the aditional forms. That way, next time it will be second > login and you will be able to show them again. > > > > > > On Wed, May 19, 2010 at 11:05 PM, Nick wrote: > > I'm trying to figure out a way to see if it is a users first time > > logging in after registering on the site. If it is then I will pass > > them through some formsets, otherwise I let them go to their profile > > page. > > > I tried using date_joined == last_login but that doesn't work, as the > > last login date changes the second you log in. > > > Anyone ever done anything like this? > > > 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 > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. > > -- > -- > Dejan Noveski > Web Developer > dr.m...@gmail.com > Twitter:http://twitter.com/dekomote| > LinkedIn:http://mk.linkedin.com/in/dejannoveski > > -- > 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.
Re: If is first time logging in
I am, but I'm not opposed to custmizing one. This part of the project will undoubtedly get bundled as a reusable registratioon and login app for other projects so it doing what I'd like it to do is more important than convenience. On May 19, 5:23 pm, Dejan Noveski wrote: > Do you use the generic login view? > > > > > > On Thu, May 20, 2010 at 12:16 AM, Nick wrote: > > I have an expanded user form right now. Here is the sign up process. > > > user registers using username, email, password > > > It sends and activation link to that email. > > > User clicks on the link and they are activated > > > User logs in > > > Here is where I would like the extended profile to pop up the first > > time. When they pass through the login screen to their home page (each > > user has a home page with a selection of different actions). > > > I can kind of see where you are going with what you have, I'm adding a > > field to check to make sure the forms are finished? > > > I'm not too worried about users not filling out the profile, this is a > > site built for submitted obituaries and the users will be funeral > > homes so filling out the form is a necessary part of their job. I just > > want to know how to make it really obvious to them the first time they > > login. > > > On May 19, 4:36 pm, Dejan Noveski wrote: > > > Best will be if you make Useraccount model that will inherit from User, > > add > > > field formsets_passed = BooleanField(initial = False) > > > > The reason why i think this is better idea is, user might leave the page > > > before finishing the aditional forms. That way, next time it will be > > second > > > login and you will be able to show them again. > > > > On Wed, May 19, 2010 at 11:05 PM, Nick wrote: > > > > I'm trying to figure out a way to see if it is a users first time > > > > logging in after registering on the site. If it is then I will pass > > > > them through some formsets, otherwise I let them go to their profile > > > > page. > > > > > I tried using date_joined == last_login but that doesn't work, as the > > > > last login date changes the second you log in. > > > > > Anyone ever done anything like this? > > > > > 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 > > > groups.com> > > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. > > > > -- > > > -- > > > Dejan Noveski > > > Web Developer > > > dr.m...@gmail.com > > > Twitter:http://twitter.com/dekomote|LinkedIn: > >http://mk.linkedin.com/in/dejannoveski > > > > -- > > > 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 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 > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. > > -- > -- > Dejan Noveski > Web Developer > dr.m...@gmail.com > Twitter:http://twitter.com/dekomote| > LinkedIn:http://mk.linkedin.com/in/dejannoveski > > -- > 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.
XML database updates
I am working on a project that requires me to grab an XML feed and use it to update entries in a DB that will also be updated by some people doing data entry. I have the workflow for the data entry side all set up but I'm having a hard time finding a resource that can help me write some functions to grab the XML, pull out some information and update the DB with those elements. I have been playing with ElementTree and BeautifulSoup but there is just something I'm not getting. If you know of a good resource or a really quick example that can get me acquainted with the different services I'll be needing to utilize I would be most appreciative. -- 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: XML database updates
That's exactly what I'm looking to do, but as I have never done it before I am having trouble gaining the base of knowledge needed to accomplish the task. Your series of questions actually helps in that it offers a quick map of the process for doing what it is I'd like to do. Here is my first thought for how to do this: feed = urllib.urlopen('http://example.xml/data.xml') tree = ElementTree.parse(feed) for obj in serializers.deserialize(feed, data): obj.save() On Jun 4, 11:14 am, Venkatraman S wrote: > On Fri, Jun 4, 2010 at 9:40 PM, Nick wrote: > > I have been playing with > > ElementTree and BeautifulSoup but there is just something I'm not > > getting. > > What is the problem that you are facing? if your XML is well defined, then > parse it, extract the data, convert that into objects and good to go ? > Right? > Or am i missing something? > > -V-http://twitter.com/venkasub -- 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.
Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?
Hi, I'm currently running Django on CentOS using the supplied Python 2.4. I now need to use Python 2.6. I have installed Python 2.6 from the EPEL repositories, which sits alongside 2.4 (which is required for CentOS things such as "yum"). Django (and other Python modules) are all located in Python 2.4's site- packages folder. When I upgrade to 2.6, is it just a case of copying these over into 2.6's site-packages folder, or do I need to install the modules afresh? 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.
styling with django templates
I am looking for a way to identify the first item returned in a loop and display it differently than the others: basically it would go like: {% for item in items %} {% if is_first_item %} This is what will show {% else %} this is what will show {% endfor %} Am I overlooking something in the docs? -- 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: styling with django templates
Boy, that just flew right past me. Ridiculous. Thanks everyone. On Jun 8, 1:06 pm, Dejan Noveski wrote: > http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for > > scroll a bit down to see the forloop object and its properties. > > > > On Tue, Jun 8, 2010 at 8:05 PM, Dejan Noveski wrote: > > change {% if is_first_item %} with {% if forloop.first %} and you are set. > > > On Tue, Jun 8, 2010 at 7:59 PM, Nick wrote: > > >> I am looking for a way to identify the first item returned in a loop > >> and display it differently than the others: > > >> basically it would go like: > > >> {% for item in items %} > >> {% if is_first_item %} > >> This is what will show > >> {% else %} > >> this is what will show > >> {% endfor %} > > >> Am I overlooking something in the docs? > > >> -- > >> 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. > > > -- > > -- > > Dejan Noveski > > Web Developer > > dr.m...@gmail.com > > Twitter:http://twitter.com/dekomote| LinkedIn: > >http://mk.linkedin.com/in/dejannoveski > > -- > -- > Dejan Noveski > Web Developer > dr.m...@gmail.com > Twitter:http://twitter.com/dekomote| > LinkedIn:http://mk.linkedin.com/in/dejannoveski -- 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.
assigning data based on a comparison between two tables
I have two models. One is a list of candidates that have filed to run for office. The second is a list of people who currently hold office. I'd like to compare the two tables and whenever a match is found between the two (an entry in the candidate table shares the same last_name and first_name with an office holder from the holds office table) I'd like to check off a box in the Candidate table called 'incumbent'. how would I begin to do this. They both have columns called last_name and first_name that I can use to compare but I don't know the syntax. -- 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: assigning data based on a comparison between two tables
Thanks Dan, I'll give it a shot On Jun 8, 6:00 pm, Dan Harris wrote: > Perhaps not the greatest way of doing things, but simple to code/read: > > class Candidate(models.Model): > first_name = models.CharField(max_length=30) > last_name = models.CharField(max_length=30) > incumbent = models.BooleanField() > > class HoldsOffice(models.Model): > first_name = models.CharField(max_length=30) > last_name = models.CharField(max_length=30) > > for officer in HoldsOffice.objects.all(): > candidates = > Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name) > > if len(candidates)>0: > raise Exception("More than 1 match found") > candidates[0].incumbent = True > candidates[0].save() > > Something like that might work for you assuming that the models and > stuff are similar. Also, this code is just off the top of my head, so > who knows if it will actually work :) > > Cheers, > > Dan Harris > dih0...@gmail.com > > On Jun 8, 6:30 pm, Nick wrote: > > > I have two models. One is a list of candidates that have filed to run > > for office. The second is a list of people who currently hold > > office. > > > I'd like to compare the two tables and whenever a match is found > > between the two (an entry in the candidate table shares the same > > last_name and first_name with an office holder from the holds office > > table) I'd like to check off a box in the Candidate table called > > 'incumbent'. > > > how would I begin to do this. They both have columns called last_name > > and first_name that I can use to compare but I don't know the syntax. -- 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.
ordering integers with regroup
Has anyone come across an ordering issue with the regroup tag whereby if the field that is being ordered is an integer you get the following problem: say you have the grouped field "District" and the following groupings District 1 District 2 District 3 District 10 District 14 District 20 District 29 District 30 Their ordering will come out: District 1 District 10 District 14 District 2 District 20 District 29 District 3 District 30 I can see why this is happening, but how do I tell the regroup tag to sort as though 1 were 01, etc. Adding a 0 to the front isn't really an option as their are thousands of records that reach from 1 - 250 Thanks 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: ordering integers with regroup
You are right, I wasn't even thinking about it like that. This is bad news as the information is coming across as "District 45" from another source and so I don't have just a district number to go off of. State government data is always terrible to work with. On Jun 9, 10:04 am, Scott Gould wrote: > If you're ordering on "District 1", "District 2", etc. then the number > is part of a string and will be sorted alphabetically. I image your > only recourse will be to use the numeric field directly, and deal with > prepending "District " to it in some other fashion. > > On Jun 9, 10:38 am, Nick wrote: > > > Has anyone come across an ordering issue with the regroup tag whereby > > if the field that is being ordered is an integer you get the following > > problem: > > > say you have the grouped field "District" and the following groupings > > > District 1 > > District 2 > > District 3 > > District 10 > > District 14 > > District 20 > > District 29 > > District 30 > > > Their ordering will come out: > > > District 1 > > District 10 > > District 14 > > District 2 > > District 20 > > District 29 > > District 3 > > District 30 > > > I can see why this is happening, but how do I tell the regroup tag to > > sort as though 1 were 01, etc. Adding a 0 to the front isn't really an > > option as their are thousands of records that reach from 1 - 250 > > > Thanks 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: assigning data based on a comparison between two tables
Just to let you know, this code worked out nicely. I made a few changes to the bottom save function: if len(candidates) > 1: raise Exception candidates.update(incumbent=True) On Jun 8, 6:11 pm, Nick wrote: > Thanks Dan, I'll give it a shot > > On Jun 8, 6:00 pm, Dan Harris wrote: > > > Perhaps not the greatest way of doing things, but simple to code/read: > > > class Candidate(models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > incumbent = models.BooleanField() > > > class HoldsOffice(models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > > for officer in HoldsOffice.objects.all(): > > candidates = > > Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name) > > > if len(candidates)>0: > > raise Exception("More than 1 match found") > > candidates[0].incumbent = True > > candidates[0].save() > > > Something like that might work for you assuming that the models and > > stuff are similar. Also, this code is just off the top of my head, so > > who knows if it will actually work :) > > > Cheers, > > > Dan Harris > > dih0...@gmail.com > > > On Jun 8, 6:30 pm, Nick wrote: > > > > I have two models. One is a list of candidates that have filed to run > > > for office. The second is a list of people who currently hold > > > office. > > > > I'd like to compare the two tables and whenever a match is found > > > between the two (an entry in the candidate table shares the same > > > last_name and first_name with an office holder from the holds office > > > table) I'd like to check off a box in the Candidate table called > > > 'incumbent'. > > > > how would I begin to do this. They both have columns called last_name > > > and first_name that I can use to compare but I don't know the syntax. -- 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: Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?
Many thanks for your helpful posts - in the end I just changed a bit of my code to work with 2.4, but this will come in handy for when I finally make the upgrade. 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.
How to implement this model
OK, here's the deal. I'm working up an obituary site. There are 3 models/tables and at one point I need to connect two in a way that is different than I have done up to this point. Here is the situation, any recommendations on how to accomplish this would be great: I have an obituary table. In that table there is a field that checks if a funeral service is on the premises (column name "on_premises" of the Funeral Home that is entering the information. If this BooleanField is checked then it returns the location information of the funeral home which is stored in a business_profile table. Not difficult, just check if the boolean returns a value and then populate the template That works out nicely except I have been given an extra criteria for this project. Some business have both a funeral home and a crematorium. Many of these situations require that we list the address of one or the other. Since the "on premises" is a BooleanField there is no way for someone to state what part of their business is responsible for the service. What I would like to do is make this option a drop down in the obituary form that basically gives the business the option of choosing which one of their locations is the one we want attached to this obit. Once this is chosen then I will pull the value into the templates. How do I relate these models? My first thought is to create two "business type" columns in the business profile table and then relate the "service_location" column to these columns in a drop down? Is that even possible? How do I retrieve the values from two different fields and then select from them in another model? -- 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: How to create the model in a different database from within the same database server.
Which version of django are you working with? On Jun 16, 2:28 pm, thusjanthan wrote: > Hi, > > when I mean database I mean the separate databases from within one > mysql database server. So ex: > > DB server: server.example.com > Databases that are contained in the one instance of mysql: > People > Books > > I have made the connection in the settings.py at the project level but > in the individual applications suppose People I would like to create > the models that write the tables in that database space and the > application Books to write its models in the Books database. This > should be possible to do but not sure why its not working. > > 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: How to implement this model
I am going to try to add better information for this issue, here we go: The model for the obituary looks like this: class obit_entry(models.Model): first_name = models.CharField('First Name', max_length=100, blank=False) middle_name = models.CharField('Middle Name', max_length=100, blank=False) last_name = models.CharField('Last Name', max_length=100, blank=False) nick_name = models.CharField('Nickname', max_length=100, blank=True) city = models.CharField('City', max_length=100, blank=False) state = USStateField(blank=False) occupation = models.CharField('Occupation', blank=True, max_length=100) date_of_birth = models.DateField(blank=False) date_of_death = models.DateField(blank=False) date_of_service = models.DateTimeField(blank=False) type_of_service = models.CharField('Type of service', max_length=100, choices=Service_Type, blank=False) on_premises = models.BooleanField(blank=True) service_location = models.CharField('Location of service', max_length=100, blank=True) service_address = models.CharField('Service Address', max_length=100, blank=True) service_city = models.CharField('City of service', max_length=100, blank=True) service_state = USStateField('State of service', blank=True) additional_info = models.TextField('Additional Information', blank=True) organ_donor = models.BooleanField(blank=True) natural_causes = models.CharField('Died of Natural causes', max_length=100, choices=Causes_Choices, blank=False) date_to_run = models.DateField('Date obit should run', blank=True, null=True) date_created = models.DateTimeField(auto_now_add=True) date_update = models.DateTimeField(auto_now=True) created_by = models.ForeignKey(FullProfile, related_name="createdBY", null=True, blank=True) the model for the business profile (FullProfile) looks like this: class FullProfile(User): bus_name = models.CharField('Full Business Name', help_text='excluding type (e.g. Funeral Home, Crematorium)', max_length=200, blank=True) bus_type = models.CharField('Business Type', help_text='(e.g. Funeral Home, Crematorium, etc.)', max_length=200, blank=True) address_street = models.CharField('Street Number', max_length=200, blank=True) address_city = models.CharField('City', max_length=200, blank=True) address_zip = models.CharField('Zip Code', max_length=10, blank=True) phone = PhoneNumberField('Phone Number', blank=True) contact = models.CharField('Contact Name', max_length=100, blank=True) bus_type_2 = models.CharField('Business Type 2', help_text='(e.g. Funeral Home, Crematorium, etc.)', max_length=200, blank=True) address_street_2 = models.CharField('Street Number', max_length=200, blank=True) address_city_2 = models.CharField('City', max_length=200, blank=True) address_zip_2 = models.CharField('Zip Code', max_length=10, blank=True) completed = models.BooleanField() objects = UserManager() There is an obituary form that is a model form of the obit model: I would like to change the on_premises field to lookup of the two business type fields in the FullProfile model so that the user can select which business type they want to attach to the individual obituary. So if a business has bus_type = Funeral Home and bus_type_2 = Crematorium, in the obituary form the user will have a drop down of either "Funeral Home" or "Crematorium" to choose from. On Jun 16, 2:39 pm, Nick wrote: > OK, here's the deal. I'm working up an obituary site. There are 3 > models/tables and at one point I need to connect two in a way that is > different than I have done up to this point. Here is the situation, > any recommendations on how to accomplish this would be great: > > I have an obituary table. In that table there is a field that checks > if a funeral service is on the premises (column name "on_premises" of > the Funeral Home that is entering the information. > > If this BooleanField is checked then it returns the location > information of the funeral home which is stored in a business_profile > table. Not difficult, just check if the boolean returns a value and > then populate the template > > That works out nicely except I have been given an extra criteria for > this project. Some business have both a funeral home and a > crematorium. Many of these situations require that we list the address > of one or the other. Since the "on premises" is a BooleanField there > is no way for someone to state what part of their business is > responsible for the service. > > What I would like to do is make thi
Re: How to implement this model
The question is how do I relate this to the business_types in the FulLProfile model? Since a business can have multiple "Premises" On Jun 16, 4:44 pm, Peter Bengtsson wrote: > Without caring or even attempting to understand your business I sounds > like you just need to stop using a BooleanField() and instead use a > ForeignKey(null=True) and then judge if it's "on_premise" by a method > rather than a field something like this: > > class MyModel(Model): > related_premise = ForeignKey(Premise, null=True) > def on_premise(self): > return self.related_premise is not None > def get_related_premise(self): > assert self.on_premise() > return self.related_premise > > On Jun 16, 3:39 pm, Nick wrote: > > > OK, here's the deal. I'm working up an obituary site. There are 3 > > models/tables and at one point I need to connect two in a way that is > > different than I have done up to this point. Here is the situation, > > any recommendations on how to accomplish this would be great: > > > I have an obituary table. In that table there is a field that checks > > if a funeral service is on the premises (column name "on_premises" of > > the Funeral Home that is entering the information. > > > If this BooleanField is checked then it returns the location > > information of the funeral home which is stored in a business_profile > > table. Not difficult, just check if the boolean returns a value and > > then populate the template > > > That works out nicely except I have been given an extra criteria for > > this project. Some business have both a funeral home and a > > crematorium. Many of these situations require that we list the address > > of one or the other. Since the "on premises" is a BooleanField there > > is no way for someone to state what part of their business is > > responsible for the service. > > > What I would like to do is make this option a drop down in the > > obituary form that basically gives the business the option of choosing > > which one of their locations is the one we want attached to this obit. > > Once this is chosen then I will pull the value into the templates. > > > How do I relate these models? My first thought is to create two > > "business type" columns in the business profile table and then relate > > the "service_location" column to these columns in a drop down? Is that > > even possible? > > > How do I retrieve the values from two different fields and then select > > from them in another model? -- 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.
OR operator in django view
How would I write this conditional statement in a view? if not candidate.office_type == "USREP" or "USSEN" or "DJ" or "ASSOCDJ": office = '%s' % (candidate.office_type_description) else: office = [] As is stands, it doesn't seem to be running through all of the OR operators -- 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: OR operator in django view
Brilliant, thanks On Jun 18, 4:08 pm, Dennis Kaarsemaker wrote: > On vr, 2010-06-18 at 14:04 -0700, Nick wrote: > > > How would I write this conditional statement in a view? > > > if not candidate.office_type == "USREP" or "USSEN" or "DJ" or > > "ASSOCDJ": > > office = '%s' % (candidate.office_type_description) > > else: > > office = [] > > > As is stands, it doesn't seem to be running through all of the OR > > operators > > if candidate.office_type not in ("USREP", "USSEN", "DJ"): > > > -- > Dennis K. > > They've gone to plaid! -- 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 ?
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
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.