csv export through command line
Hi All, I need to export .CSV(example.csv) file data into my data base table . How can I do this through command line. My application blog/ __init__.py models.py management/ __init__.py commands/ __init__.py csvexport.py views.py How can I pass file name as argument... csvexport.py -- from django.core.management.base import BaseCommand class Command(BaseCommand): def handle(self, *app_labels, **options): reader = csv.reader(csvfile, dialect='excel') try: for row in reader: column_first_name = row[4] column_last_name = row[5] column_middle_name = row[6] column_phone = row[8] column_email = row[9] column_age = row[0] column_address = row[12] column_city = row[13] column_state = row[14] column_zipcode = row[15] full_slug = column_first_name + ' ' + column_last_name try: Person.objects.get_or_create(first_name=column_first_name, last_name=column_last_name, middle_name=column_middle_name, slug=slugify(full_slug), phone=column_phone, email=column_email, age=column_age, address=column_address, city=column_city, state=column_state, zipcode=column_zipcode) success = True except Person.MultipleObjectsReturned: pass except IndexError: index_out_range = True Please advise. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django point field
Thanks a lot Nabil servais. its works for me too On Fri, Sep 25, 2009 at 2:06 PM, Nabil Servais wrote: > > Hello, > > I use json for output instead of cvs, and it works. Also I convert the > lattitude and longitude into float. > > enjoy > > def get_lat_long(location): > key = settings.GOOGLE_API_KEY > output = "json" > location = urllib.quote_plus(location) > request = > "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s > <http://maps.google.com/maps/geo?q=%s&output=%s&key=%s>" % (location, > output, key) > data = urllib.urlopen(request).read() > dlist = simplejson.loads(data) > if dlist['Status']['code'] == 200: > lat = float(dlist['Placemark'][0]['Point']['coordinates'][0]) > long = float(dlist['Placemark'][0]['Point']['coordinates'][1]) > return (lat, long) > else > return '' > > > > Le 25/09/2009 09:47, please smile a écrit : > > Hi all, > > I have a problem to convert latitude and longitude values into > > point field value. > > > > > > def get_lat_long(location): > > key = settings.GOOGLE_API_KEY > > output = "csv" > > location = urllib.quote_plus(location) > > request = > > "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s > > <http://maps.google.com/maps/geo?q=%s&output=%s&key=%s>" % (location, > > output, key) > > data = urllib.urlopen(request).read() > > dlist = data.split(',') > > if dlist[0] == '200': > > #return "%s, %s" % (dlist[2], dlist[3]) > > return (dlist[2], dlist[3]) > > else: > > return '' > > > > > > My models.py > > -- > > class Person(models.Model): > > address = models.CharField(_('address'), max_length=200, > > blank=True) > > city = models.CharField(_('city'), max_length=100, blank=True) > > state = USStateField(_('state'), blank=True) > > zipcode = models.CharField(_('zip code'), max_length=5, > > blank=True) > > point = models.PointField(blank=True, null=True) > > > > objects = models.GeoManager() > > > > > > > > def save(self, force_insert=False, force_update=False): > > > > if self.point == None: > > location = "%s+%s+%s+%s" % (self.address, self.city, > > self.state, self.zipcode) > > point_lat, point_long = get_lat_long(location) > > pnt = Point(point_long, point_lat) > > self.point = pnt > > > > Here I convert latitude , longitude value into point field value. But > > i am getting "Exception Value: Invalid parameters given for Point > > initialization." > > > > please advise... > > Thank you > > > > Trace back > > --- > > Environment: > > > > Request Method: POST > > Request URL: http://192.168.1.57:8000/admin/people/person/add/ > > Django Version: 1.1 > > Python Version: 2.5.2 > > Installed Applications: > > ['peoplesearch.people', > > 'django.contrib.admin', > > 'django.contrib.gis', > > 'django.contrib.auth', > > 'django.contrib.contenttypes', > > 'django.contrib.sessions', > > 'django.contrib.sites', > > 'django.contrib.databrowse', > > 'peoplesearch.haystack'] > > Installed Middleware: > > ('django.middleware.common.CommonMiddleware', > > 'django.contrib.sessions.middleware.SessionMiddleware', > > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > > > > > Traceback: > > File "/root/myprojects/directory/django/core/handlers/base.py" in > > get_response > > 92. response = callback(request, *callback_args, > > **callback_kwargs) > > File "/root/myprojects/directory/django/contrib/admin/options.py" in > > wrapper > > 226. return self.admin_site.admin_view(view)(*args, > > **kwargs) > > File "/root/myprojects/directory/django/views/decorators/cache.py" in > > _wrapped_view_func > > 44. resp
Django point field
Hi all, I have a problem to convert latitude and longitude values into point field value. def get_lat_long(location): key = settings.GOOGLE_API_KEY output = "csv" location = urllib.quote_plus(location) request = "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s"; % (location, output, key) data = urllib.urlopen(request).read() dlist = data.split(',') if dlist[0] == '200': #return "%s, %s" % (dlist[2], dlist[3]) return (dlist[2], dlist[3]) else: return '' My models.py -- class Person(models.Model): address = models.CharField(_('address'), max_length=200, blank=True) city = models.CharField(_('city'), max_length=100, blank=True) state = USStateField(_('state'), blank=True) zipcode = models.CharField(_('zip code'), max_length=5, blank=True) point = models.PointField(blank=True, null=True) objects = models.GeoManager() def save(self, force_insert=False, force_update=False): if self.point == None: location = "%s+%s+%s+%s" % (self.address, self.city, self.state, self.zipcode) point_lat, point_long = get_lat_long(location) pnt = Point(point_long, point_lat) self.point = pnt Here I convert latitude , longitude value into point field value. But i am getting "Exception Value: Invalid parameters given for Point initialization." please advise... Thank you Trace back --- Environment: Request Method: POST Request URL: http://192.168.1.57:8000/admin/people/person/add/ Django Version: 1.1 Python Version: 2.5.2 Installed Applications: ['peoplesearch.people', 'django.contrib.admin', 'django.contrib.gis', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.databrowse', 'peoplesearch.haystack'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/root/myprojects/directory/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/root/myprojects/directory/django/contrib/admin/options.py" in wrapper 226. return self.admin_site.admin_view(view)(*args, **kwargs) File "/root/myprojects/directory/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/root/myprojects/directory/django/contrib/admin/sites.py" in inner 186. return view(request, *args, **kwargs) File "/root/myprojects/directory/django/db/transaction.py" in _commit_on_success 240. res = func(*args, **kw) File "/root/myprojects/directory/django/contrib/admin/options.py" in add_view 734. self.save_model(request, new_object, form, change=False) File "/root/myprojects/directory/django/contrib/admin/options.py" in save_model 557. obj.save() File "/root/myprojects/peoplesearch/../peoplesearch/people/models.py" in save 118. pnt = Point(point_long, point_lat) File "/root/myprojects/directory/django/contrib/gis/geos/point.py" in __init__ 32. raise TypeError('Invalid parameters given for Point initialization.') Exception Type: TypeError at /admin/people/person/add/ Exception Value: Invalid parameters given for Point initialization. --~--~-~--~~~---~--~~ 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: admin.py -- AlreadyRegistered
hi, class BookAdmin(admin.ModelAdmin): pass # admin.site.register(Book, BookAdmin) Just put '#' in front of admin.site.register(Book, BookAdmin) .Now run the server ,if it s ok then remove the # On Tue, Dec 2, 2008 at 12:47 PM, Roland van Laar <[EMAIL PROTECTED]> wrote: > > djan wrote: > > Hello. > > > > I'm following along with djangobook.com and trying to make necessary > > changes to port django to version 1.0. In Django's Site > > Administration, chapter 6, I run into the error: > > > > > > Exception Type: AlreadyRegistered > > Exception Value: The model Book is already registered > > Exception Location: /usr/local/lib64/python2.5/site-packages/django/ > > contrib/admin/sites.py in register, line 64 > > > > > Probably: > Try to restart the django development server. > The django dev server doesn't reload the admin.py file properly when it's > edited or when it encounters an error in that file. > > > > I used the site administration site successfully with just "Book", and > > then when I attempted to add the other models (Auther, Publisher), I > > received the above error. > > > > in admin.py I have: > > > > from django.contrib import admin > > from models import Book, Author, Publisher > > > > > On another note, you don't have to do this: > > > class BookAdmin(admin.ModelAdmin): > > pass > > admin.site.register(Book, BookAdmin) > > > admin.site.register(Book) > > would suffice. > > > class AuthorAdmin(admin.ModelAuthor): > > pass > > admin.site.register(Author, AuthorAdmin) > > > > class PublisherAdmin(admin.ModelPublisher): > > pass > > admin.site.register(Publisher, PublisherAdmin) > > > > When I updated admin.py I ran: > > python manage.py syncdb > > > > It is as if the database wasn't "synced" though, and that two > > instances of this model are trying to be created. > > > > When I searched around for this error, I found instances of this > > occuring in 0.96, with the model being called several times. The Admin > > changes in 1.0 were said to resolve this, so perhaps it is something > > else. > > > > I appreciate any help. Thanks! > > > > > Regards, > > Roland > > > > > > --~--~-~--~~~---~--~~ 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: Form POST Issue
Thanks Karen Tracey,I typecast the posted value as integer. now Its works fine. On Tue, Dec 2, 2008 at 3:28 AM, Karen Tracey <[EMAIL PROTECTED]> wrote: > In the future, if you click "Switch to copy-and-paste-view" and then just > copy and paste the contents of the traceback window, that is generally > easier to deal with. The traceback in your screenshot (which shows your > photosapp/views.py on line 104 calling paginator.page) doesn't match up with > the code you originally showed (where I don't see any call to > paginator.page) so it's a little hard to be entirely sure what is going > wrong. I'd guess you are passing in a unicode value from the POST data and > the paginator is expecting an integer. So if you cast your value to an int > before handing it to the Paginator that may fix it. Possibly the Paginator > should handle this more gracefully, but I'm not sure since I don't have a > full idea of what you code is doing, exactly, and I'm traveling so don't > have time to try to replicate the error myself at the moment. > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Form POST Issue
Hi All, I need to pass the "totalItems" value as argument to Paginator(disp, totalItems) function if It is POST. But it throws the error "coercing to Unicode: need string or buffer, int found" How do I rectify it. Thanks def detail(request, gallery_slug, page=0): if request.method == 'POST': totalItems = request.POST['quantity'] else: totalItems = 6 gallery = get_object_or_404(Gallery, slug__iexact=gallery_slug) disp = Photo.objects.filter(gallery=gallery) paginator = Paginator(disp, totalItems) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
image resizing
Hi All, Can Any one help me to resize all types of (like jpeg,gif ect) images. This code only useful to upload Jpeg images only. When I upload a image 'thumbnail' folder has two images and when I delete the image only one image is deleted from folder(Resized image or thumbnail image ).I need to delete both the images . Please advise me. thanks. models.py ` from __future__ import division import os import tempfile import Image from django.core.files import File class Picture(models.Model): name = models.CharField(max_length=200) thumbnail = models.ImageField(upload_to='thumbnail') def save(self, force_update=False, force_insert=False): orig = Image.open(self.thumbnail.path) name = os.path.basename(self.thumbnail.name) width = 100 height = 100 thumb = orig.resize((width, height), Image.ANTIALIAS) thumb_file = tempfile.NamedTemporaryFile('w+b') thumb.save(thumb_file,'JPEG') self.thumbnail.save(name, File(thumb_file), False) thumb_file.close() #tempfile is deleted upon close:) super(Picture, self).save(force_update, force_insert) --~--~-~--~~~---~--~~ 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: automatically save latitude and longitude of the address.
Thanks Adam .It works fine. On Mon, Nov 17, 2008 at 10:51 PM, Adam Fast <[EMAIL PROTECTED]> wrote: > > I can see several causes here why you're not getting the desired > result. The biggest one is you declare fnclatitude as taking a single > argument, called location - but when you call the function from your > save() method you're passing no arguments to it. > > Second, you're returning element 3 (which is longitude) and calling it > latitude. > > There are two possible ways to rewrite the code to work: > > 1: (bring the call to Google into the save() method, which is > perfectly acceptable if this is the only model that requires > geocoding) > > Code at: http://dpaste.com/91472/ > > 2: (keep it seperate, which is more useful if other models in your > system will require geocoding. I'd definitely rename the function > though because it's doing more than just returning latitude at that > point.) > > Code at: http://dpaste.com/91483/ > > Adam > > > On Mon, Nov 17, 2008 at 3:19 AM, please smile <[EMAIL PROTECTED]> > wrote: > > HI All, > > > > How can I add automatically latitude and longitude of the physical > address. > > for exp if, fnclatitude('Chennai') returns latitude and longitude of > > chenai. > > > > Please help > > > > This is my model (models.py) > > > > def fnclatitude(location): > > key = settings.GOOGLE_KEY > > output = "csv" > > location = urllib.quote_plus(location) > > request = "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s"; > % > > (location, output, key) > > data = urllib.urlopen(request).read() > > dlist = data.split(',') > > if dlist[0] == '200': > > return "%s" % (dlist[3]) > > #return "%s, %s" % (dlist[2], dlist[3]) > > else: > > return '' > > > > class Business(models.Model): > > physicaladdr_street1 = models.CharField("Street 1", max_length=25) > > modified_date = models.DateTimeField() > > latitude = models.DecimalField(max_digits=11, decimal_places=6, > > null=True, blank=True) > > longitude = models.DecimalField(max_digits=11, decimal_places=6, > > null=True, blank=True) > > > > > > > > def save(self, force_insert=False, force_update=False): > > self.modified_date = datetime.datetime.now() > > self.latitude = fnclatitude() > > # here I need to automatically add latitude and longitude of the > > physical address. > > # for exp if, fnclatitude('Chennai') returns latitude and > > longitude of chenai. > > super(Business, self).save(force_insert, force_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-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 -~--~~~~--~~--~--~---
automatically save latitude and longitude of the address.
HI All, How can I add automatically latitude and longitude of the physical address. for exp if, fnclatitude('Chennai') returns latitude and longitude of chenai. Please help This is my model (models.py) def fnclatitude(location): key = settings.GOOGLE_KEY output = "csv" location = urllib.quote_plus(location) request = "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s"; % (location, output, key) data = urllib.urlopen(request).read() dlist = data.split(',') if dlist[0] == '200': return "%s" % (dlist[3]) #return "%s, %s" % (dlist[2], dlist[3]) else: return '' class Business(models.Model): physicaladdr_street1 = models.CharField("Street 1", max_length=25) modified_date = models.DateTimeField() latitude = models.DecimalField(max_digits=11, decimal_places=6, null=True, blank=True) longitude = models.DecimalField(max_digits=11, decimal_places=6, null=True, blank=True) def save(self, force_insert=False, force_update=False): self.modified_date = datetime.datetime.now() self.latitude = fnclatitude() # here I need to automatically add latitude and longitude of the physical address. # for exp if, fnclatitude('Chennai') returns latitude and longitude of chenai. super(Business, self).save(force_insert, force_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-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 -~--~~~~--~~--~--~---
help for RSS Feed
Hi All , Can anybody please send me a small RSS feed application using django. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
fetching images from database
Hi All, I have uploaded some images in a folder and also saved the image name into data base table. Now I need to fetch and display all the images to my client side web page . How can I do this .Please help. Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help to Upload image
Hi All, Can anybody please tell how to upload a image ? models.py class photos(models.Model): caption = models.CharField(max_length=10) photo = models.ImageField(upload_to= 'Path') It works at Admin Side .But not working at client side. MyHtml.html Caption : Image : What would be the views.py code ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
help for Date base generic views
Hi All, Can anyone please send me a small date based generic view application . 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 -~--~~~~--~~--~--~---