Re: File Uploading
enctype 2009/2/12 huw_at1 > > Yep I just found the thread about the enctype and indeed it was this > and not my comp catching fire!!! Many thanks :) > > On Feb 12, 2:48 pm, Alex Gaynor wrote: > > On Thu, Feb 12, 2009 at 9:38 AM, Karen Tracey > wrote: > > > On Thu, Feb 12, 2009 at 8:02 AM, huw_at1 wrote: > > > > >> Hi all, > > > > >> I am trying to write a simple app that allows a user to select a file > > >> (via the browse button) from which data can be read in and parsed. I > > >> have read several examples but none seem to do exactly what I want. I > > >> have built a form and so am trying to use forms.FileField(). I can add > > >> this field no problem to my form. However I am not sure I understand > > >> how I am supposed to pull the data contained within the file from > > >> within my views. I tried: > > > > >> > > >> file = forms.FileField() > > > > >> > > > > >> if request.FILES: > > >> filename = request.FILES['file'] > > > > >> ... > > > > >> However I cant seem to get this to work. Does anyone have any good > > >> tutorials or can offer any suggestions? > > > > > Can't get it to work means what, exactly? Your get an error message? > Your > > > filename variable winds up being set to to something you aren't > expecting? > > > Your computer catches fire? > > > > > This page: > > > > >http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ > > > > > discusses handling uploaded files in some detail. As described there, > > > request.FILES['file'] will be an UploadedFile object, so your > assignment of > > > it to a variable named 'filename' rather sounds like you have > misunderstood > > > something there, since request.FILES['file'] will be more than the > file's > > > name, it will be an object with methods and attributes that (as > detailed on > > > that page) that let you access the uploaded file's name, size, and data > > > (either in chunks or in one piece). There's an example > handle_uploaded_file > > > function that iterates through the data chunks and does something with > > > them. Obviously it's not going to do exactly what you want to do with > your > > > file data, but that page lays out a whole working structure and would > seem > > > to be a good starting point for you to use in developing your specific > > > file-handling code. > > > > > Karen > > > > Remember to set the enctype on your form, this is something a lot of > people > > forget. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero- Hide quoted text - > > > > - Show quoted text - > > > --~--~-~--~~~---~--~~ 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: __unicode__(self):
add"self" 2008/4/14, Malcolm Tredinnick <[EMAIL PROTECTED]>: > > > > On Sun, 2008-04-13 at 22:04 -0700, Brandon Taylor wrote: > > Hello everyone, > > > > I'm pretty new to Django, so please bear with me. > > > > When I'm defining a model, and I want to return a value to use in the > > admin for the information to be displayed as such: > > > > from django.db import models > > > > class Link(models.Model): > > name = models.CharField() > > url = models.CharField() > > position = models.PositiveSmallIntegerField() > > > > def __unicode__(self): > > return name > > > That will give you a NameError, since "name" does not exist. You want to > do "return self.name" there. > > > > Is it possible to concatenate fields for the def__unicode__(self) > > method? I can't seem to find a way to do that, and was just wondering > > if it's possible? > > > A __unicode__ method must return a unicode string. That's all. How you > construct that string is entirely up to you. If you want to construct it > by putting various attribute values together, that's fine. It's just > Python. So, for example, > > return u"%s %s" % (self.name, self.url) > > would return a concatenation of the name and url attributes. Season to > taste. > > Regards, > Malcolm > > > -- > Honk if you love peace and quiet. > http://www.pointy-stick.com/blog/ > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: "get next" and "get last" on any field?
*get next* = Info.objects.filter(id__gt=newsid).order_by('id')[:1] *get last* = Info.objects.filter(id__lt=newsid).order_by('id')[:1] 2008/4/5, SlowLearner <[EMAIL PROTECTED]>: > > > Hi, I am hoping there is a better solution to my problem than the one > I have come up with, or one built in to the django models. > > I would like to include "get next" and "get last" buttons on my view. > > The catch is that I want to do get next, get last on an integer field > (which is not a primary key but is unique, if that make a difference). > > Searching in the group and googling the internet in general turns up a > few things but these are date based or quite old posts suggesting > creating managers etc. > > My current solution is a brute force cycle over all the objects until > I find the object wanted, the previous and the next which is not ideal > but works. > > I am currently using 0.96 but I am intending to download trunk in the > not too distant future as there is a templatetag application I want to > use which does not work under 0.96. > > 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-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: JSON serializers.serialize raises DoesNotExist on recursive data structures
Is this model work on in admin? 2008/4/1, Legioneer <[EMAIL PROTECTED]>: > > > My data model is very similar to your: > > class Category(models.Model): > name = models.CharField(max_length=64) > descr = models.CharField(max_length=255, blank=True) > rank = models.PositiveIntegerField(default=10) > parent = models.ForeignKey('self', null=True, blank=True, > related_name='child_set') > > but because of some reason it doesn't want to to go through JSON > serializer :( > > Anthony > > > > this is my example > > > > class Type(models.Model): > > type = models.CharField('分类名称',maxlength=50,core=True) > > path = models.CharField > ('url地址',maxlength=250,blank=True,editable=False) > > typename = models.CharField('分类名称',maxlength=200,editable=False) > > parent = models.ForeignKey('self',related_name="munchie",null=True, > > blank=True) > > created = models.DateTimeField(auto_now_add=True) > > > > order_id=models.IntegerField ('排序',default=0) > > fid=models.IntegerField ('根ID',default=0,editable=False) > > cengshu=models.IntegerField ('层数',default=1,editable=False) > > > > > > --~--~-~--~~~---~--~~ 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: JSON serializers.serialize raises DoesNotExist on recursive data structures
this is my example class Type(models.Model): type = models.CharField('分类名称',maxlength=50,core=True) path = models.CharField('url地址',maxlength=250,blank=True,editable=False) typename = models.CharField('分类名称',maxlength=200,editable=False) parent = models.ForeignKey('self',related_name="munchie",null=True, blank=True) created = models.DateTimeField(auto_now_add=True) order_id=models.IntegerField ('排序',default=0) fid=models.IntegerField ('根ID',default=0,editable=False) cengshu=models.IntegerField ('层数',default=1,editable=False) 2008/4/1, Legioneer <[EMAIL PROTECTED]>: > > > Thank you, Michael. Tried several combinations but it doesn't work > either. > > 1. First I tried to use Category.objects.all(): > c = Category.objects.all() > serializers.serialize("json", c) > > and got the same error. > > 2. Then tried to init some variable with s[:5] and the result didn't > change. > > 3. When I use some other model which doesn't refer to itself (is a non > recursive) it works fine even when using with lazy filter calls > similar to my first example. > > Anthony > > > On Apr 1, 5:34 am, Michael <[EMAIL PROTECTED]> wrote: > > Your error is actually coming from the fact that you are not getting > > any results from your filter query. The reason that the error is > > appearing on the second line of your script is because filter is a > > lazy call and isn't really made until you ask it to return objects in > > this bit: s[:5]. Change your filter or call Category.objects.all() it > > should work. > > > > Hope that helps, > > Michael > > > > > On Mon, Mar 31, 2008 at 5:39 AM, Legioneer <[EMAIL PROTECTED]> wrote: > > > > > Hi All, > > > > > I'm trying to serialize recursive model (a category which refers to > > > itself) and get a 'DoesNotExist: Category matching query does not > > > exist', while other models work fine. Does anyone know a clue for > > > this? > > > > > I'm doing like this: > > > > > from django.core import serializers; > > > from newproject.models import Category > > > > > s = Category.objects.filter(parent__exact='0') > > > serializers.serialize("json", s[:5]) > > > > > and get: > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > File "/usr/lib/python2.3/site-packages/django/core/serializers/ > > > __init__.py", line 72, in serialize > > > s.serialize(queryset, **options) > > > File "/usr/lib/python2.3/site-packages/django/core/serializers/ > > > base.py", line 48, in serialize > > > self.handle_fk_field(obj, field) > > > File "/usr/lib/python2.3/site-packages/django/core/serializers/ > > > python.py", line 41, in handle_fk_field > > > related = getattr(obj, field.name) > > > File "/usr/lib/python2.3/site-packages/django/db/models/fields/ > > > related.py", line 209, in __get__ > > > rel_obj = self.field.rel.to._default_manager.get(**params) > > > File "/usr/lib/python2.3/site-packages/django/db/models/manager.py", > > > line 69, in get > > > return self.get_query_set().get(*args, **kwargs) > > > File "/usr/lib/python2.3/site-packages/django/db/models/query.py", > > > line 263, in get > > > raise self.model.DoesNotExist, "%s matching query does not exist." > > > % self.model._meta.object_name > > > DoesNotExist: Category matching query does not exist. > > > > > Anthony > > > --~--~-~--~~~---~--~~ 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: Announce: 7days7apps.com
good~~~ it's very cool~~ 2008/1/28, shabda <[EMAIL PROTECTED]>: > > > Hi Every one, > > Just wanted to let everyone know of www.7days7apps.com , where I am > trying to build and deploy 7 small but useful apps in 7 days. By now I > have completed 5 apps. All of them are released under GPL, and the > source for them is available at http://code.google.com/p/7days7apps/ . > If you use them for learning or in a production setting be sure to let > me know. And if you got a few seconds, can you tell me your opinion at > http://day4.7days7apps.com/poll/Does-7days7apps-suck/ > > Thanks, > Shabda > > > --~--~-~--~~~---~--~~ 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: "ImportError: No module named django" persists...
django is in your sys.path? 2008/1/16, Scott <[EMAIL PROTECTED]>: > > > Thank you to anyone who may be of help... > > PROBLEM: > > ImportError: No module named django > > MY SETTINGS: > > /Working/django/django/__init__.py (file exists) > /Working/projects/ (my main project > folder) > /Working/projects/mysite('mysite' project folder) > /usr/lib/python2.4/site-packages(my python packages folder) > (Permissions are 755 with owner:group = root:root) > > httpd.conf directives are... > > > SetHandler python-program > PythonPath "['/Working/django','/Working/modules','/Working/ > projects','/Working/projects/mysite'] + sys.path" > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > # PythonHandler mod_python.testhandler > PythonHandler django.core.handlers.modpython > PythonDebug On > > > OTHER CLUES: > > - Django imports just fine from command line python call with > $PYTHONPATH exported to same directories as location directive. > - If I put my django folder in /usr/lib/python2.4/site-packages/ it > works. > - A sym link from /Working/django/django to /usr/lib/python2.4/site- > packages/django does not work. > - Reference by PythonPath directive also is failing. > - Viewing testhandler output shows that my /Working/* directories are > getting into sys.path alright. > > MY SYSTEM: > > OS = { Red Hat Enterprise Linux 5 | RHEL 5 | RHEL5 } > Python 2.4.3 (#1, Dec 11 2006, 11:38:52) > Apache/2.2.3 (Red Hat) Server > mod_python.version '3.2.8' > Django VERSION = (0, 97, 'pre') > > > Thank you for looking. > > Scott > > > > --~--~-~--~~~---~--~~ 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: TemplateDoesNotExist at /admin/
settings.py TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. #"./templates/", "E:/myproject/wedding/templates/", ) you can copy python/libs/site_packges/django/contrib/admin/templates in you project templates 2008/1/16, Guillermo <[EMAIL PROTECTED]>: > > > > Hi all, > > I'm using Windows XP SP2 + Django 0.96.1. > > Following along the tutorial, I got this error when I tried to access > the admin interface for the first time: > > TemplateDoesNotExist at /admin/ > admin/login.html > Request Method: GET > Request URL:http://127.0.0.1:8000/admin/ > Exception Type: TemplateDoesNotExist > Exception Value:admin/login.html > Exception Location: C:\Python25\lib\site-packages\django\template > \loader.py in find_template_source, line 72 > > I've seen in this board that people solved the issue updating to the > dev version, but that's out of the question for me now --can't use > Subversion. > > I've gone through the tutorial twice step by step, so I don't think I > forgot any instructions explained there. > > Does anyone know how to fix this? I'm dying to start developing > websites with Django! > > Regards, > > Guillermo > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how to form the admin of django. Only users can administrate the informations which published by themselves.
how to form the admin of django. Only users can administrate the informations which published by themselves. How to perform this without using "newforms-admin"? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django admin 中 如何实现用自己添加的信息自己管理?
django admin 中 如何实现用自己添加的信息自己管理? 查了不少资料,newforms admin 分支对定制admin进行了加强可以实现,但因为问题较多不敢使用 ,不知道直接使用目前的 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-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 -~--~~~~--~~--~--~---