Re: pre-save and check for existing value of image
you self.instance.fieldname use this ur from . On Tue, Nov 10, 2009 at 12:58 PM, Ramdas S wrote: > Hi, > > I have this app which has an ImageField, where the image needs to be > cropped, resized, and a few effects (all from PIL) are applied on it, the > model looks something like this > > class MidPanel(models.Model): > >. >image = models.ImageField(upload_to="images"): > >def save(self): > > if self.image: >dosomething(self.image) > > > Everything is fine, expect that every time someone makes a change to a > field in the model, the images gets manipulated. The image manipulation is > supposed to happen only once. > > What I want is somehow to apply the cmanipulation on self.image only if > the image is changed, or its been created... Is pre_seave the right way, if > so how do you actually use it where it need to compare previosly stored data > and the newone and then only execute. > > Ramdas > > > > -- > Ramdas S > +91 9342 583 065 > > > > > --~--~-~--~~~---~--~~ 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 internationalization problem: Error: errors happened while running xgettext on __init__.py /bin/sh: xgettext: command not found
I did not know that gettext should be installed. After installing it ( apt-get install gettext) - Debian, it's working just fine. 2009/11/10 rebus_ > > 2009/11/9 NMarcu : > > > > Hello all, > > > > When I run django-admin.py makemessages -l ro I got this: > > Error: errors happened while running xgettext on __init__.py > > /bin/sh: xgettext: command not found > > > > You know why, I need to install somethng else? > > > > > > > are you sure you have gettext installed on your computer? > > > > -- All the best, Nicolae MARCU --~--~-~--~~~---~--~~ 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: Display a view of a single record?
Yes, the fields should not be editable in a "view". However, I do not see it as "a problem" - more as "a desirable feature". There are any number of use cases for letting users see detailed record data but not be able (or not need, at that point in time) to edit it. This feature is not meant to replace the existing ability to edit a record; but to add another option to the interface. It just seems strange to me that the admin interface allows for display of multiple records in a listing, but has no facility to display a complete, single record "view". I do not want to have redevelop an admin-like interface just to allow for this option (given that is such a generic one). It is not clear from what you say - but I assume that it is not possible to readily alter the current admin interface to incorporate the generic views you refer to? If it is, any guidance, or examples, along these lines would be appreciated. On Nov 9, 2:37 pm, Ludwik Trammer wrote: > I have a really hard time understanding what do you need, and I > suspect I'm not the only one. You are talking about the admin > interface, right? It displays a list containing all records, and when > you click on a record you go to a page that shows all fields for this > record (and lets you change their values). Isn't that exactly what you > want? > > If the problem is that you don't want the fields to be editable, > because you just want to display read-only lists of records: re-think > using admin interface. It is meant specifically for managing records > on your website. Just use > "django.views.generic.list_detail.object_list" (display list of > records) and "django.views.generic.list_detail.object_detail" (display > detailed view of a single record) generic views: > > http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-... --~--~-~--~~~---~--~~ 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: MySQL and 'NoneType object is unsubscriptable' error
On Nov 10, 1:36 am, Julien Phalip wrote: > Hi, > > I've tried to install MySQL for an existing project, and I'm getting a > strange error (see traceback below). Apparently "self.converter" is > None, but I can't see why. > > I can access the database just fine using the 'mysql' command in the > terminal or using PhpMyAdmin. > > Do you know how this could be fixed? > > Thanks a lot for you help. > > Julien > > Traceback (most recent call last): > File "/Users/julien/Documents/Development/eclipse/workspace/ > myproject/trunk/site/manage.py", line 13, in > execute_manager(settings) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/__init__.py", line 439, in execute_manager > utility.execute() > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/__init__.py", line 380, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/base.py", line 195, in run_from_argv > self.execute(*args, **options.__dict__) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/base.py", line 222, in execute > output = self.handle(*args, **options) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/commands/runserver.py", line 84, in handle > inner_run() > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/commands/runserver.py", line 48, in inner_run > self.validate(display_num_errors=True) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/base.py", line 249, in validate > num_errors = get_validation_errors(s, app) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/core/management/validation.py", line 67, in > get_validation_errors > connection.validation.validate_field(e, opts, f) > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/db/backends/mysql/validation.py", line 15, in validate_field > db_version = connection.get_server_version() > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/db/backends/mysql/base.py", line 297, in get_server_version > self.cursor() > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/db/backends/__init__.py", line 81, in cursor > cursor = self._cursor() > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > django/db/backends/mysql/base.py", line 281, in _cursor > self.connection = Database.connect(**kwargs) > File "/opt/local/lib/python2.5/site-packages/MySQLdb/__init__.py", > line 81, in Connect > return Connection(*args, **kwargs) > File "/opt/local/lib/python2.5/site-packages/MySQLdb/ > connections.py", line 222, in __init__ > self.converter[FIELD_TYPE.STRING].append((None, string_decoder)) > TypeError: 'NoneType' object is unsubscriptable Looks like a problem with your database connection settings. Can you post the relevant bits from settings.py? -- 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-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: How to handle this race condition?
>> 1) retrieve the current_high_bid field of the Auction object >> 2) compare it with the new_bid >> 3) if the new bid is higher than current_high_bid, I update >> current_high_bid to the value of the new_bid. >> >> but there's a (slight) chance that between steps (1) and (3) a >> different user could've submitted an even higher bid which then become >> the current_high_bid. In that case step 3 should not proceed. What can >> I do to make sure such a situation does not arise? > > For now, you can write custom SQL (consider this pseudo-code rather > than a drop-in replacement): > > """ Be sure this all runs inside a single transaction! Use the > appropriate middleware or > decorators... """ > cursor = connection.cursor() > cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE id=%s > FOR UPDATE", [auction.id]) > """ Until this SELECT, other users could have modified the high > bid, so do not trust the > in-memory copy. """ > returned_rows = cursor.fetchall() > high_bid = returned_rows[0][0] > if new_bid > high_bid: > auction.high_bid = new_bid > auction.save() If you are going to drop to raw SQL, you can let SQL handle the atomicity: UPDATE auction SET current_high_bid = %(new_bid)f WHERE id = %(auction_id)i AND %(new_bid)f > current_high_bid If the new_bid is based on data in another table of bid-histories, you can use something like UPDATE auction SET current_high_bid = ( SELECT Max(bid) FROM Bids WHERE auction_id = %(auction_id)s ) WHERE id = %(auction_id)i AND ( SELECT Max(bid) FROM Bids WHERE auction_id = %(auction_id)s ) > current_high_bid Adjust for table-names and field-names. It should be fairly portable SQL, working across all of the big 3 Django databases (sqlite, postgres, and recent versions of mysql that support sub-selects...it also happens to work in SQL Server, FWIW) -tim --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
> (I changed "Education" to "School" because in the admin panel it > showed up as "Educations". I think "Schools" makes more sense.) Did you remember to syncdb afterwards? I'd be interested to see if the SQL you showed is what the tables in the DB actually look like. > Any ideas why Lawyer link in the admin panel does not work? It's on retainer? Hahahaha...sorry...a little 4:30am lawyer humor :) -tim --~--~-~--~~~---~--~~ 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: domains vs sub-domains
Hi, I personally also use option #1 due to performance, scalability and "prettiness" of URL, etc, reasons all mentioned in above posts. On the other hand if you spread your content over a bunch of sub domains you could, instead of increasing performance, downgrade it due to numerous DNS queries which can be quite expensive sometimes. So don't get carried away with static content serving domains. --~--~-~--~~~---~--~~ 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: annotation with filter issue (left join needed)
On Nov 10, 8:29 am, Михаил Лукин wrote: > Well, I didn't find solution yet. Except that filter condition must be > placed in LEFT OUTER JOIN ... ON ( ), but i'm not sure if it's > possible with Django ORM. I notices that Aggregate base class takes 'extra' > argument in its constructor, but I'm not sure how to use it for such > purpose. Django can not handle left joins where the filter conditions need to be in the ON clause of the join. The comment for function join in django.db.models.sql clearly states this. So if you really need to place the filter condition on the left outer join, then there is nothing you can do except use raw SQL. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Will PasswordField be in Django?
Hello, I am new to Django. I'm writing an app with it. And I found there is no PasswordField in Django. I Googled a bit. And I found, in patch #61, that someone has wrote it already. Will it be in place soon? When? Or, what is the matter of it? Koala Yeung --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[newbie] New records and edited records
Hi, I'm following the book "Django 1.0 WEB Site Development" to learn django and python. I modified the function BookmarkSave so that it correctly initialize the checkbox showing if a bookmark is shared or not. I think it's correct, please confirm I used the right way to do it adding share = SharedBookmark.objects.get(bookmark = bookmark) When I try to edit a record and modify the value of the checkbox the functions don't react to it at all. I checked the form values and there is a difference in the parameters of the checkbox between the "new" form and the "edited" one. Could please someone explain me what is going on? the code is: models.py: class Bookmark(models.Model): title=models.CharField(max_length=200) user=models.ForeignKey(User) link=models.ForeignKey(Link) def __unicode__(self): return u'%s, %s' % (self.user.username, self.link.url) class SharedBookmark(models.Model): bookmark = models.ForeignKey(Bookmark, unique=True) date = models.DateTimeField(auto_now_add=True) votes = models.IntegerField(default=1) users_voted = models.ManyToManyField(User) def __unicode__(self): return u'%s, %s' % (self.bookmark, self.votes) forms.py: class BookmarkSaveForm(forms.Form): url = forms.URLField( label=u'URL', widget=forms.TextInput(attrs={'size': 64}) ) title = forms.CharField( label=u'Title', widget=forms.TextInput(attrs={'size': 64}) ) tags = forms.CharField( label=u'Tags', required=False, widget=forms.TextInput(attrs={'size': 64}) ) share = forms.BooleanField( label=u'Share on the main page', required=False ) views.py: def _bookmark_save(request, form): #create or get link link, dummy = Link.objects.get_or_create( url=form.cleaned_data['url'] ) # create or get bookmark bookmark, created = Bookmark.objects.get_or_create( user=request.user, link=link ) # update bookmark title bookmark.title = form.cleaned_data['title'] # if the bookmark is being updated, clear old tag list if not created: bookmark.tag_set.clear() # create new tag list tag_names = form.cleaned_data['tags'].split() for tag_name in tag_names: tag, dummy = Tag.objects.get_or_create(name=tag_name) bookmark.tag_set.add(tag) # share on the main page if requested if form.cleaned_data['share']: shared, created = SharedBookmark.objects.get_or_create( bookmark=bookmark ) if created: shared.users_voted.add(request.user) shared.save() # save bookmark to database bookmark.save() return bookmark @login_required def bookmark_save_page(request): ajax = 'ajax' in request.GET if request.method == 'POST': form = BookmarkSaveForm(request.POST) if form.is_valid(): bookmark = _bookmark_save(request, form) if ajax: variables = RequestContext(request, { 'bookmarks': [bookmark], 'show_edit': True, 'show_tags': True }) return render_to_response('bookmark_list.html', variables) else: return HttpResponseRedirect('/user/%s/' % request.user.username) else: if ajax: return HttpResponse(u'failure') elif 'url' in request.GET: url = request.GET['url'] title = '' tags = '' share = False try: link = Link.objects.get(url=url) bookmark = Bookmark.objects.get( link = link, user = request.user ) title = bookmark.title tags = ' '.join(tag.name for tag in bookmark.tag_set.all ()) share = SharedBookmark.objects.get( bookmark = bookmark ) except (Link.DoesNotExist, Bookmark.DoesNotExist, SharedBookmark.DoesNotExist): pass form = BookmarkSaveForm({ 'url': url, 'title': title, 'tags': tags, 'share': share }) else: form = BookmarkSaveForm() variables = RequestContext(request, {'form': form}) print 'form: ', form if ajax: return render_to_response('bookmark_save_form.html', variables) else: return render_to_response('bookmark_save.html', variables) Thanks for your help Enrico --~--~-~--~~~---~--~~ 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: Will PasswordField be in Django?
On 10 Nov 20:05, Shu Hung (Koala) wrote: > Hello, > > I am new to Django. > I'm writing an app with it. And I found there is no PasswordField in Django. > I Googled a bit. And I found, in patch #61, that someone has wrote it > already. > > Will it be in place soon? > When? Or, what is the matter of it? Well, a password field isn't actually a different type of data than a text field, so you'd usually just override the form's default for the password field, using a modelform to specify that you want it to appear as a password widget. -- Brett Parker --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
Hi Tim, Yes, I syncdb several times. C:\sw\sw>manage.py syncdb C:\sw\sw>manage.py sql wkw BEGIN; CREATE TABLE "wkw_school" ( "id" integer NOT NULL PRIMARY KEY, "school" varchar(200) NOT NULL ) ; CREATE TABLE "wkw_lawyer" ( "id" integer NOT NULL PRIMARY KEY, "school_id" integer NOT NULL REFERENCES "wkw_school" ("id"), "first" varchar(20) NOT NULL, "initial" varchar(2) NOT NULL, "last" varchar(20) NOT NULL, "year_graduated" datetime NOT NULL ) ; COMMIT; C:\sw\sw> On Nov 10, 5:27 am, Tim Chase wrote: > > (I changed "Education" to "School" because in the admin panel it > > showed up as "Educations". I think "Schools" makes more sense.) > > Did you remember to syncdb afterwards? I'd be interested to see > if the SQL you showed is what the tables in the DB actually look > like. > > > Any ideas why Lawyer link in the admin panel does not work? > > It's on retainer? Hahahaha...sorry...a little 4:30am lawyer humor :) > > -tim --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
djangocon videos
will conference videos be available or did something terrible happened? Aljosa Mohorovic --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
On Nov 10, 12:57 pm, Zeynel wrote: > Hi Tim, > > Yes, I syncdb several times. > > C:\sw\sw>manage.py syncdb > > C:\sw\sw>manage.py sql wkw > > BEGIN; > CREATE TABLE "wkw_school" ( > "id" integer NOT NULL PRIMARY KEY, > "school" varchar(200) NOT NULL > ) > ; > CREATE TABLE "wkw_lawyer" ( > "id" integer NOT NULL PRIMARY KEY, > "school_id" integer NOT NULL REFERENCES "wkw_school" ("id"), > "first" varchar(20) NOT NULL, > "initial" varchar(2) NOT NULL, > "last" varchar(20) NOT NULL, > "year_graduated" datetime NOT NULL > ) > ; > COMMIT; > > C:\sw\sw> > > On Nov 10, 5:27 am, Tim Chase wrote: > > > > > > (I changed "Education" to "School" because in the admin panel it > > > showed up as "Educations". I think "Schools" makes more sense.) > > > Did you remember to syncdb afterwards? I'd be interested to see > > if the SQL you showed is what the tables in the DB actually look > > like. > > > > Any ideas why Lawyer link in the admin panel does not work? > > > It's on retainer? Hahahaha...sorry...a little 4:30am lawyer humor :) > > > -tim syncdb does not change existing table definitions. And sql will just show what the sql should be, not what it actually is. If you're not using a migrations system such as South, your best bet is to drop your tables and start again. -- 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-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: Will PasswordField be in Django?
On Tue, Nov 10, 2009 at 8:55 PM, Brett Parker wrote: > > Well, a password field isn't actually a different type of data than a > text field, so you'd usually just override the form's default for the > password field, using a modelform to specify that you want it to appear > as a password widget. > > -- > Brett Parker > A password field is different from text. Usually a password field would store hashed password. How do I specify, with django's model, that a field need to be encryped and hased before store? Koala Yeung --~--~-~--~~~---~--~~ 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: Will PasswordField be in Django?
django comes with an inbuilt form that does the hashing and saving of password. from django.contrib.auth.forms import UserCreationForm Simliarly an inbuilt form that does the login, logout and such. Look at the source in the path above, and/or refer to the documentation of django auth: http://docs.djangoproject.com/en/dev/topics/auth/ Best! On Tue, Nov 10, 2009 at 6:40 PM, Shu Hung (Koala) wrote: > > On Tue, Nov 10, 2009 at 8:55 PM, Brett Parker < > idu...@sommitrealweird.co.uk> wrote: > >> >> Well, a password field isn't actually a different type of data than a >> text field, so you'd usually just override the form's default for the >> password field, using a modelform to specify that you want it to appear >> as a password widget. >> >> -- >> Brett Parker >> > > A password field is different from text. > Usually a password field would store hashed password. > > How do I specify, with django's model, that a field need to be encryped and > hased before store? > > > Koala Yeung > > > > > -- Regards, Lakshman becomingguru.com lakshmanprasad.com --~--~-~--~~~---~--~~ 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: Will PasswordField be in Django?
On 10 Nov 21:10, Shu Hung (Koala) wrote: > On Tue, Nov 10, 2009 at 8:55 PM, Brett Parker > wrote: > > > > > Well, a password field isn't actually a different type of data than a > > text field, so you'd usually just override the form's default for the > > password field, using a modelform to specify that you want it to appear > > as a password widget. > > > > -- > > Brett Parker > > > > A password field is different from text. > Usually a password field would store hashed password. > > How do I specify, with django's model, that a field need to be encryped and > hased before store? You'd use field validation, probably using a clean_password method to hash the password from the form and return the "cleaned" data. Thanks, -- Brett Parker --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
forms.ChoiceField and empty values
Hi, I have the following problem... I've got a form, which looks like this: class CompetitionSearchForm(forms.Form): name = forms.CharField(required=False) type = forms.ChoiceField(choices=COMPETITION_TYPE_CHOICES, required=False) The tuple COMPETITION_TYPE_CHOICES is used in a model class (the purpose of the form is to search through Competition objects). It looks something a bit like this: COMPETITION_TYPE_CHOICES = ( (1, 'Olympic Games'), (2, 'ISU Championships'), (3, 'Grand Prix Series'), ) I'd like the select widget in ChoiceField to display an empty label. According to the documentation (http://docs.djangoproject.com/en/dev/ ref/forms/fields/#choicefield), it seems like this should happen by default, but I don't get an empty value in the select widget at all. Why is this? Monika --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
Ok, thanks. I started over and created a new project sw1 and module wkw1, and now it all works. But now I noticed that, the "initial" field in "Lawyer" is required. But I want it to be optional. Do I need to start over again to make that change :( And also in the "Year Graduated" field I just need the year, so I need to remove, day, month, and time. How do I make these changes? There must be a way without starting over and creating a new project. Thanks. On Nov 10, 8:06 am, Daniel Roseman wrote: > On Nov 10, 12:57 pm, Zeynel wrote: > > > > > > > Hi Tim, > > > Yes, I syncdb several times. > > > C:\sw\sw>manage.py syncdb > > > C:\sw\sw>manage.py sql wkw > > > BEGIN; > > CREATE TABLE "wkw_school" ( > > "id" integer NOT NULL PRIMARY KEY, > > "school" varchar(200) NOT NULL > > ) > > ; > > CREATE TABLE "wkw_lawyer" ( > > "id" integer NOT NULL PRIMARY KEY, > > "school_id" integer NOT NULL REFERENCES "wkw_school" ("id"), > > "first" varchar(20) NOT NULL, > > "initial" varchar(2) NOT NULL, > > "last" varchar(20) NOT NULL, > > "year_graduated" datetime NOT NULL > > ) > > ; > > COMMIT; > > > C:\sw\sw> > > > On Nov 10, 5:27 am, Tim Chase wrote: > > > > > (I changed "Education" to "School" because in the admin panel it > > > > showed up as "Educations". I think "Schools" makes more sense.) > > > > Did you remember to syncdb afterwards? I'd be interested to see > > > if the SQL you showed is what the tables in the DB actually look > > > like. > > > > > Any ideas why Lawyer link in the admin panel does not work? > > > > It's on retainer? Hahahaha...sorry...a little 4:30am lawyer humor :) > > > > -tim > > syncdb does not change existing table definitions. And sql will just > show what the sql should be, not what it actually is. If you're not > using a migrations system such as South, your best bet is to drop your > tables and start again. > -- > 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-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: How to handle this race condition?
another option if you want to stay in just python and are on a POSIX system is to use system file locking to ensure you don't get concurrent calls to your updated function. http://docs.python.org/library/fcntl.html#fcntl.lockf -Preston On Nov 9, 10:17 pm, Continuation wrote: > Thanks Christophe and Kenneth! > > Let me make sure I understand this: > > If I write this vew function: > > @transaction.commit_on_success > def update_high_bid(request): > > cursor = connection.cursor() > cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE > id=%s > FOR UPDATE", [auction.id]) > returned_rows = cursor.fetchall() > high_bid = returned_rows[0][0] > if new_bid > high_bid: > auction.high_bid = new_bid > auction.save() > > The entire function will be wrapped within a transaction. > SELECT FOR UPDATE will acquire a row-level lock > and that lock will not be released until the function update_high_bid > () returns successfully, or until the function raises an exception and > the whole transaction is rolled back. > > Is that right? > > Thanks. > > On Nov 10, 12:45 am, Christophe Pettus wrote: > > > > > On Nov 9, 2009, at 9:34 PM, Continuation wrote: > > > > Also does django middleware acquire database lock on my behalf, or do > > > I need to explicitly perform the locking? > > > In the example code, it's the SELECT ... FOR UPDATE that acquires the > > lock. Django doesn't currently have any explicit knowledge of > > locking, so you need to drop down to the custom SQL level to issue the > > right statement to acquire the lock on the row. > > > The example I wrote assumed you were using PostgreSQL as the backend; > > you can get all sorts of details about locking in PostgreSQL here: > > > > > http://www.postgresql.org/docs/8.4/interactive/explicit-locking.html#... > > -- > > -- Christophe Pettus > > x...@thebuild.com --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
When you execute manage.py sql wkw, the output is just how your current models translate into SQL. To see what's actually in the database you should do manage.py dbshell and then use whatever command your database supports (\d wkw_lawyer in PostgreSQL and DESCRIBE wkw_lawyer in MySQL). Try doing manage.py reset wkw My guess is that the wkw_lawyer table in the database probably has a field called education_id instead of school_id, the reset command should drop and create the wkw_lawyer table again (like my predecessor proposed). More about how syncdb works (and why it wouldn't have changed education_id into school_id) here: http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb And finally, you don't have to change the name of the class when you don't like how the plural of a class name is being rendered. You can specify the plural in the Meta class of the model: http://docs.djangoproject.com/en/dev/topics/db/models/#meta-options http://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name-plural Hope that helps :) On Nov 10, 3:14 am, Zeynel wrote: > Hello, > > These are my tables: > > BEGIN; > CREATE TABLE "wkw_school" ( > "id" integer NOT NULL PRIMARY KEY, > "school" varchar(200) NOT NULL > ) > ; > CREATE TABLE "wkw_lawyer" ( > "id" integer NOT NULL PRIMARY KEY, > "first" varchar(20) NOT NULL, > "initial" varchar(2) NOT NULL, > "last" varchar(20) NOT NULL, > "year_graduated" datetime NOT NULL, > "school_id" integer NOT NULL REFERENCES "wkw_school" ("id") > ) > ; > COMMIT; > > (I changed "Education" to "School" because in the admin panel it > showed up as "Educations". I think "Schools" makes more sense.) > > I created the admin and I registered School and Lawyer. > > In the admin panel School link works fine but when I click on Lawyer > link I get a "TemplateSyntaxError at /admin/wkw/lawyer/ > Caught an exception while rendering: no such column: > wkw_lawyer.school_id" > > But according to the above tables, school_id has been created. > > I tried to add in the shell, > > p = Lawyer(school_id=1) > > but > > p.save() > > throws an error. > > Any ideas why Lawyer link in the admin panel does not work? > > This is the offending line on the debug page: > > 78 {% result_list cl %} > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Display a view of a single record?
Derek, If you want something that display data but doesn't allow you to edit it, you should check out the databrowse[1] contrib app. You just register a model with it (like the admin) and it generates all the pages. It lets users look through the data, but not edit it. [1]http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/ Hope that helps, Alex On Nov 10, 3:36 am, derek wrote: > Yes, the fields should not be editable in a "view". > > However, I do not see it as "a problem" - more as "a desirable > feature". There are any number of use cases for letting users see > detailed record data but not be able (or not need, at that point in > time) to edit it. This feature is not meant to replace the existing > ability to edit a record; but to add another option to the interface. > > It just seems strange to me that the admin interface allows for > display of multiple records in a listing, but has no facility to > display a complete, single record "view". I do not want to have > redevelop an admin-like interface just to allow for this option (given > that is such a generic one). > > It is not clear from what you say - but I assume that it is not > possible to readily alter the current admin interface to incorporate > the generic views you refer to? If it is, any guidance, or examples, > along these lines would be appreciated. > > On Nov 9, 2:37 pm, Ludwik Trammer wrote: > > > I have a really hard time understanding what do you need, and I > > suspect I'm not the only one. You are talking about the admin > > interface, right? It displays a list containing all records, and when > > you click on a record you go to a page that shows all fields for this > > record (and lets you change their values). Isn't that exactly what you > > want? > > > If the problem is that you don't want the fields to be editable, > > because you just want to display read-only lists of records: re-think > > using admin interface. It is meant specifically for managing records > > on your website. Just use > > "django.views.generic.list_detail.object_list" (display list of > > records) and "django.views.generic.list_detail.object_detail" (display > > detailed view of a single record) generic views: > > >http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-.. --~--~-~--~~~---~--~~ 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: Databrowse: Loading a large number of records
That error happens if you refresh the page while it is still loading from the dev server. You may have gotten impatient, refreshed and caused that error. It is possible that this isn't really the problem you are having, but just a secondary issue caused by the long load time and a page refresh. On Nov 9, 6:49 am, Ismail Dhorat wrote: > Hi Guys, > > I am currently testing the contrib app databrowse in Django ver 1.1.1, > the current setup for testing purposes is: > > OS: Mac OsX 10.6 > DB: Sqlite3 > Django: 1.1.1 > Python: 2.5 > > Here is what i have done, i have a model and i am trying to see what > the capabilities and limits of this app (since i will most likely be > working with a huge number of records), i loaded +- 300,000 records > into the DB current SQLITE file size is 30mb > > When trying to access /databrowse i get errors, and the page refuses > to load. It basically hangs, from the looks of it the page seems to be > displaying all the contents. Here is the traceback: > > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", > line 280, in run > self.finish_response() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", > line 320, in finish_response > self.write(data) > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", > line 399, in write > self.send_headers() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", > line 463, in send_headers > self.send_preamble() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", > line 381, in send_preamble > 'Date: %s\r\n' % http_date() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/socket.py", > line 261, in write > self.flush() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/socket.py", > line 248, in flush > self._sock.sendall(buffer) > error: (32, 'Broken pipe') > > I also see there has been a ticket logged for this issue about 2 years ago. > > http://code.djangoproject.com/ticket/4481 > > Has this been implemented? If not would would a simple paginate tag in > the template suffice? > > Regards, > Ismail --~--~-~--~~~---~--~~ 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: TemplateSyntaxError
Thanks. I will try what you suggested. But I am almost there with the admin, the only thing is I need to change the date format so that it takes only the year. Now DateField requires month, day and year. I tried this year_graduated = models.DateField('Year graduated', input_formats= ['%Y']) as in class Lawyer(models.Model): first = models.CharField(max_length=20) initial = models.CharField(blank=True, max_length=2) last = models.CharField(max_length=20) year_graduated = models.DateField('Year graduated', input_formats= ['%Y']) school = models.CharField(max_length=200) school = models.ForeignKey(School) def __unicode__(self): return self.first but it doesn't work. Some googling shows that I may be confusing "form" and "models" http://osdir.com/ml/DjangoUsers/2009-03/msg02593.html In that case how can I fix the DateField so that it takes only the date? Because I only need "Year Graduated" not month or day. Thanks again. On Nov 10, 9:40 am, Monika Sulik wrote: > When you execute manage.py sql wkw, the output is just how your > current models translate into SQL. To see what's actually in the > database you should do manage.py dbshell and then use whatever command > your database supports (\d wkw_lawyer in PostgreSQL and DESCRIBE > wkw_lawyer in MySQL). > > Try doing manage.py reset wkw > My guess is that the wkw_lawyer table in the database probably has a > field called education_id instead of school_id, the reset command > should drop and create the wkw_lawyer table again (like my predecessor > proposed). More about how syncdb works (and why it wouldn't have > changed education_id into school_id) > here:http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb > > And finally, you don't have to change the name of the class when you > don't like how the plural of a class name is being rendered. You can > specify the plural in the Meta class of the > model:http://docs.djangoproject.com/en/dev/topics/db/models/#meta-optionshttp://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name... > > Hope that helps :) > > On Nov 10, 3:14 am, Zeynel wrote: > > > > > Hello, > > > These are my tables: > > > BEGIN; > > CREATE TABLE "wkw_school" ( > > "id" integer NOT NULL PRIMARY KEY, > > "school" varchar(200) NOT NULL > > ) > > ; > > CREATE TABLE "wkw_lawyer" ( > > "id" integer NOT NULL PRIMARY KEY, > > "first" varchar(20) NOT NULL, > > "initial" varchar(2) NOT NULL, > > "last" varchar(20) NOT NULL, > > "year_graduated" datetime NOT NULL, > > "school_id" integer NOT NULL REFERENCES "wkw_school" ("id") > > ) > > ; > > COMMIT; > > > (I changed "Education" to "School" because in the admin panel it > > showed up as "Educations". I think "Schools" makes more sense.) > > > I created the admin and I registered School and Lawyer. > > > In the admin panel School link works fine but when I click on Lawyer > > link I get a "TemplateSyntaxError at /admin/wkw/lawyer/ > > Caught an exception while rendering: no such column: > > wkw_lawyer.school_id" > > > But according to the above tables, school_id has been created. > > > I tried to add in the shell, > > > p = Lawyer(school_id=1) > > > but > > > p.save() > > > throws an error. > > > Any ideas why Lawyer link in the admin panel does not work? > > > This is the offending line on the debug page: > > > 78 {% result_list cl %} > > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how to achieve functionality of asynchronous popups
Hello, I would like to implement functionality described below. Lets say that There is a Django application in which each user can create records and insert them into Database (for example record containing one text column). Many users can be logged in the application at the same time. One users created record which was inserted into the database. Than another user edited it from application and saved. What I want to achieve is sort of popup which will appear on the first user screan informing him that record created by him was changed. The logic described above is just a sample. What I need is to know how to pass some information to logged user and show it in popup or sth similar. For example in Gmail when someone starts chatting to you there is a small popup in the bottom corner. Maybe article or tutorial on the web ? thank very much for 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-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: How to handle this race condition?
On Nov 9, 2009, at 10:17 PM, Continuation wrote: > The entire function will be wrapped within a transaction. > SELECT FOR UPDATE will acquire a row-level lock > and that lock will not be released until the function update_high_bid > () returns successfully, or until the function raises an exception and > the whole transaction is rolled back. Yes, that appears to be correct. -- -- Christophe Pettus x...@thebuild.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model field validation for admin
Hello, I want to make a field optional (blank=True), only if another text field's options match a certain value in the admin. Is there any way to do this? 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: TemplateSyntaxError
On Nov 10, 3:02 pm, Zeynel wrote: > Thanks. I will try what you suggested. But I am almost there with the > admin, the only thing is I need to change the date format so that it > takes only the year. Now DateField requires month, day and year. I > tried this > > year_graduated = models.DateField('Year graduated', input_formats= > ['%Y']) > > as in > > class Lawyer(models.Model): > first = models.CharField(max_length=20) > initial = models.CharField(blank=True, max_length=2) > last = models.CharField(max_length=20) > year_graduated = models.DateField('Year graduated', input_formats= > ['%Y']) > school = models.CharField(max_length=200) > school = models.ForeignKey(School) > def __unicode__(self): > return self.first > > but it doesn't work. Some googling shows that I may be confusing > "form" and "models"http://osdir.com/ml/DjangoUsers/2009-03/msg02593.html > > In that case how can I fix the DateField so that it takes only the > date? Because I only need "Year Graduated" not month or day. > > Thanks again. If it only takes a year, it's not a date field. So just use a string or an integer field, possibly with a list of choices for the range of years you want. -- 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-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: Model field validation for admin
2009/11/10 pixelcowboy : > > Hello, I want to make a field optional (blank=True), only if another > text field's options match a certain value in the admin. Is there any > way to do this? Thanks! > This is from the top of my head, but you probably want to say null=True (i am guessing you'll leave this field empty in some cases) and blank=True on certain model field, then override models save() method to check for some conditions under which you want or do not want to allow the field to be empty. I am not sure how you would rise validation error from save() though. --~--~-~--~~~---~--~~ 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: How to handle this race condition?
On 10 nov, 05:36, Continuation wrote: > I'm working on an auction app. > > In an Auction object I store the current_high_bid for that auction. > > When a new_bid comes in, I: > 1) retrieve the current_high_bid field of the Auction object > 2) compare it with the new_bid > 3) if the new bid is higher than current_high_bid, I update > current_high_bid to the value of the new_bid. > > but there's a (slight) chance that between steps (1) and (3) a > different user could've submitted an even higher bid which then become > the current_high_bid. In that case step 3 should not proceed. What can > I do to make sure such a situation does not arise? Well, the SimplestSolution would be to NOT denormalize your DB. From a relational / SQL POV, you shouldn't store the "current_high_bid" in the 'auction' table, but query the 'bid' table for the currently max bid for this auction. But I guess you have some good reasons to dismiss this solution... --~--~-~--~~~---~--~~ 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: How to handle this race condition?
On Nov 9, 2009, at 10:56 PM, Tamas Szabo wrote: > UPDATE bid = new_bid WHERE id = id and bid < new_bid That's an even better solution, if no further processing within the locked area is required. -- -- Christophe Pettus x...@thebuild.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Puzzling filter/annotation of queryset based on count
Hi all, have been having trouble with figuring out how to construct more complicated filters on query sets, especially when mixing them with annotations. Specifically, I have: An Item, which has one of many ItemTypes A Collection, which contains many Items. What I want to construct is a queryset containing a set of Collections, with a field (annotation) with the Count of items belonging to that collection with a specific ItemType So something along the lines of Collection.objects.annotate (item_count=Count('item')).filter(item__itemtype=1).filter (item_count__gt=0).all() however I can't figure out the correct configuration of annotations and filters to get back what I want! I'm sure this will take a seasoned djangonaut a few seconds to figure out so any help is appreciated! Cheers Ben --~--~-~--~~~---~--~~ 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: how to achieve functionality of asynchronous popups
On Tue, Nov 10, 2009 at 10:03 AM, elminio wrote: > What I want to achieve is sort of popup which will appear on the first > user screan informing him that record created by him was changed. > > The logic described above is just a sample. What I need is to know how > to pass some information to logged user and show it in popup or sth > similar. this is the textbook example for a Comet approach. But for simple notifications it's easy do to with straight AJAX. just add a Django view that returns (possibly as a JSON structure) any notification(s) to a given user, then set a simple JavaScript function to be called every 10sec or so, and check if there's any notification by simply calling that view. i think it would be around 3 lines with jQuery. > For example in Gmail when someone starts chatting to you there is a > small popup in the bottom corner. maybe not the embedded chat, (that is better handled with a full Comet architecture); but the 'more messages available' notification. in this case, the query is not about messages for a user, rather it's more like 'messages about this context', where the context in Gmail case is the displayed thread. -- Javier --~--~-~--~~~---~--~~ 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: How to handle this race condition?
Why store it in the database? You might be able to avoid this directly if you use a model method for this attribute. Continuation wrote: > I'm working on an auction app. > > In an Auction object I store the current_high_bid for that auction. > > When a new_bid comes in, I: > 1) retrieve the current_high_bid field of the Auction object > 2) compare it with the new_bid > 3) if the new bid is higher than current_high_bid, I update > current_high_bid to the value of the new_bid. > > but there's a (slight) chance that between steps (1) and (3) a > different user could've submitted an even higher bid which then become > the current_high_bid. In that case step 3 should not proceed. What can > I do to make sure such a situation does not arise? > > 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: how to achieve functionality of asynchronous popups
Thanks, That is exactly the answer I needed. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
computed values in templates...
Hi, In my db I hve some fields like 'price' and 'quantity'. In one record of data I want to display the 'price x quantity'...I tried something like this: {{ stock.price * stock.quantity }} ...and got error. Is there a recommended way to do this...? --deostroll --~--~-~--~~~---~--~~ 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: computed values in templates...
El Tue, 10 Nov 2009 10:31:13 -0800 (PST) deostroll escribió: > Is there a recommended way to do this...? Yeah: write an instance method in your "Stock" class (model) that returns exactly that and call it from the template. Remember: there shouldn't be any data processing in the presentation layer. -- P.U. Gonzalo Delgado http://gonzalodelgado.com.ar/ pgpVGngMDm9rd.pgp Description: PGP signature
Adding a search box in admin
Hello, Thanks again for all the help. I have the admin page and I added some lawyer names and schools, now I want to add the search box. In the tutorial it says "Let's add some search capability: search_fields = ['question'] ... " Translating this to my model, I entered in admin.py search_fields = ['last'] But this did not work for me. I did not see a search box anywhere. I found these references online: http://www.julienphalip.com/blog/2008/08/16/adding-search-django-site-snap/ http://blog.tkbe.org/archive/django-admin-search-functionality/ http://groups.google.com/group/django-users/browse_thread/thread/59a0fb0f07f1c93f/960f28867e75909d?hl=en&lnk=gst&q=search+box#960f28867e75909d but I am not sure if that's what I need to do. I need one search: I want to pull all lawyers who graduated from same school the same year. Can you give me a clue about how to do this? 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 -~--~~~~--~~--~--~---
name 'request' is not defined
hi i have defined a function in my view.py from django.http import HttpResponse class work(request): def get(self): return HttpResponse("its working") but when i browse to mysite/work i am getting "name 'request' is not defined" any one have any idea what is wrong ? cheers nash --~--~-~--~~~---~--~~ 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: How to handle this race condition?
On Mon, Nov 9, 2009 at 10:56 PM, Tamas Szabo wrote: > Would something like > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > work for you? > > It is a more optimistic approach (it assumes that the case you describe is > an exception rather than what usually happens) and I think it is simpler by > not having to do any locking etc. > > > Regards, > > Tamas > > > That only works if you have transactions disabled for your database. If your connections are using transactions, you still have the race condition. For example (in MySQL): Start two DB Shells In the first shell: mysql> insert into bids (id, high_bid) values (1, 20); Query OK, 1 row affected (0.00 sec) mysql> START TRANSACTION; Query OK, 0 rows affected (0.01 sec) In the second shell: mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> update bids set high_bid = 25 where id = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.00 sec) Back in the first shell: mysql> UPDATE bids SET high_bid = 23 where id = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> select * from bids; +--+--+ | id | high_bid | +--+--+ |1 | 23 | +--+--+ 1 row in set (0.00 sec) Craig > > > > On Tue, Nov 10, 2009 at 2:17 PM, Continuation wrote: > >> >> Thanks Christophe and Kenneth! >> >> Let me make sure I understand this: >> >> If I write this vew function: >> >> @transaction.commit_on_success >> def update_high_bid(request): >> >> cursor = connection.cursor() >>cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE >> id=%s >> FOR UPDATE", [auction.id]) >> returned_rows = cursor.fetchall() >>high_bid = returned_rows[0][0] >>if new_bid > high_bid: >>auction.high_bid = new_bid >>auction.save() >> >> The entire function will be wrapped within a transaction. >> SELECT FOR UPDATE will acquire a row-level lock >> and that lock will not be released until the function update_high_bid >> () returns successfully, or until the function raises an exception and >> the whole transaction is rolled back. >> >> Is that right? >> >> Thanks. >> >> >> On Nov 10, 12:45 am, Christophe Pettus wrote: >> > On Nov 9, 2009, at 9:34 PM, Continuation wrote: >> > >> > > Also does django middleware acquire database lock on my behalf, or do >> > > I need to explicitly perform the locking? >> > >> > In the example code, it's the SELECT ... FOR UPDATE that acquires the >> > lock. Django doesn't currently have any explicit knowledge of >> > locking, so you need to drop down to the custom SQL level to issue the >> > right statement to acquire the lock on the row. >> > >> > The example I wrote assumed you were using PostgreSQL as the backend; >> > you can get all sorts of details about locking in PostgreSQL here: >> > >> > >> http://www.postgresql.org/docs/8.4/interactive/explicit-locking.html#... >> > -- >> > -- Christophe Pettus >> > x...@thebuild.com >> >> > > > > --~--~-~--~~~---~--~~ 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: name 'request' is not defined
On Nov 10, 7:34 pm, nash wrote: > hi i have defined a function in my view.py > > from django.http import HttpResponse > > class work(request): > def get(self): > return HttpResponse("its working") > > but when i browse to mysite/work i am getting "name 'request' is not > defined" any one have any idea what is wrong ? > cheers nash Yes: you need to learn some Python. What you've written is a class that inherits from 'request', with a 'get' method. 'request' is not a parameter here, so it has to exist in the module somewhere. What are you trying to do? -- 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-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: domains vs sub-domains
Am Montag, den 09.11.2009, 21:38 -0800 schrieb Chris: > I've recently been in discussion about which is better to have. > > http://media.example.com OR > http://example.com/media/ > > 1) The first method, I've been told, allows you to make more requests. > IE for example can only make like 4 requests at a given time on a > given domain. but, if you use sub-domains, you can make additional > requests (4 additional in the example of IE). I am not sure, but I think if you use SSL this could lead to problems because some files are loaded from a different server. […] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil
Re: Just upgraded to 1.1, can't start development server, TypeError
Same problem here. Any ideas? Thanks! On Oct 14, 7:11 pm, eculver wrote: > Not so sure about that. Here are my installed apps: > > INSTALLED_APPS = ( > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.admin', > 'myproject.api', > 'myproject.pages', > 'myproject.contact_form', > 'myproject.albums', > 'myproject.paypalcart', > 'myproject.messaging', > ) > > None of them are being pulled from my python path? Am I missing > something obvious? > > On Oct 14, 1:09 am, Lakshman Prasad wrote: > > > Seems like, some of the apps that you have in settings.py INSTALLED_APPS are > > there in the pythonpath for python2.5 and not for python2.6. > > You will need to do a easy_install-2.6 (or a corresponding pip/distribute > > equivalent) package_name > > > On Wed, Oct 14, 2009 at 11:48 AM, eculver wrote: > > > > I just tried upgrade to django 1.1, ran ./manage.py runserver, but was > > > promptly halted due to this exception: > > > > ... > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > > > site-packages/django/utils/translation/trans_real.py", line 180, in > > > _fetch > > > app = import_module(appname) > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > python2.6/site-packages/django/utils/importlib.py", line 35, in > > > import_module > > > __import__(name) > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > python2.6/site-packages/django/contrib/admin/__init__.py", line 1, in > > > > > > from django.contrib.admin.options import ModelAdmin, HORIZONTAL, > > > VERTICAL > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > python2.6/site-packages/django/contrib/admin/options.py", line 5, in > > > > > > from django.contrib.contenttypes.models import ContentType > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > python2.6/site-packages/django/contrib/contenttypes/models.py", line > > > 1, in > > > from django.db import models > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > python2.6/site-packages/django/db/__init__.py", line 57, in > > > 'TIME_ZONE': settings.TIME_ZONE, > > > TypeError: __init__() takes exactly 1 argument (2 given) > > > > Everything worked fine in 1.0.4 before the upgrade. Seems like it may > > > be an obvious upgrade problem/oversight on my part. Any ideas? > > > -- > > Regards, > > Lakshman > > becomingguru.com > > lakshmanprasad.com --~--~-~--~~~---~--~~ 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: Feedback on Django1.1.1
sometimes there is this error after upgrade to 1.1.1: http://groups.google.com/group/django-users/browse_thread/thread/c6a61a3788138745 On Nov 7, 9:29 am, Tomasz Zieliński wrote: > On 7 Lis, 09:03, Good Z wrote: > > > > > Any feedback on 1.1 for production software is appreciated. > > I recently migrated quite big live service from 1.0.2 to 1.1.1 > and I didn't observe even single migration-related problem. > It was probably the smoothestupgradeI had in a few years. > But I remember migrating from 0.9 to 1.0 and that wasn't as smooth > as 1.0->1.1. > > -- > Tomasz Zielińskihttp://pyconsultant.eu --~--~-~--~~~---~--~~ 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: Feedback on Django1.1.1
2009/11/10 Evgeny : > sometimes there is this error after upgrade to 1.1.1: > > http://groups.google.com/group/django-users/browse_thread/thread/c6a61a3788138745 >From the sound of it, this was a configuration problem on your system, and not an issue with Django (any time deleting an older copy of code "fixes" a problem, this is the case). -- "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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Just upgraded to 1.1, can't start development server, TypeError
I think I found a workaround: first completely delete previous django installation, then install 1.1.1 the problem went away for me after this manipulation. On Nov 10, 12:39 pm, Evgeny wrote: > Same problem here. Any ideas? > Thanks! > > On Oct 14, 7:11 pm, eculver wrote: > > > Not so sure about that. Here are my installed apps: > > > INSTALLED_APPS = ( > > 'django.contrib.auth', > > 'django.contrib.contenttypes', > > 'django.contrib.sessions', > > 'django.contrib.sites', > > 'django.contrib.admin', > > 'myproject.api', > > 'myproject.pages', > > 'myproject.contact_form', > > 'myproject.albums', > > 'myproject.paypalcart', > > 'myproject.messaging', > > ) > > > None of them are being pulled from my python path? Am I missing > > something obvious? > > > On Oct 14, 1:09 am, Lakshman Prasad wrote: > > > > Seems like, some of the apps that you have in settings.py INSTALLED_APPS > > > are > > > there in the pythonpath for python2.5 and not for python2.6. > > > You will need to do a easy_install-2.6 (or a corresponding pip/distribute > > > equivalent) package_name > > > > On Wed, Oct 14, 2009 at 11:48 AM, eculver wrote: > > > > > I just tried upgrade to django 1.1, ran ./manage.py runserver, but was > > > > promptly halted due to this exception: > > > > > ... > > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > > > > site-packages/django/utils/translation/trans_real.py", line 180, in > > > > _fetch > > > > app = import_module(appname) > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > > python2.6/site-packages/django/utils/importlib.py", line 35, in > > > > import_module > > > > __import__(name) > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > > python2.6/site-packages/django/contrib/admin/__init__.py", line 1, in > > > > > > > > from django.contrib.admin.options import ModelAdmin, HORIZONTAL, > > > > VERTICAL > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > > python2.6/site-packages/django/contrib/admin/options.py", line 5, in > > > > > > > > from django.contrib.contenttypes.models import ContentType > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > > python2.6/site-packages/django/contrib/contenttypes/models.py", line > > > > 1, in > > > > from django.db import models > > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > > > python2.6/site-packages/django/db/__init__.py", line 57, in > > > > 'TIME_ZONE': settings.TIME_ZONE, > > > > TypeError: __init__() takes exactly 1 argument (2 given) > > > > > Everything worked fine in 1.0.4 before the upgrade. Seems like it may > > > > be an obvious upgrade problem/oversight on my part. Any ideas? > > > > -- > > > Regards, > > > Lakshman > > > becomingguru.com > > > lakshmanprasad.com --~--~-~--~~~---~--~~ 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: name 'request' is not defined
hi thanks for the reply i am trying to get django up and running with googleapp engine as. i understand in django correct me if i am wrong return is a global variable when a url is matched as defined in the url.py it calls the class that is matched in views.py and all the variables are passed in request object. so i am bit confused why i am getting the error. have i miss configured some thing some how ? below is my urls.py if its any help from django.conf.urls.defaults import * from portfolio.models import Project info_dict = { 'queryset': Project.all() } urlpatterns = patterns('', # Example: # (r'^foo/', include('foo.urls')), (r'^work/$', 'portfolio.views.work'), # Uncomment this for admin: # (r'^admin/', include('django.contrib.admin.urls')), ) On Nov 11, 4:07 am, Daniel Roseman wrote: > On Nov 10, 7:34 pm, nash wrote: > > > hi i have defined a function in my view.py > > > from django.http import HttpResponse > > > class work(request): > > def get(self): > > return HttpResponse("its working") > > > but when i browse to mysite/work i am getting "name 'request' is not > > defined" any one have any idea what is wrong ? > > cheers nash > > Yes: you need to learn some Python. What you've written is a class > that inherits from 'request', with a 'get' method. 'request' is not a > parameter here, so it has to exist in the module somewhere. > > What are you trying to do? > -- > 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-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: name 'request' is not defined
On Nov 10, 9:32 pm, nash wrote: > hi thanks for the reply i am trying to get django up and running with > googleapp engine as. i understand in django correct me if i am wrong > return is a global variable when a url is matched as defined in the > url.py it calls the class that is matched in views.py and all the > variables are passed in request object. so i am bit confused why i am > getting the error. have i miss configured some thing some how ? below > is my urls.py if its any help > But where did you get the idea that it should be a class? As I said (probably a bit more harshly than I intended), this is basic Python: when you do 'class work(request)' that doesn't mean a function to which you pass 'request', it means a class that inherits from 'request', which must already be defined in that scope. This is absolutely not what you want. And why define a 'get' method? Just get rid of the class, and do as the documentation says: a simple function that takes the 'request' parameter and returns a response. def work(request): return HttpResponse("it's working") -- 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-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: domains vs sub-domains
>From the user's point of view #2 might be better i'd think that most people naturally "root" path to site name On Nov 10, 12:38 pm, Paul Menzel wrote: > Am Montag, den 09.11.2009, 21:38 -0800 schrieb Chris: > > > I've recently been in discussion about which is better to have. > > >http://media.example.comOR > >http://example.com/media/ > > > 1) The first method, I've been told, allows you to make more requests. > > IE for example can only make like 4 requests at a given time on a > > given domain. but, if you use sub-domains, you can make additional > > requests (4 additional in the example of IE). > > I am not sure, but I think if you use SSL this could lead to problems > because some files are loaded from a different server. > > […] > > 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-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 -~--~~~~--~~--~--~---
Imports, works from directory but not from file
I have a folder called lib on my path and in there I have a folder called openid. If i want to import things from openid i have a problem. For example if I have these 2 import statements: from openid.yadis import xri from openid.association import Association as OIDAssociation yadis is a directory (in openid) and then there is xri.py inside. This works fine. association is a .py file not in a subdirectory, just in lib/openid this produces the following error: Traceback (most recent call last): File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in from openid.association import Association as OIDAssociation ImportError: No module named association I don't see why one would be a problem and not the other, does anyone have any ideas? 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: Imports, works from directory but not from file
Which all of these directories are on your python path, and which of them have __init__.py files? Bill [Hint to answer first question: from pprint import pprint as pp import sys pp(sys.path) ] On Tue, Nov 10, 2009 at 5:12 PM, When ideas fail wrote: > > I have a folder called lib on my path and in there I have a folder > called openid. > > If i want to import things from openid i have a problem. > > For example if I have these 2 import statements: > > from openid.yadis import xri > from openid.association import Association as OIDAssociation > > yadis is a directory (in openid) and then there is xri.py inside. This > works fine. > association is a .py file not in a subdirectory, just in lib/openid > this produces the following error: > > Traceback (most recent call last): > File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in > > from openid.association import Association as OIDAssociation > ImportError: No module named association > > I don't see why one would be a problem and not the other, does anyone > have any ideas? > > 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: djangocon videos
According to there twitter (http://twitter.com/djangocon/status/4680045261) they should be up but who knows when. Vitaly Babiy On Tue, Nov 10, 2009 at 8:01 AM, Aljosa Mohorovic < aljosa.mohoro...@gmail.com> wrote: > > will conference videos be available or did something terrible > happened? > > Aljosa Mohorovic > > > --~--~-~--~~~---~--~~ 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: Imports, works from directory but not from file
I used this in my settings.py to add the open id folder on my path sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid')) and on my path it say: 'C:\\TheAbeonaFile\\Python26\\Lib\\idlelib\\lib\\openid' And both the yadis file and openid file have an init.py On 10 Nov, 22:18, Bill Freeman wrote: > Which all of these directories are on your python path, and which of > them have __init__.py files? > > Bill > > [Hint to answer first question: > > from pprint import pprint as pp > import sys > pp(sys.path) > > ] > > On Tue, Nov 10, 2009 at 5:12 PM, When ideas fail > > wrote: > > > I have a folder called lib on my path and in there I have a folder > > called openid. > > > If i want to import things from openid i have a problem. > > > For example if I have these 2 import statements: > > > from openid.yadis import xri > > from openid.association import Association as OIDAssociation > > > yadis is a directory (in openid) and then there is xri.py inside. This > > works fine. > > association is a .py file not in a subdirectory, just in lib/openid > > this produces the following error: > > > Traceback (most recent call last): > > File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in > > > > from openid.association import Association as OIDAssociation > > ImportError: No module named association > > > I don't see why one would be a problem and not the other, does anyone > > have any ideas? > > > 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: wsgi config
Maybe the backslash is a problem. Here is how my media alias looks like: Alias /media/ "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/django/media/" Order allow,deny Allow from all On Sun, Nov 8, 2009 at 11:37 PM, knight wrote: > > Hi. I have a problem with configuring my django site with mod_wsgi. > My httpd.conf is: > > > LoadModule wsgi_module modules/mod-wsgi.so > WSGIScriptAlias /peergw C:/mxhw/mx30/django.wsgi > > >Order deny,allow >allow from all > > > Alias /media/ "C:\Program Files\Apache Software Foundation > \Apache2.2\htdocs\media" > Alias /peergw/site_media/ "C:\Program Files\Apache Software Foundation > \Apache2.2\htdocs\site_media" > > \Apache2.2\htdocs"> > Order deny,allow > Allow from all > > > > I want my site to run on /peergw since I have many instances on the > server and each one running with the different prefix. > Everything works fine except all the images - I can't see static media > files both in admin and my site. > When I go to "/site_media//image" and not "/peergw/site_media// > image", I do see the image. > What am I doing wrong? > By the way, I'm running on Vista, but I have the same problem on XP. > > Thanks, Arshavski Alexander. > > > > > > --~--~-~--~~~---~--~~ 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: MySQL and 'NoneType object is unsubscriptable' error
On Nov 10, 9:12 pm, Daniel Roseman wrote: > On Nov 10, 1:36 am, Julien Phalip wrote: > > > > > Hi, > > > I've tried to install MySQL for an existing project, and I'm getting a > > strange error (see traceback below). Apparently "self.converter" is > > None, but I can't see why. > > > I can access the database just fine using the 'mysql' command in the > > terminal or using PhpMyAdmin. > > > Do you know how this could be fixed? > > > Thanks a lot for you help. > > > Julien > > > Traceback (most recent call last): > > File "/Users/julien/Documents/Development/eclipse/workspace/ > > myproject/trunk/site/manage.py", line 13, in > > execute_manager(settings) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/__init__.py", line 439, in execute_manager > > utility.execute() > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/__init__.py", line 380, in execute > > self.fetch_command(subcommand).run_from_argv(self.argv) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/base.py", line 195, in run_from_argv > > self.execute(*args, **options.__dict__) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/base.py", line 222, in execute > > output = self.handle(*args, **options) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/commands/runserver.py", line 84, in handle > > inner_run() > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/commands/runserver.py", line 48, in inner_run > > self.validate(display_num_errors=True) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/base.py", line 249, in validate > > num_errors = get_validation_errors(s, app) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/core/management/validation.py", line 67, in > > get_validation_errors > > connection.validation.validate_field(e, opts, f) > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/db/backends/mysql/validation.py", line 15, in validate_field > > db_version = connection.get_server_version() > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/db/backends/mysql/base.py", line 297, in get_server_version > > self.cursor() > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/db/backends/__init__.py", line 81, in cursor > > cursor = self._cursor() > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > django/db/backends/mysql/base.py", line 281, in _cursor > > self.connection = Database.connect(**kwargs) > > File "/opt/local/lib/python2.5/site-packages/MySQLdb/__init__.py", > > line 81, in Connect > > return Connection(*args, **kwargs) > > File "/opt/local/lib/python2.5/site-packages/MySQLdb/ > > connections.py", line 222, in __init__ > > self.converter[FIELD_TYPE.STRING].append((None, string_decoder)) > > TypeError: 'NoneType' object is unsubscriptable > > Looks like a problem with your database connection settings. Can you > post the relevant bits from settings.py? > -- > DR. Hi Daniel, Thanks for your reply. The settings seem to be fine I think: DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. DATABASE_NAME = 'testdb' # Or path to database file if using sqlite3. DATABASE_USER = 'root' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. I've never come across that error before. And this code used to work when I run it some months ago... I'm really at a loss here. Thanks, Julien --~--~-~--~~~---~--~~ 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: MySQL and 'NoneType object is unsubscriptable' error
On Nov 11, 9:37 am, Julien Phalip wrote: > On Nov 10, 9:12 pm, Daniel Roseman wrote: > > > > > On Nov 10, 1:36 am, Julien Phalip wrote: > > > > Hi, > > > > I've tried to install MySQL for an existing project, and I'm getting a > > > strange error (see traceback below). Apparently "self.converter" is > > > None, but I can't see why. > > > > I can access the database just fine using the 'mysql' command in the > > > terminal or using PhpMyAdmin. > > > > Do you know how this could be fixed? > > > > Thanks a lot for you help. > > > > Julien > > > > Traceback (most recent call last): > > > File "/Users/julien/Documents/Development/eclipse/workspace/ > > > myproject/trunk/site/manage.py", line 13, in > > > execute_manager(settings) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/__init__.py", line 439, in execute_manager > > > utility.execute() > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/__init__.py", line 380, in execute > > > self.fetch_command(subcommand).run_from_argv(self.argv) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/base.py", line 195, in run_from_argv > > > self.execute(*args, **options.__dict__) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/base.py", line 222, in execute > > > output = self.handle(*args, **options) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/commands/runserver.py", line 84, in handle > > > inner_run() > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/commands/runserver.py", line 48, in inner_run > > > self.validate(display_num_errors=True) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/base.py", line 249, in validate > > > num_errors = get_validation_errors(s, app) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/core/management/validation.py", line 67, in > > > get_validation_errors > > > connection.validation.validate_field(e, opts, f) > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/db/backends/mysql/validation.py", line 15, in validate_field > > > db_version = connection.get_server_version() > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/db/backends/mysql/base.py", line 297, in get_server_version > > > self.cursor() > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/db/backends/__init__.py", line 81, in cursor > > > cursor = self._cursor() > > > File "/Users/julien/Documents/Development/eclipse/workspace/django/ > > > django/db/backends/mysql/base.py", line 281, in _cursor > > > self.connection = Database.connect(**kwargs) > > > File "/opt/local/lib/python2.5/site-packages/MySQLdb/__init__.py", > > > line 81, in Connect > > > return Connection(*args, **kwargs) > > > File "/opt/local/lib/python2.5/site-packages/MySQLdb/ > > > connections.py", line 222, in __init__ > > > self.converter[FIELD_TYPE.STRING].append((None, string_decoder)) > > > TypeError: 'NoneType' object is unsubscriptable > > > Looks like a problem with your database connection settings. Can you > > post the relevant bits from settings.py? > > -- > > DR. > > Hi Daniel, > > Thanks for your reply. The settings seem to be fine I think: > > DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' > or 'ado_mssql'. > DATABASE_NAME = 'testdb' # Or path to database file if > using sqlite3. > DATABASE_USER = 'root' # Not used with sqlite3. > DATABASE_PASSWORD = '' # Not used with sqlite3. > DATABASE_HOST = '' # Set to empty string for localhost. > Not used with sqlite3. > DATABASE_PORT = '' # Set to empty string for default. Not > used with sqlite3. > > I've never come across that error before. And this code used to work > when I run it some months ago... I'm really at a loss here. > > Thanks, > > Julien Hi again, I thought I'd post some more info on my problem. It definitely connects to the database host. If the database doesn't exist, then Django complains it can't find it. But if I create that database, whether it's empty or contains all the tables, Django gives that 'unsubscriptable' error when I try to run the dev server. Julien --~--~-~--~~~---~--~~ 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=e
Re: Model field validation for admin
Ok, I'll try that.Thanks! On Nov 10, 10:19 am, rebus_ wrote: > 2009/11/10 pixelcowboy : > > > > > Hello, I want to make a field optional (blank=True), only if another > > text field's options match a certain value in the admin. Is there any > > way to do this? Thanks! > > This is from the top of my head, but you probably want to say > null=True (i am guessing you'll leave this field empty in some cases) > and blank=True on certain model field, then override models save() > method to check for some conditions under which you want or do not > want to allow the field to be empty. > > I am not sure how you would rise validation error from save() though. --~--~-~--~~~---~--~~ 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: How to handle this race condition?
On Nov 10, 2009, at 11:55 AM, Craig Kimerer wrote: > That only works if you have transactions disabled for your > database. If your connections are using transactions, you still > have the race condition. The example you give isn't exactly the same as the suggestion. In the suggestion, it includes a comparison of the bid amount in the WHERE clause: UPDATE bid = new_bid WHERE id = id and bid < new_bid; That's what makes it work. Lacking that, you're absolutely right, the race condition remains. --~--~-~--~~~---~--~~ 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: How to handle this race condition?
You missed the 'where bid < new_bid' part of the update. In that case there is no race I am aware of. Either the transaction sees the update of the other transaction in which case the highest bid will stay in effect or it will not see the effect of the other transaction in which case there is concurrent update and the transaction is aborted. Anyways, as concurrency is hard and taking row level locks is cheap and easy way to get the concurrency right I would suggest you use the select for update method. Also, this way you will avoid the need to retry failed transactions because of concurrent updates. On Nov 10, 9:55 pm, Craig Kimerer wrote: > On Mon, Nov 9, 2009 at 10:56 PM, Tamas Szabo wrote: > > Would something like > > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > > work for you? > > > It is a more optimistic approach (it assumes that the case you describe is > > an exception rather than what usually happens) and I think it is simpler by > > not having to do any locking etc. > > > Regards, > > > Tamas > > That only works if you have transactions disabled for your database. If > your connections are using transactions, you still have the race condition. > > For example (in MySQL): > Start two DB Shells > > In the first shell: > > mysql> insert into bids (id, high_bid) values (1, 20); > Query OK, 1 row affected (0.00 sec) > > mysql> START TRANSACTION; > Query OK, 0 rows affected (0.01 sec) > > In the second shell: > > mysql> START TRANSACTION; > Query OK, 0 rows affected (0.00 sec) > > mysql> update bids set high_bid = 25 where id = 1; > Query OK, 1 row affected (0.00 sec) > Rows matched: 1 Changed: 1 Warnings: 0 > > mysql> commit; > Query OK, 0 rows affected (0.00 sec) > > Back in the first shell: > > mysql> UPDATE bids SET high_bid = 23 where id = 1; > Query OK, 1 row affected (0.00 sec) > Rows matched: 1 Changed: 1 Warnings: 0 > > mysql> commit; > Query OK, 0 rows affected (0.00 sec) > > mysql> select * from bids; > +--+--+ > | id | high_bid | > +--+--+ > | 1 | 23 | > +--+--+ > 1 row in set (0.00 sec) > > Craig > > > > > On Tue, Nov 10, 2009 at 2:17 PM, Continuation > > wrote: > > >> Thanks Christophe and Kenneth! > > >> Let me make sure I understand this: > > >> If I write this vew function: > > >> @transaction.commit_on_success > >> def update_high_bid(request): > >> > >> cursor = connection.cursor() > >> cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE > >> id=%s > >> FOR UPDATE", [auction.id]) > >> returned_rows = cursor.fetchall() > >> high_bid = returned_rows[0][0] > >> if new_bid > high_bid: > >> auction.high_bid = new_bid > >> auction.save() > > >> The entire function will be wrapped within a transaction. > >> SELECT FOR UPDATE will acquire a row-level lock > >> and that lock will not be released until the function update_high_bid > >> () returns successfully, or until the function raises an exception and > >> the whole transaction is rolled back. > > >> Is that right? > > >> Thanks. > > >> On Nov 10, 12:45 am, Christophe Pettus wrote: > >> > On Nov 9, 2009, at 9:34 PM, Continuation wrote: > > >> > > Also does django middleware acquire database lock on my behalf, or do > >> > > I need to explicitly perform the locking? > > >> > In the example code, it's the SELECT ... FOR UPDATE that acquires the > >> > lock. Django doesn't currently have any explicit knowledge of > >> > locking, so you need to drop down to the custom SQL level to issue the > >> > right statement to acquire the lock on the row. > > >> > The example I wrote assumed you were using PostgreSQL as the backend; > >> > you can get all sorts of details about locking in PostgreSQL here: > > >>http://www.postgresql.org/docs/8.4/interactive/explicit-locking.html#... > >> > -- > >> > -- Christophe Pettus > >> > x...@thebuild.com > > --~--~-~--~~~---~--~~ 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: Model field validation for admin
> > > Hello, I want to make a field optional (blank=True), only if another > > > text field's options match a certain value in the admin. Is there any > > > way to do this? Thanks! You want to do this in a modelform, and then specify that model form in your admin.py. Put the checks in the overall form clean method (as it refers to more than one field). In your model allow blank/null. Peter --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Happy 5th Brithday Firefox
hmmm it seems we forgot to greet and thank Firefox for it's 5th year of existence! http://www.spreadfirefox.com/5years/en-US/ http://zi.pe/eft --~--~-~--~~~---~--~~ 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: Imports, works from directory but not from file
Did you really mean "init.py", rather than the required "__init__.py". If so, that's wrong. I presume that the names of the files and directories are all lower case and contain no spaces or accented characters. I presume that you've checked and rechecked the spelling of the file name against the spelling in the import statement. It is just possible that it's a permission problem. Can you open the files for reading? In the manage.py shell try (and assuming FILE_ROOT is the current directory): open('lib/openid/association.py').readline() If that doesn't give an exception, but just prints the first line of the file, good. If there's an association.pyc remove it and try again (write permission problem to replace file with compiled python for the version of the interpreter in use, though I think it would work fine anyway). I'd expect a different exception, but maybe a problem in association.py is preventing it from importing. Try adding: import pdb;pdb.set_trace() to the top of association.py and see if it gets there and stops, then step along ("n" command) to see that it all completes. Check that the file doesn't have Apple line endings ('\r' only). I know that both DOS and *nix line endings work on Windows ('\r\n' and '\n' respectively). There could be problems if the file is in a unicode variant as opposed to simple 7 bit ASCII, though I hope not. That would probably be clear from the open test above. Check that the __init__.py files are either empty, or have valid python contents. Beyond that, I'm out of ideas. Good luck. Bill On Tue, Nov 10, 2009 at 5:24 PM, When ideas fail wrote: > > I used this in my settings.py to add the open id folder on my path > sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid')) > > and on my path it say: > 'C:\\TheAbeonaFile\\Python26\\Lib\\idlelib\\lib\\openid' > > And both the yadis file and openid file have an init.py > > On 10 Nov, 22:18, Bill Freeman wrote: >> Which all of these directories are on your python path, and which of >> them have __init__.py files? >> >> Bill >> >> [Hint to answer first question: >> >> from pprint import pprint as pp >> import sys >> pp(sys.path) >> >> ] >> >> On Tue, Nov 10, 2009 at 5:12 PM, When ideas fail >> >> wrote: >> >> > I have a folder called lib on my path and in there I have a folder >> > called openid. >> >> > If i want to import things from openid i have a problem. >> >> > For example if I have these 2 import statements: >> >> > from openid.yadis import xri >> > from openid.association import Association as OIDAssociation >> >> > yadis is a directory (in openid) and then there is xri.py inside. This >> > works fine. >> > association is a .py file not in a subdirectory, just in lib/openid >> > this produces the following error: >> >> > Traceback (most recent call last): >> > File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in >> > >> > from openid.association import Association as OIDAssociation >> > ImportError: No module named association >> >> > I don't see why one would be a problem and not the other, does anyone >> > have any ideas? >> >> > 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 -~--~~~~--~~--~--~---
Happy 5th Brithday Firefox
hmmm it seems we forgot to greet and thank Firefox for it's 5th year of existence! http://www.spreadfirefox.com/5years/en-US/ http://zi.pe/eft --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
datetime problems with Django application
I have a Django application running with mod_python on Apache. In settings.py I have set TIME_ZONE="America/New_York". Within my application I verify that os.environ['TZ'] is indeed set to this value. Within my view.py I use datetime.datetime.now() to create a time stamp that is stored in a model as a DateTimeField and viewed on a rendered html page. However, the times that I generate in my view are all off from what they should be by five hours. I've changed the time zone around "America/Chicago", "America/Anchorage" etc. no matter what I set TIME_ZONE to, I get the same wrong time (5 hours off). If I go to the admin page and use the change entry page to modify the values stored in the database, the Time now link gives the correct time? Any idea on what is going on here? I'm particularly perplexed as to why the admin page and my view are giving different times. Brian --~--~-~--~~~---~--~~ 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: How to handle this race condition?
Ah, you're absolutely right. I am not sure how I didn't even catch the other thing that should have grabbed my attention this morning, which was that the table I was using was MyISAM. This is why I shouldn't send emails before noon :) Sorry about that, that was my mistake. Craig On Tue, Nov 10, 2009 at 3:28 PM, akaariai wrote: > > You missed the 'where bid < new_bid' part of the update. In that case > there is no race I am aware of. Either the transaction sees the update > of the other transaction in which case the highest bid will stay in > effect or it will not see the effect of the other transaction in which > case there is concurrent update and the transaction is aborted. > > Anyways, as concurrency is hard and taking row level locks is cheap > and easy way to get the concurrency right I would suggest you use the > select for update method. Also, this way you will avoid the need to > retry failed transactions because of concurrent updates. > > On Nov 10, 9:55 pm, Craig Kimerer wrote: > > On Mon, Nov 9, 2009 at 10:56 PM, Tamas Szabo wrote: > > > Would something like > > > > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > > > > work for you? > > > > > It is a more optimistic approach (it assumes that the case you describe > is > > > an exception rather than what usually happens) and I think it is > simpler by > > > not having to do any locking etc. > > > > > Regards, > > > > > Tamas > > > > That only works if you have transactions disabled for your database. If > > your connections are using transactions, you still have the race > condition. > > > > For example (in MySQL): > > Start two DB Shells > > > > In the first shell: > > > > mysql> insert into bids (id, high_bid) values (1, 20); > > Query OK, 1 row affected (0.00 sec) > > > > mysql> START TRANSACTION; > > Query OK, 0 rows affected (0.01 sec) > > > > In the second shell: > > > > mysql> START TRANSACTION; > > Query OK, 0 rows affected (0.00 sec) > > > > mysql> update bids set high_bid = 25 where id = 1; > > Query OK, 1 row affected (0.00 sec) > > Rows matched: 1 Changed: 1 Warnings: 0 > > > > mysql> commit; > > Query OK, 0 rows affected (0.00 sec) > > > > Back in the first shell: > > > > mysql> UPDATE bids SET high_bid = 23 where id = 1; > > Query OK, 1 row affected (0.00 sec) > > Rows matched: 1 Changed: 1 Warnings: 0 > > > > mysql> commit; > > Query OK, 0 rows affected (0.00 sec) > > > > mysql> select * from bids; > > +--+--+ > > | id | high_bid | > > +--+--+ > > |1 | 23 | > > +--+--+ > > 1 row in set (0.00 sec) > > > > Craig > > > > > > > > > On Tue, Nov 10, 2009 at 2:17 PM, Continuation >wrote: > > > > >> Thanks Christophe and Kenneth! > > > > >> Let me make sure I understand this: > > > > >> If I write this vew function: > > > > >> @transaction.commit_on_success > > >> def update_high_bid(request): > > >> > > >> cursor = connection.cursor() > > >>cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE > > >> id=%s > > >> FOR UPDATE", [auction.id]) > > >> returned_rows = cursor.fetchall() > > >>high_bid = returned_rows[0][0] > > >>if new_bid > high_bid: > > >>auction.high_bid = new_bid > > >>auction.save() > > > > >> The entire function will be wrapped within a transaction. > > >> SELECT FOR UPDATE will acquire a row-level lock > > >> and that lock will not be released until the function update_high_bid > > >> () returns successfully, or until the function raises an exception and > > >> the whole transaction is rolled back. > > > > >> Is that right? > > > > >> Thanks. > > > > >> On Nov 10, 12:45 am, Christophe Pettus wrote: > > >> > On Nov 9, 2009, at 9:34 PM, Continuation wrote: > > > > >> > > Also does django middleware acquire database lock on my behalf, or > do > > >> > > I need to explicitly perform the locking? > > > > >> > In the example code, it's the SELECT ... FOR UPDATE that acquires > the > > >> > lock. Django doesn't currently have any explicit knowledge of > > >> > locking, so you need to drop down to the custom SQL level to issue > the > > >> > right statement to acquire the lock on the row. > > > > >> > The example I wrote assumed you were using PostgreSQL as the > backend; > > >> > you can get all sorts of details about locking in PostgreSQL here: > > > > >>http://www.postgresql.org/docs/8.4/interactive/explicit-locking.html#. > .. > > >> > -- > > >> > -- Christophe Pettus > > >> > x...@thebuild.com > > > > > > > --~--~-~--~~~---~--~~ 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: A simple database project
Hi Tomasz, I was able to build the admin page and put a search box there: class LawyerAdmin(admin.ModelAdmin): fieldsets = [ ('Name', {'fields': ['last', 'first', 'initial']}), ('School', {'fields': ['school', 'year_graduated']}), ] list_display = ('first', 'initial', 'last', 'school', 'year_graduated') list_filter = ['year_graduated'] search_fields = ['last', 'first'] This search box searches only first and last names. But what i want is a search box that finds all lawyers who went to same school. My database now contains: Tom T. Lawyer3 Columbia School of Law 2003 Bob Lawyer2 NYU 2000 JohnI Lawyer1 NYU 2000 So Lawyer1 and Lawyer2 graduated from NYU in 2000. So I want to enter in the search box "Lawyer1" and in the result page I want to see "Lawyer1 knows Lawyer2" How do I do this? Thank you so much. On Nov 7, 12:23 pm, Tomasz Zieliński wrote: > On 7 Lis, 15:58, Zeynel wrote: > > > Hello, > > > I am planning to build a demo prototype for a who-knows-who database > > for the legal profession. Database will consist of lawyer name, school > > and year graduated. Searching by lawyer name will return other lawyers > > graduated from same law school the same year. Can I build this in > > Django? How long would it take me to learn enough Django to build this > > myself? > > Of course you can build this in Django, I think that going through > tutorial: > > http://docs.djangoproject.com/en/dev/intro/tutorial01/ > > is enough to build it in no longer that a few days (learning > included), > even for pre-intermediate programmer. > > -- > Tomasz Zielińskihttp://pyconsultant.eu --~--~-~--~~~---~--~~ 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: A simple database project
On Wednesday 11 Nov 2009 5:51:00 am Zeynel wrote: > So I want to enter in the search box "Lawyer1" and in the result page > I want to see "Lawyer1 knows Lawyer2" > if your school is a foreign key (I think it is) you need a related name to search for that. Check out ModelAdmin.search_fields in the docs. Not sure that this is what you are looking for though. -- regards Kenneth Gonsalves Senior Project Officer NRC-FOSS http://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ 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: datetime problems with Django application
On Nov 11, 10:41 am, BEC wrote: > I have a Django application running with mod_python on Apache. In > settings.py I have set TIME_ZONE="America/New_York". Within my > application I verify that os.environ['TZ'] is indeed set to this > value. Within my view.py I use datetime.datetime.now() to create a > time stamp that is stored in a model as a DateTimeField and viewed on > a rendered html page. > > However, the times that I generate in my view are all off from what > they should be by five hours. I've changed the time zone around > "America/Chicago", "America/Anchorage" etc. no matter what I set > TIME_ZONE to, I get the same wrong time (5 hours off). > > If I go to the admin page and use the change entry page to modify the > values stored in the database, the Time now link gives the correct > time? > > Any idea on what is going on here? I'm particularly perplexed as to > why the admin page and my view are giving different times. Do you run other Python or PHP applications in the same Apache? If you do they likely have conflicting time zone requires. The problem here is that TZ is a process wide setting and can only be set to one value at a time. Thus, whatever application got to set it last will take precedence. See: http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_Locale_Settings Use mod_wsgi daemon mode or fastcgi solutions, both of which can run applications in their own processes if you are being afflicted with this problem. Graham --~--~-~--~~~---~--~~ 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: datetime problems with Django application
There may be another application setting the time zone, but my question still remains as to why the admin page is getting the correct time but the view is not. Brian On Tue, Nov 10, 2009 at 7:45 PM, Graham Dumpleton < graham.dumple...@gmail.com> wrote: > > > > On Nov 11, 10:41 am, BEC wrote: > > I have a Django application running with mod_python on Apache. In > > settings.py I have set TIME_ZONE="America/New_York". Within my > > application I verify that os.environ['TZ'] is indeed set to this > > value. Within my view.py I use datetime.datetime.now() to create a > > time stamp that is stored in a model as a DateTimeField and viewed on > > a rendered html page. > > > > However, the times that I generate in my view are all off from what > > they should be by five hours. I've changed the time zone around > > "America/Chicago", "America/Anchorage" etc. no matter what I set > > TIME_ZONE to, I get the same wrong time (5 hours off). > > > > If I go to the admin page and use the change entry page to modify the > > values stored in the database, the Time now link gives the correct > > time? > > > > Any idea on what is going on here? I'm particularly perplexed as to > > why the admin page and my view are giving different times. > > Do you run other Python or PHP applications in the same Apache? If you > do they likely have conflicting time zone requires. > > The problem here is that TZ is a process wide setting and can only be > set to one value at a time. Thus, whatever application got to set it > last will take precedence. > > See: > > > http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_Locale_Settings > > Use mod_wsgi daemon mode or fastcgi solutions, both of which can run > applications in their own processes if you are being afflicted with > this problem. > > Graham > > > --~--~-~--~~~---~--~~ 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: How to handle this race condition?
> > Anyways, as concurrency is hard and taking row level locks is cheap > and easy way to get the concurrency right I would suggest you use the > select for update method. Also, this way you will avoid the need to > retry failed transactions because of concurrent updates. > > IMHO, both approaches are valid and have their own advantages and disadvantages. I don't think that we have enough information to make a suggestion. What works best for the situation is for the OP to decide. Regards, Tamas --~--~-~--~~~---~--~~ 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: How to handle this race condition?
> Would something like > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > work for you? This is a great idea. One question is, how do I know whether bid has been updated to new_bid or not (ie. how to tell whether the conditional test bid < new_bid is true or not)? --~--~-~--~~~---~--~~ 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: How to handle this race condition?
You can inspect the rowcount attribute of the cursor object after you executed your update. rowcount returns the number of rows affected by your update, so it will be 1 if your where condition was true. On Wed, Nov 11, 2009 at 10:04 AM, Continuation wrote: > > > > Would something like > > > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > > > work for you? > > This is a great idea. > > One question is, how do I know whether bid has been updated to new_bid > or not (ie. how to tell whether the conditional test bid < new_bid is > true or not)? > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
tiny_mce TypeError
Hello, I'm just following "Practical Django Projects" and was curious if anyone else was able to fix a TypeError when trying to add tiny_mce to the admin for flatpages, or is this something buried in the tiny_mce.js file? (r'^tiny_mce/(?P.*)$', 'django.views.static.serve', { 'dcument_root': '/Users/username/src/tinymce/jscripts/tiny_mce' }), tinyMCE.init({ mode: "textareas", theme: "simple" }); Thanks, J --~--~-~--~~~---~--~~ 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: tiny_mce TypeError
On Tue, Nov 10, 2009 at 9:47 PM, neridaj wrote: > I'm just following "Practical Django Projects" and was curious if > anyone else was able to fix a TypeError when trying to add tiny_mce to > the admin for flatpages, or is this something buried in the > tiny_mce.js file? Compare to this, which is the canonical version (and which worked locally for me on 1.1 when I committed it): http://bitbucket.org/ubernostrum/practical-django-projects/src/tip/cms/templates/admin/flatpages/flatpage/change_form.html -- "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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to handle this race condition?
Thank you. On Nov 10, 10:03 pm, Tamas Szabo wrote: > You can inspect the rowcount attribute of the cursor object after you > executed your update. > rowcount returns the number of rows affected by your update, so it will be 1 > if your where condition was true. > > On Wed, Nov 11, 2009 at 10:04 AM, Continuation wrote: > > > > > > Would something like > > > > UPDATE bid = new_bid WHERE id = id and bid < new_bid > > > > work for you? > > > This is a great idea. > > > One question is, how do I know whether bid has been updated to new_bid > > or not (ie. how to tell whether the conditional test bid < new_bid is > > true or not)? --~--~-~--~~~---~--~~ 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: tiny_mce TypeError
I'm using 1.2 pre-alpha, I tried pasting that code in, again, but no dice. On Nov 10, 8:06 pm, James Bennett wrote: > On Tue, Nov 10, 2009 at 9:47 PM, neridaj wrote: > > I'm just following "Practical Django Projects" and was curious if > > anyone else was able to fix a TypeError when trying to add tiny_mce to > > the admin for flatpages, or is this something buried in the > > tiny_mce.js file? > > Compare to this, which is the canonical version (and which worked > locally for me on 1.1 when I committed it): > > http://bitbucket.org/ubernostrum/practical-django-projects/src/tip/cm... > > -- > "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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
request.POST['value'] cannot get value, 500 error
I am posting data from a form to a django view. The form is created using inputEx (a YUI-like interface). The form gets created much like you create a YUI form and you include names for all your fields in javascript. It is javascript that creates the form on the page. I am able to load database data from the django view into my form fields (sending json string to UI), but when I post I cannot access individual posted values, even though I can see that the 'request.POST' is getting posted to the django view. The request.POST looks something like When trying to access a value by using... def MemberInfo(request, member_id): if request.method == "POST": print request.POST try: print request.POST['LastName'] #ERROR ... error message is: "POST /MemberInfo/1 HTTP/1.1" 500 54476 any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Template not displaying
Hi all, am using xampp as webserver with django 1.1,when i access the browser the template does not work. The media is in c:/xampp/htdocs/adc/media/ where i put the css,img and js folders. I set admin_media_prefix='http:/127.0.0.1/adc/media/' the same to media_url. The template is at c:/xampp/htdocs/adc/templates/. Please any idea on how to make the templates working? -- Sent from my mobile device --~--~-~--~~~---~--~~ 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: request.POST['value'] cannot get value, 500 error
Does request.POST['value'][0]['LastName'] work? It looks like your post data has an array (keyed as 'value') of dicts. You might also consider using Firebug (or something similar) to inspect the http requests and responses when you are developing. Regards, Tamas On Wed, Nov 11, 2009 at 2:38 PM, robinne wrote: > > I am posting data from a form to a django view. The form is created > using inputEx (a YUI-like interface). The form gets created much like > you create a YUI form and you include names for all your fields in > javascript. It is javascript that creates the form on the page. > > I am able to load database data from the django view into my form > fields (sending json string to UI), but when I post I cannot access > individual posted values, even though I can see that the > 'request.POST' is getting posted to the django view. The request.POST > looks something like [u'{"FirstName":"Mary","LastName":"Smith"...etc]}> > > When trying to access a value by using... > > def MemberInfo(request, member_id): >if request.method == "POST": >print request.POST >try: >print request.POST['LastName'] #ERROR > > ... > error message is: > "POST /MemberInfo/1 HTTP/1.1" 500 54476 > > any ideas? > > > > > --~--~-~--~~~---~--~~ 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: annotation with filter issue (left join needed)
It seems that you're right :( raw SQL takes away most of benefits of ORM 2009/11/10 akaariai > > > > On Nov 10, 8:29 am, Михаил Лукин wrote: > > Well, I didn't find solution yet. Except that filter condition must be > > placed in LEFT OUTER JOIN ... ON ( ), but i'm not sure if it's > > possible with Django ORM. I notices that Aggregate base class takes > 'extra' > > argument in its constructor, but I'm not sure how to use it for such > > purpose. > > Django can not handle left joins where the filter conditions need to > be in the ON clause of the join. The comment for function join in > django.db.models.sql clearly states this. > > So if you really need to place the filter condition on the left outer > join, then there is nothing you can do except use raw SQL. > > > > -- regards, Mihail --~--~-~--~~~---~--~~ 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: Uploading and using images in a database application
Bruno All the help is much appreciated - its working now, and I need to spend time to understand all the changes. On Nov 5, 5:53 pm, bruno desthuilliers wrote: > On 3 nov, 16:02, derek wrote: > > > Given that I am a "wet behind the ears" newbie, maybe I should not be > > attempting this, but... > > Attempts at thing we don't yet fully grasp can be a good way to > learn. > > > I need some simple and straightforward guidance on > > uploading and using images in a simple database application, which (so far) > > only uses the admin interface. > > > I working on my development machine (i.e. no Apache integration as yet). > > > The use case is not that complex. If I have an "Event" object, with which I > > want to associate a number of images (typically, photos taken by people at > > that event), then I also need an "EventImage" object, with the event.id as > > the foreign key. > > > So, the models look like: > > > class Event(models.Model): > > id = models.AutoField(primary_key=True) > > Hint : if you leave this previous line out, Django will automagically > add this very same field to your model !-) > > > > > date_time = models.DateTimeField() > > title = models.CharField(unique=True,max_length=250) > > > class EventImage(models.Model): > > id = models.AutoField(primary_key=True) > > caption = models.CharField(unique=True,max_length=10) > > title = models.CharField(max_length=250) > > event = models.ForeignKey(Event) > > image = models.ImageField(upload_to='photos') > > > What I have gathered so far, from browsing articles and snippets and Q&A, is > > that I also need: > > > 1.to add/change settings.py: > > > MEDIA_ROOT = '/home/blah/blah/mysite/media/' > > MEDIA_URL = 'http://127.0.0.1:8000/media/' > > ADMIN_MEDIA_PREFIX = '/media/' > > Using the same path component for both the static medias and the admin > media usually leads to unexpected results. Either change your static > medias component path to something else or - way simplier -, change > the ADMIN_MEDIA_PREFIX (here we canonically set it to 'admin-media'). > > > STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/' > > > 2. add the following to the start of urls.py: > > > from django.conf import settings > > > 3. add the following to the end of urls.py: > > > if settings.DEBUG: > > urlpatterns += patterns('', > > (r'^static/(?P.*)$', 'django.views.static.serve', > > {'document_root': settings.STATIC_DOC_ROOT}), > > ) > > This url pattern is not consistant with the your MEDIA_URL settings. A > good way to avoid this kind of problems is to follow the SPOT rule: > > ### in settings.py > import os > > PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) > SITE_URL = "http://127.0.0.1:8000"; > > MEDIA_DIR = "media" > MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) > MEDIA_URL = "%s/%s/" % (SITE_URL, MEDIA_DIR) > > ADMIN_MEDIA_PREFIX = '/admin-media/' > > # decouple this from the DEBUG flag - you may want to > # set DEBUG to true in preproduction > # (ie, running behind apache or another web server) > DEV_SERVER = True > > ### in urls.py > from django.conf import settings > > # urls here... > > if settings.DEV_SERVER: > urlpatterns += patterns('', > (r'^%s/(?P.*)$' % setting.MEDIA_DIR, > 'django.views.static.serve', > {'document_root': settings.MEDIA_ROOT}), > ) > > > (I have also tried variations on the above, such as: > > (r'^media/(?P.*)$', 'django.views.static.serve', > > which may have worked, minus the conflict between MEDIA_URL and > ADMIN_MEDIA_PREFIX > > > and > > (r'%s(?P.*)' % settings.MEDIA_URL[1:], > > MEDIA_URL is a string, so MEDIA_URL[1:] is the same string minus the > first character, ie, in your case : "ttp://127.0.0.1:8000/media/". > Probably not what you expected !-) > > > 'django.views.static.serve', > > {'document_root': settings.MEDIA_ROOT}), > > ) > > > but in all cases, although the file does get uploaded and appears in the > > '/home/blah/blah/mysite/media/photos/' directory, when I click on the link - > > which is shown as > > >http://127.0.0.1:8000/media/photos/test.jpg > > > I get a "Page not found: /media/photos/test.jpg" > > > This seems like a simple thing to fix - but not for me? > > cf above. > > > Any help to fix this is appreciated, as is any guidance on what will need to > > change once this project needs to run under Apache... > > If you're careful to use the "medias" context processor and > {{ MEDIA_URL }} in your templates, you shouldn't have to do much more > than update your settings.py appropriately. But anyway - first fix > your development setup. --~--~-~--~~~---~--~~ 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://g
Re: Uploading and using images in a database application
Adrian Does the Photologue app store the image references in the database? On Nov 5, 6:58 pm, adrian wrote: > The easiest way is to use the Photologue application. > It has done most of the work for you. > > On Nov 5, 9:53 am, bruno desthuilliers > wrote: > > > On 3 nov, 16:02, derek wrote: > > > > Given that I am a "wet behind the ears" newbie, maybe I should not be > > > attempting this, but... > > > Attempts at thing we don't yet fully grasp can be a good way to > > learn. > > > > I need some simple and straightforward guidance on > > > uploading and using images in a simple database application, which (so > > > far) > > > only uses the admin interface. > > > > I working on my development machine (i.e. no Apache integration as yet). > > > > The use case is not that complex. If I have an "Event" object, with > > > which I > > > want to associate a number of images (typically, photos taken by people at > > > that event), then I also need an "EventImage" object, with the event.id as > > > the foreign key. > > > > So, the models look like: > > > > class Event(models.Model): > > > id = models.AutoField(primary_key=True) > > > Hint : if you leave this previous line out, Django will automagically > > add this very same field to your model !-) > > > > date_time = models.DateTimeField() > > > title = models.CharField(unique=True,max_length=250) > > > > class EventImage(models.Model): > > > id = models.AutoField(primary_key=True) > > > caption = models.CharField(unique=True,max_length=10) > > > title = models.CharField(max_length=250) > > > event = models.ForeignKey(Event) > > > image = models.ImageField(upload_to='photos') > > > > What I have gathered so far, from browsing articles and snippets and Q&A, > > > is > > > that I also need: > > > > 1.to add/change settings.py: > > > > MEDIA_ROOT = '/home/blah/blah/mysite/media/' > > > MEDIA_URL = 'http://127.0.0.1:8000/media/' > > > ADMIN_MEDIA_PREFIX = '/media/' > > > Using the same path component for both the static medias and the admin > > media usually leads to unexpected results. Either change your static > > medias component path to something else or - way simplier -, change > > the ADMIN_MEDIA_PREFIX (here we canonically set it to 'admin-media'). > > > > STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/' > > > > 2. add the following to the start of urls.py: > > > > from django.conf import settings > > > > 3. add the following to the end of urls.py: > > > > if settings.DEBUG: > > > urlpatterns += patterns('', > > > (r'^static/(?P.*)$', 'django.views.static.serve', > > > {'document_root': settings.STATIC_DOC_ROOT}), > > > ) > > > This url pattern is not consistant with the your MEDIA_URL settings. A > > good way to avoid this kind of problems is to follow the SPOT rule: > > > ### in settings.py > > import os > > > PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) > > SITE_URL = "http://127.0.0.1:8000"; > > > MEDIA_DIR = "media" > > MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) > > MEDIA_URL = "%s/%s/" % (SITE_URL, MEDIA_DIR) > > > ADMIN_MEDIA_PREFIX = '/admin-media/' > > > # decouple this from the DEBUG flag - you may want to > > # set DEBUG to true in preproduction > > # (ie, running behind apache or another web server) > > DEV_SERVER = True > > > ### in urls.py > > from django.conf import settings > > > # urls here... > > > if settings.DEV_SERVER: > > urlpatterns += patterns('', > > (r'^%s/(?P.*)$' % setting.MEDIA_DIR, > > 'django.views.static.serve', > > {'document_root': settings.MEDIA_ROOT}), > > ) > > > > (I have also tried variations on the above, such as: > > > (r'^media/(?P.*)$', 'django.views.static.serve', > > > which may have worked, minus the conflict between MEDIA_URL and > > ADMIN_MEDIA_PREFIX > > > > and > > > (r'%s(?P.*)' % settings.MEDIA_URL[1:], > > > MEDIA_URL is a string, so MEDIA_URL[1:] is the same string minus the > > first character, ie, in your case : "ttp://127.0.0.1:8000/media/". > > Probably not what you expected !-) > > > > 'django.views.static.serve', > > > {'document_root': settings.MEDIA_ROOT}), > > > ) > > > > but in all cases, although the file does get uploaded and appears in the > > > '/home/blah/blah/mysite/media/photos/' directory, when I click on the > > > link - > > > which is shown as > > > >http://127.0.0.1:8000/media/photos/test.jpg > > > > I get a "Page not found: /media/photos/test.jpg" > > > > This seems like a simple thing to fix - but not for me? > > > cf above. > > > > Any help to fix this is appreciated, as is any guidance on what will need > > > to > > > change once this project needs to run under Apache... > > > If you're careful to use the "medias" context processor and > > {{ MEDIA_URL }} in your templates, you shouldn't have to do much more > > than update your settings.py appropriately. But anyway - first fix > > your development setup. > > --~--~-~--~~--
flatpages not finding site_media
I'm trying to use some flatpages for static content and I don''t understand why they keep failing to load media files. I have my template_dirs defined, media_root and media_url - when used in template does not resolve to media_root i.e., template contains: results in: Failed to load source for: http://127.0.0.1:8000/about/css/base.css MEDIA_ROOT = '/Users/neridaj/django-templates/neridaj/' MEDIA_URL = '/site_media/' TEMPLATE_DIRS = ( '/Users/neridaj/django-templates/neridaj/' ) The default template renders but without any of the css. Thanks, J --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---