How to get the current record id from django admin form?
I am using django version 1.0. I have a admin with a form for custom validation. My validation is done in def clean(self): The problem is that I have a requirement to get the record id to check against database for data validation. But i don't know how to do. My model is: class Category(models.Model): name = models.CharField(max_length=100) parent = models.ForeignKey('self') The validation is to check if user selected the record itself as its "parent", which is illogical. I think i need to get the record id to check against database. However, i am only able to get form values, but not the record id. Do you have any idea? Arnold --~--~-~--~~~---~--~~ 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 1.0 admin with inline model, IntegrityError when delete
I have upgraded to django 1.0 beta or the latest version for my development machine. And faced IntegrityError when i delete a record with few related records. This problem do not happen before django 1.0 A Product model and a Part model, which is a 1-to-many relationship, (a Product can have multiple Parts). The Parts has an InlineAdmin in Product admin, so that i can modify the Part records which belongs to it on the same admin page. I have created Product record, with some Part records (which belong to the Product record) and save, it is OK. When i delete the product record i have created. The django admin shows a confirmation page. Say that: Are you sure? Are you sure you want to delete the product "My Product"? All of the following related items will be deleted: I answered: "Yes, I'm Sure", but it shows 1451, 'Cannot delete or update a parent row: a foreign key constraint fails' Do you know why? my models.py and admin.py are as follows: -- models.py -- class Product(models.Model): name = models.CharField(max_length=100) class Part(models.Model): product = models.ForeignKey(product) name = models.CharField(max_length=100) -- admin.py -- class PartInline(admin.TabularInline): model = Part class ProductAdmin(admin.ModelAdmin): inlines = [PartInline] admin.site.register(Product, ProductAdmin) --~--~-~--~~~---~--~~ 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: Method 'allow_tags' doesn't work?
I also faced this problem, i have a rolled-out site, using the allow_tags method to do a critical mission in a customized admin site. regards, Arnold On Nov 16, 3:34 am, wowar <[EMAIL PROTECTED]> wrote: > Today, after updating django to revision 6678 method 'allow_tags' > doesn't work. Despite it is set to True I've got html code. > > Regards, > WW --~--~-~--~~~---~--~~ 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: ImageField Validation Error
I faced this problem as well, but there is a work around. I am using django 0.97 pre (i downloaded from svn 16th Nov, 2007) Go to c:/python2.4/lib/site-packages/django/core/validators.py or /usr/lib/python2.4/site-packages/django/core/validators.py , if you are using Fedora comment the following lines (the line numbers in my version is 186 and 187 trial_image = Image.open(StringIO(content)) trial_image.load() Good luck On Nov 5, 3:27 am, Matt <[EMAIL PROTECTED]> wrote: > I've got a model with anImageField. But, when I attempt to add an > image via the Admin interface, I receive theerrormessage: "Upload a > valid image. The file you uploaded was either not an image or a > corrupted image." > > I'm pretty sure that all of my paths are set correctly because I can > change the field to a FileField and add an image without any problems. > I can also successfully work with the same image field via PIL - so I > don't think it's not an issue with the actual image file or PIL. > > Is this a bug or is there something I'm not doing right? I'm running > the latest Django from SVN, PIL 1.1.6 and Python 2.5.1 on OS X 10.5. > 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 -~--~~~~--~~--~--~---
Re: Using auth in model
Sorry, there is a typo mistake, my question is "how to get logged-in" user WITHOUT request parameter. Because i want to use it in a function in models.py regards, Arnold On 11月8日, 下午8時18分, Dan Fairs <[EMAIL PROTECTED]> wrote: > > My question above can be simplified as "how to get logged-in user with > > request parameter" > > request.user will give you the logged-in user. > > If you want to know more about Django profile support, read the docs: > >http://www.djangobook.com/en/beta/chapter12/ > > You want the profiles section, near the bottom. > > Cheers, > Dan > > -- > Dan Fairs <[EMAIL PROTECTED]> --~--~-~--~~~---~--~~ 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: Using auth in model
My question above can be simplified as "how to get logged-in user with request parameter" On Nov 8, 12:32 pm, Arnold Chen <[EMAIL PROTECTED]> wrote: > I want to let users to create their own profile in django admin. And > when they save any new records, use their logged-in user id > (models.ForeignKey(User)) and override the save() function of the > model. > > Is there any statement that i can use? i believe it should be > something like auth.user > > 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 -~--~~~~--~~--~--~---
Using auth in model
I want to let users to create their own profile in django admin. And when they save any new records, use their logged-in user id (models.ForeignKey(User)) and override the save() function of the model. Is there any statement that i can use? i believe it should be something like auth.user 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 -~--~~~~--~~--~--~---
i18n/setlang no longer support GET
I used to use /i18n/setlang?language=zh-cn approach to change language. However i found that the latest (as of this writing 20th Sept, 2007) svn version django do not support calling the url using GET, and there is a sentence in the function set_language in the i18n.py file "Since this view changes how the user will see the rest of the site, it must only be accessed as a POST request." The django website shows an example of using the convenient setlang function and the url is: http://www.djangoproject.com/documentation/i18n/#the-set-language-redirect-view This example is good to demonstrate the power of the function, but the usability is not as good as its functionality. Imagine the user don't even know English. So, the user don't know even he/she should click on the selection box and select. So i use my own way showing "English | 中文 | 日文 | Français" and hyperlinking each language to corresponding setlang URL. For example, setlang?language=fr for Français. I don't know why the developers change like that, and if there any one can, please tell me the consequences of using GET (by modifying the set_language function by myself) Arnold --~--~-~--~~~---~--~~ 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: SOMETIMES mod_python error
Yes, the server has been restarted many times On 9月11日, 下午6時54分, Ryan K <[EMAIL PROTECTED]> wrote: > Have you tried restarting the web server? > > Arnold Chen wrote: > > Dear all, > > > I am experiencing some situation that is very strange. the development > > site ishttp://alberta.design97.com > > > This site is django-powered, it is up sometimes, on some computers, > > you can visit this site for a preview, if you get an error, try reload > > the page, usually the page will show within 5-10 times reload. > > > The error message that i SOMETIMES got is: > > > MOD_PYTHON ERROR > > > ProcessId: 15673 > > Interpreter:'alberta.design97.com' > > > ServerName: 'alberta.design97.com' > > DocumentRoot: '/var/www/vhosts/design97.com/subdomains/alberta/ > > httpdocs' > > > URI:'/' > > Location: '/' > > Directory: None > > Filename: '/var/www/vhosts/design97.com/subdomains/alberta/ > > httpdocs/' > > PathInfo: '' > > > Phase: 'PythonHandler' > > Handler:'django.core.handlers.modpython' > > > Traceback (most recent call last): > > > File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line > > 1537, in HandlerDispatch > > default=default_handler, arg=req, silent=hlist.silent) > > > File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line > > 1229, in _process_target > > result = _execute_target(config, req, object, arg) > > > File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line > > 1128, in _execute_target > > result = object(arg) > > > File "/usr/lib/python2.3/site-packages/django/core/handlers/ > > modpython.py", line 177, in handler > > return ModPythonHandler()(req) > > > File "/usr/lib/python2.3/site-packages/django/core/handlers/ > > modpython.py", line 150, in __call__ > > response = self.get_response(request) > > > File "/usr/lib/python2.3/site-packages/django/core/handlers/ > > base.py", line 111, in get_response > > return debug.technical_500_response(request, *sys.exc_info()) > > > File "/usr/lib/python2.3/site-packages/django/views/debug.py", line > > 103, in technical_500_response > > pre_context_lineno, pre_context, context_line, post_context = > > _get_lines_from_file(filename, lineno, 7, loader, module_name) > > > File "/usr/lib/python2.3/site-packages/django/views/debug.py", line > > 195, in _get_lines_from_file > > context_line = source[lineno].strip('\n') > > > IndexError: list index out of range --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
SOMETIMES mod_python error
Dear all, I am experiencing some situation that is very strange. the development site is http://alberta.design97.com This site is django-powered, it is up sometimes, on some computers, you can visit this site for a preview, if you get an error, try reload the page, usually the page will show within 5-10 times reload. The error message that i SOMETIMES got is: MOD_PYTHON ERROR ProcessId: 15673 Interpreter:'alberta.design97.com' ServerName: 'alberta.design97.com' DocumentRoot: '/var/www/vhosts/design97.com/subdomains/alberta/ httpdocs' URI:'/' Location: '/' Directory: None Filename: '/var/www/vhosts/design97.com/subdomains/alberta/ httpdocs/' PathInfo: '' Phase: 'PythonHandler' Handler:'django.core.handlers.modpython' Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line 1229, in _process_target result = _execute_target(config, req, object, arg) File "/usr/lib/python2.3/site-packages/mod_python/importer.py", line 1128, in _execute_target result = object(arg) File "/usr/lib/python2.3/site-packages/django/core/handlers/ modpython.py", line 177, in handler return ModPythonHandler()(req) File "/usr/lib/python2.3/site-packages/django/core/handlers/ modpython.py", line 150, in __call__ response = self.get_response(request) File "/usr/lib/python2.3/site-packages/django/core/handlers/ base.py", line 111, in get_response return debug.technical_500_response(request, *sys.exc_info()) File "/usr/lib/python2.3/site-packages/django/views/debug.py", line 103, in technical_500_response pre_context_lineno, pre_context, context_line, post_context = _get_lines_from_file(filename, lineno, 7, loader, module_name) File "/usr/lib/python2.3/site-packages/django/views/debug.py", line 195, in _get_lines_from_file context_line = source[lineno].strip('\n') IndexError: list index out of range --~--~-~--~~~---~--~~ 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: php fsockopen equivalent in Django
How come i don't remember using the python socket ? thanks James On Sep 10, 1:13 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On 9/9/07, Arnold Chen <[EMAIL PROTECTED]> wrote: > > > I am writing an application that require "silent" post of data to a > > specific URL. I know that is a function fsockopen in PHP which can > > achieve this, and i am looking for function in Django like that. > > http://docs.python.org/lib/module-socket.html > > Remember that "Django" is not a programming language; Django is > written in Python, and does not try to duplicate things Python already > handles. So when you find yourself looking for the counterpart to > something you're used to from another language, the Python > documentation is the best place to check. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
php fsockopen equivalent in Django
Dear All, I am writing an application that require "silent" post of data to a specific URL. I know that is a function fsockopen in PHP which can achieve this, and i am looking for function in Django like that. fsockopen is used to Open Internet or Unix domain socket connection. and you can post GET, POST data to a URL silently, here is an example code: \n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> To know more about fsockopen : http://www.php.net/fsockopen --~--~-~--~~~---~--~~ 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: Using session variable in models
You know? you are superb!!! Arnold On Jul 25, 7:19 am, "Wolfram Kriesing" <[EMAIL PROTECTED]> wrote: > and i forgot, this allows you to access the property "name" of the > object anywhere seemlessly, in the template, in the code, etc. this is > pretty neat imho :-) > > wolfram > > On 7/25/07, Wolfram Kriesing <[EMAIL PROTECTED]> wrote: > > > > > after some investigation and help from the list i took this approach > > and have to say it works great: > > > from django.utils import translation > > > @property > > def name(self): > > if translation.get_language()=="en": > > return self.name_en > > else: > > return self.name_de > > > good luck > > > wolfram > > > On 7/25/07, Arnold Chen <[EMAIL PROTECTED]> wrote: > > > > I am implementing a multi-lingual product catalog website with Django. > > > It is in English (default), Trad. Chinese and Simp. Chinese. I want to > > > let user to choose the language they want, and the system display the > > > corresponding product name (in the selected language). > > > > The product class is something like > > > > # === start class = > > > class Product(models.Model) > > >name_en = mode.CharField() > > >name_tw = mode.CharField() > > >name_cn = mode.CharField() > > > >def get_name(self, lang="en"): > > > return eval("self.name_" + lang) > > > > # === end class = > > > > The language preference that user has chosen will be saved in > > > request.session['django_language'] > > > > Of cos, i don't know how to use the get_name() function that i've > > > implemented, because i can't pass the lang from view or template. So, > > > the question is how do i get the request.session['django_language'] > > > variable in models ? or is there any other way to achieve the desired > > > result? > > > > Thanks in advance. > > > Arnold > > > -- > > cu > > > Wolfram > > -- > cu > > Wolfram --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using session variable in models
I am implementing a multi-lingual product catalog website with Django. It is in English (default), Trad. Chinese and Simp. Chinese. I want to let user to choose the language they want, and the system display the corresponding product name (in the selected language). The product class is something like # === start class = class Product(models.Model) name_en = mode.CharField() name_tw = mode.CharField() name_cn = mode.CharField() def get_name(self, lang="en"): return eval("self.name_" + lang) # === end class = The language preference that user has chosen will be saved in request.session['django_language'] Of cos, i don't know how to use the get_name() function that i've implemented, because i can't pass the lang from view or template. So, the question is how do i get the request.session['django_language'] variable in models ? or is there any other way to achieve the desired result? Thanks in advance. Arnold --~--~-~--~~~---~--~~ 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 serving static PDF file
Besides, i want to revise my first question as: How to serve static file by "pushing" a PDF to client? In php, there is a way to serve PDF by pushing the file to the client, and client to choose "Save As" or "Open" the file directly. Adobe reader is very slow if they run in browsers, and most of the time, they hang the browser, so is there a way to push ? regards, Arnold On Jul 17, 4:03 pm, Arnold Chen <[EMAIL PROTECTED]> wrote: > Thanks Ben, > > Besides, i've found thatwww.lawrence.comandwww.ljworld.com(which > are famous sites that use django) use ahttp://media.their-domain-name.com > to store the media files. > All static files, images, css are from thehttp://media.their-domain-name.com > server. Obviously the media subdomain is not a django environment, i > wonder if we can setup an environment like that, and can i still > upload image to the media subdomain from the django admin console? > > Arnold > > On Jul 17, 3:29 pm, Ben van Staveren <[EMAIL PROTECTED]> wrote: > > > You're better off not doing it with Django, just make a directory > > that won't be handled by Django and stick all your static content in > > there. After all, the webserver is usually better at serving static > > files than Django is :) > > > On 17/07/2007, at 2:26 PM, Arnold Chen wrote: > > > > Can any one please tell me how to serve a static PDF in django ? The > > > file is located in the server, and do not need to be created on the > > > fly (by using report lab). I have done it in PHP by using header, but > > > i just don't know how to do it with 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 -~--~~~~--~~--~--~---
Re: Django serving static PDF file
Thanks Ben, Besides, i've found that www.lawrence.com and www.ljworld.com (which are famous sites that use django) use a http://media.their-domain-name.com to store the media files. All static files, images, css are from the http://media.their-domain-name.com server. Obviously the media subdomain is not a django environment, i wonder if we can setup an environment like that, and can i still upload image to the media subdomain from the django admin console? Arnold On Jul 17, 3:29 pm, Ben van Staveren <[EMAIL PROTECTED]> wrote: > You're better off not doing it with Django, just make a directory > that won't be handled by Django and stick all your static content in > there. After all, the webserver is usually better at serving static > files than Django is :) > > On 17/07/2007, at 2:26 PM, Arnold Chen wrote: > > > > > Can any one please tell me how to serve a static PDF in django ? The > > file is located in the server, and do not need to be created on the > > fly (by using report lab). I have done it in PHP by using header, but > > i just don't know how to do it with 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 -~--~~~~--~~--~--~---
Django serving static PDF file
Can any one please tell me how to serve a static PDF in django ? The file is located in the server, and do not need to be created on the fly (by using report lab). I have done it in PHP by using header, but i just don't know how to do it with 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 -~--~~~~--~~--~--~---