Re: converting sql command to django api query
Thanks, this is a very interesting way. I will give a try. Cheers, Alan On Mon, Dec 29, 2008 at 04:48, join.toget...@gmail.com < join.toget...@gmail.com> wrote: > > In your model definition, you can specify choices for each field. > http://docs.djangoproject.com/en/dev/topics/db/models/#field-options > > Create a list of (DB value, display value) tuples containing all the > choices, then set the field's "choices" option to that list. > > Later, when you have your model instance, you can call > "instance.get_junit_display()" to obtain the "4 magenta" etc for > display or whatever else you would need it for. > > On Dec 25, 4:28 pm, Alanwrote: > > Hi List, Merry Xmas! > > > > In my mysql db, I have this table (ccpngrid_gridjob), created from a > model > > GridJob: > > > > | juser | jname | title | fileName | jdate | jobdir | jstatus | jpid | > jiter > > | round | > > > > where my pk is jobdir. > > > > I would like to know how to convert, if possible, the sql command below > to a > > django query: > > > > select *, case > > when jstatus='Submitted' then '1 orange' > > when jstatus='Running' then '2 blue' > > when jstatus='Failed' then '3 red' > > when jstatus='Cancelled' then '4 magenta' > > when jstatus='Finished' then '5 green' > > else '6 black' end as seq > > from ccpngrid_gridjob where juser='alan' > > order by seq, jobdir DESC > > > > Many thanks in advance. > > > > Alan > > > > -- > > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate > > Department of Biochemistry, University of Cambridge. > > 80 Tennis Court Road, Cambridge CB2 1GA, UK. > > > > >>http://www.bio.cam.ac.uk/~awd28<< > > > -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< --~--~-~--~~~---~--~~ 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 question - Deploying Django apps
Hi, I am using Eclipse editor to work with my django projects. Can anyone recommend a way to deploy my django apps to an Apache web server? Currently, I am manually copying the entire source folder to the correct location on my Apache server. It seems that there should be an easier way to keep my Apache server up to date with changes. Thanks in advance, Leslie --~--~-~--~~~---~--~~ 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 IDE
how can we debug errors in templates? Are there any IDE for this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 Django Comic Site Issues
Hello, Thanks for your reply Daniel, that along with setting ordering on the Comic model seems to have fixed it. Titus On Dec 28, 9:55 am, Daniel Rosemanwrote: > On Dec 28, 5:35 am, tsop wrote: > > > > > Hey, > > I'm quite new to django but I ran into a small problem maybe someone > > can shed some light onto: > > > models.py > > > class Comic(models.Model): > > title = models.CharField(max_length=80, help_text='Title of > > comic.') > > series = models.ForeignKey(ComicSeries, help_text='Which > > series comic belongs to.') > > image = models.ImageField(upload_to='tmp', help_text='A > > comic.') > > page_number = models.IntegerField(editable=False) > > def __unicode__(self): > > return "%s - %s" % (self.title, self.series) > > > def get_absolute_url(self): > > #return "/comics/%s/?page=%d" % (self.series.slug, > > self.page_number) > > return "/comics/%s/%d" % (self.series.slug, > > self.page_number) > > > def save(self): > > if not self.page_number: > > count = len(Comic.objects.filter > > (series=self.series)) > > self.page_number = count + 1 > > > super(Comic, self).save() > > > -- > > > admin.py > > > class ComicInline(admin.StackedInline): > > model = Comic > > extra = 20 > > > (Multi form uploading) > > > When saving a comic it should also save the right page number, the > > reason I'm using my own page_numbers is because each comic belongs to > > a series and if its the first in that series it should be page number > > one, so we're not using comic id or anything. > > > It works for the most part, the page number increments as the comics > > are saved, but when you start deleting previous comics and adding new > > ones it doesn't save in the right order anymore. > > > All I really need to know is if there's a way we can make sure that > > when multi form saves, it saves them in either the right order, or pre- > > populates the page_number field with the right values. > > Instead of getting the total number of comics in the series, what you > want to do is get the highest existing page number. This is one way to > do it: > Comic.objects.filter(series=self.series).order_by('-page_number') > [0].page_number > > This just reverse-orders the comic series by page number, and takes > the page_number from the first object - which will be the highest. > -- > 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: Variables in templates
Vicky wrote: > Is there any way to create a variable within the templates...? > You'll need to be more specific. What exactly are you trying to do? You can define anything you need in your view, and then pass it to the template. Logic belongs in the view. Templates are only there to put that data into the final file format for the end user (html in most cases). Jeff Anderson signature.asc Description: OpenPGP digital signature
how to set up google docs-like sharing
I'm trying to set up a system where you can create a document and add collaborators (well, watchers) similar to google docs. Here's my model right now: class Poll(models.Model): title = models.CharField(max_length="250") owner = models.ForeignKey(User, null=True, related_name="%(class)s_poll", editable=False) watchers = models.ManyToManyField(User) created_date = models.DateTimeField(default=datetime.now, editable=False) expiration_date = models.DateTimeField() def __unicode__(self): return self.title class Meta: ordering = ['title'] A ModelForm, by default, gives me a multi-select box for watchers. Is my best approach to write my own widget to have them type in a comma separated list of emails? How could I handle email addresses for accounts that aren't set up yet? -Paul --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Variables in templates
Is there any way to create a variable within the templates...? --~--~-~--~~~---~--~~ 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: wondering how to do something similar to save_model for inline.
This is your database error.. On Dec 28, 8:32 am, Timboywrote: > Great link. I was really excited to try it. > > Here is my new inline: > class rentalInline(admin.TabularInline): > model= Rent > extra = 3 > raw_id_fields = ('movie',) > exclude = ['rented_by'] > > def save_formset(self, request, form, formset, change): > instances = formset.save(commit=False) > for instance in instances: > instance.rented_by = request.user > instance.save() > formset.save() > > I am still getting the same issue: > Traceback: > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" > in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" > in root > 157. return self.model_page(request, *url.split('/', > 2)) > File "/usr/lib/python2.5/site-packages/django/views/decorators/ > cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" > in model_page > 176. return admin_obj(request, rest_of_url) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in __call__ > 197. return self.change_view(request, unquote(url)) > File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in > _commit_on_success > 238. res = func(*args, **kw) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in change_view > 583. self.save_formset(request, form, formset, > change=True) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in save_formset > 382. formset.save() > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save > 372. return self.save_existing_objects(commit) + > self.save_new_objects(commit) > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in > save_new_objects > 407. self.new_objects.append(self.save_new(form, > commit=commit)) > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in > save_new > 473. return save_instance(form, new_obj, exclude= > [self._pk_field.name], commit=commit) > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in > save_instance > 59. instance.save() > File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in > save > 91. super(Rent, self).save(**kwargs) > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in > save > 307. self.save_base(force_insert=force_insert, > force_update=force_update) > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in > save_base > 379. result = manager._insert(values, > return_id=update_pk) > File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in > _insert > 138. return insert_query(self.model, values, **kwargs) > File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in > insert_query > 888. return query.execute_sql(return_id) > File "/usr/lib/python2.5/site-packages/django/db/models/sql/ > subqueries.py" in execute_sql > 308. cursor = super(InsertQuery, self).execute_sql(None) > File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py" > in execute_sql > 1700. cursor.execute(sql, params) > File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in > execute > 19. return self.cursor.execute(sql, params) > > Exception Type: IntegrityError at /admin/store/renter/4/ > Exception Value: null value in column "rented_by_id" violates not-null > constraint --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Please have a look, sub category field is not saving
Hi all i am not able to save the entry of sub_cat field here is my model.py class MainCategory(models.Model): main_cat_code= models.CharField(max_length=20,primary_key=True) description = models.CharField(max_length = 50,) def __unicode__(self): return self.main_cat_code class SubCategory(models.Model): sub_cat_code= models.CharField(max_length=20,primary_key=True) main_category=models.ForeignKey(MainCategory) description = models.CharField(max_length = 50) def __unicode__(self): return self.description In admin.py: i am using stackedline. and i have registered MainCategoryAdmin class SubInline(admin.StackedInline): model = SubCategory extra = 1 class MainCategoryAdmin(admin.ModelAdmin): list_filter=['main_cat_code'] search_fields = ['main_cat_code'] inlines = [SubInline] admin.site.register(MainCategory, MainCategoryAdmin) --~--~-~--~~~---~--~~ 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: converting sql command to django api query
In your model definition, you can specify choices for each field. http://docs.djangoproject.com/en/dev/topics/db/models/#field-options Create a list of (DB value, display value) tuples containing all the choices, then set the field's "choices" option to that list. Later, when you have your model instance, you can call "instance.get_junit_display()" to obtain the "4 magenta" etc for display or whatever else you would need it for. On Dec 25, 4:28 pm, Alanwrote: > Hi List, Merry Xmas! > > In my mysql db, I have this table (ccpngrid_gridjob), created from a model > GridJob: > > | juser | jname | title | fileName | jdate | jobdir | jstatus | jpid | jiter > | round | > > where my pk is jobdir. > > I would like to know how to convert, if possible, the sql command below to a > django query: > > select *, case > when jstatus='Submitted' then '1 orange' > when jstatus='Running' then '2 blue' > when jstatus='Failed' then '3 red' > when jstatus='Cancelled' then '4 magenta' > when jstatus='Finished' then '5 green' > else '6 black' end as seq > from ccpngrid_gridjob where juser='alan' > order by seq, jobdir DESC > > Many thanks in advance. > > Alan > > -- > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate > Department of Biochemistry, University of Cambridge. > 80 Tennis Court Road, Cambridge CB2 1GA, UK. > > >>http://www.bio.cam.ac.uk/~awd28<< --~--~-~--~~~---~--~~ 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: enumerate in templates
ya that's what i need :) thanks a lot :) :) On Dec 28, 8:06 pm, Daniel Rosemanwrote: > On Dec 27, 6:20 am, Vicky wrote: > > > Is there a way to access the previous value of a for loop in > > templates. Can anyone tell the template representation for the python > > code like: > > > for i,j in enumerate(item): > > ... > > I think the various forloop variables are what you want. > > {% for j in item %} > {{ forloop.counter0 }} > {% endfor %} > > See :http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for > -- > 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: memory use in django database queries
Three things: 1: http://docs.djangoproject.com/en/dev/ref/models/querysets/#iterator 2: What you're trying to do can be done much more efficiently the following way: sum(SomeModel.objects.all().values_list('value')) 3: django 1.1 will have aggregation support, meaning you won't even need to do #2 On Dec 24, 5:42 pm, garyrobwrote: > I am getting the impression that when I do a django database query > that iterates through all the rows of the table, django stores every > model instance in memory. > > For instance, just doing > > sumValues = 0 > for someModel in SomeModel.objects.all(): > sumValues += someModel.value > print sumValues > > can eat up gigabytes of memory if the table is large. > > But in this example, I don't have any need for the SomeModel instances > that have already been processed once the value has been retrieved. So > this is a huge amount of wasted memory. > > Is there any way to make django not behave this way? I.e., when > iterating through a query request, I'd like to be able to tell django > to just retrieve a row at a time from the database, and release the > memory that was used for previously-retrieved rows. --~--~-~--~~~---~--~~ 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 populate a form field with a Select widget
I would like to populate a form field which uses a Select widget with choices in views.py. I understand I can pass the initial arg to the form but I couldn't find the correct value to pass. The choices is a list of tuple CHOICES = ( ('P', 'Pending'), ('A', 'Active'), ('D', 'Done')) Any hints? -Aaron --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
custome tags, single model, multiple classes
I've got a gallery model, with a Gallery class, and an ImageUpload class. in my custom tag i'm pulling in the Gallery to display a list of galleries in a side bar. this works fine. But, i want to randomly display an image associated with that gallery, which would be accessed through ImageUpload (i should change the class name to Image). do i create another class in the single custom tag in the templatestag directory? or can i create another tag in that directory? or... do i create a method inside the Gallery class so that it is accessible that way? 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: '.schema' is not recognized as an internal or external command, operable program or batch file
Hey, .schema is a command for the sqlite3 shell. If you have sqlite3 installed and have set DATABASE_ENGINE to sqlite3, type "sqlite3 " at your shell. is file name specified by DATABASE_NAME in settings.py. You should be able to issue the ".schema" command successfully from there. Regards, Jeff On Sun, Dec 28, 2008 at 5:24 PM, mango7wrote: > > I am new to django, and following the tutorial at: > http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs > > I got as far as creating and syncing a DB, but when I type .schema > into my command prompt, I get: > > '.schema' is not recognized as an internal or external command, > operable program or batch file > > Does anyone know why this is? I was able to get through the end of > the tutorial otherwise. > > Thanks in advance. > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
'.schema' is not recognized as an internal or external command, operable program or batch file
I am new to django, and following the tutorial at: http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs I got as far as creating and syncing a DB, but when I type .schema into my command prompt, I get: '.schema' is not recognized as an internal or external command, operable program or batch file Does anyone know why this is? I was able to get through the end of the tutorial otherwise. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django i18n for google
On Sun, Dec 28, 2008 at 7:19 PM, Alessandro Ronchiwrote: > Django itselfs permits selecting the i18n language via POST. I think > it should be useful to add also a GET var to set the language, and a > localization middleware catches it. This has been debated to death, and the conclusion is that Django's own i18n system will only support changing language via HTTP POST. Please consult the list archives for details. -- "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: django i18n for google
2008/12/27 Antoni Aloy: > You could create a url that links to your localized site so Google > would be able to crawl it, but I suppose that your site depens on > changing the language via POST, isn't it? > > I that case, you could write yourselve the code and allow changing the > code using GET. Django itselfs permits selecting the i18n language via POST. I think it should be useful to add also a GET var to set the language, and a localization middleware catches it. Django gets user language from the browser accept-language or user browser cookie, but it should be useful to force it with a =en This little mod could improve google crawling, because one can only make sitemaps with urls and that get value added to default urls for every translations (and it should be easy to add a shortcut to add urls in different language translations in sitemap views). -- Alessandro Ronchi Skype: aronchi http://www.alessandroronchi.net SOASI Soc.Coop. - www.soasi.com Sviluppo Software e Sistemi Open Source Sede: Via Poggiali 2/bis, 47100 Forlì (FC) Tel.: +39 0543 798985 - Fax: +39 0543 579928 Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~-~--~~~---~--~~ 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: link to a text file without "txt" extension
Thanks Jarek, it sounds true what you said because when I did this first implementation was in Zope. But I am not the admin. I will check with the admin here. Cheers, Alan 2008/12/28 Jarek Zgoda> > Wiadomość napisana w dniu 2008-12-28, o godz. 19:05, przez Alan: > > > A external program generate files and I want to access then via > > django. I have a file "report" and buit the link to it. But when I > > click on the link to "report", instead of getting the "report" text > > content showed by my browser, I got a prompt to download it. > > > > How can I do in my template file to tell to the browser that the > > link is to a content-type "text/html"? > > > > This is handled by Content-disposition HTTP header - you have to go to > your HTTP server config and modify it to treat and serve this > particular file as readable plain text, not a binary file. Django > templates (and HTML links) have nothing to do with this, I think. > > -- > We read Knuth so you don't have to. - Tim Peters > > Jarek Zgoda, R, Redefine > jarek.zg...@redefine.pl > > > > > -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
adding default inline items on a model/add page in the admin
Hi, I'm trying to figure out how to customize a model/add page so that it includes zero or more default items in an inline list. More specifically, the following code produces almost what I need, but I'd like to be able to add some default entries to the inline Roles list on (only) the meetings/add page, based on the suggested_maximum_per_meeting and is_enabled fields in the RoleDefinition model. Any ideas? I have the following in my admin.py: class RoleDefinitionAdmin(admin.ModelAdmin): fields = ['title', 'suggested_maximum_per_meeting', 'description'] list_display = ('title') search_fields = ['title', 'description'] class RoleInline(admin.TabularInline): model = Role extra = 2 class MeetingAdmin(admin.ModelAdmin): fields = ['title', 'date', 'description'] list_display = ('title', 'date') inlines = [RoleInline] list_filter = ['date'] search_fields = ['title', 'description'] date_hierarchy = 'date' ... and the following in my models.py: class Meeting(models.Model): title = models.CharField(max_length=300) description = models.TextField() date = models.DateTimeField(unique=True) class RoleDefinition(models.Model): title = models.CharField(max_length=100) description = models.TextField() suggested_maximum_per_meeting = models.IntegerField() # suggested maximum number of this role assignment allowed per meeting class Role(models.Model): meeting = models.ForeignKey(Meeting) role_definition = models.ForeignKey(RoleDefinition) user = models.ForeignKey(User) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: image uploading via admin, and an error...
I find a way to install correctly PIL : http://www.unelectronlibre.info/tutoriels/python/installer_pil_sous_mac_osx.html Then, Django didnt bothered me anymore with this error. And the selftest.py joined with the PIL sources now pass without problems. I only had to install the .dmg, I didnt set up the symbolic links as the document explains. Hope it will work for 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: Calculate and store the average rating
@Dave: It is not a 1-to1 as I would like each borrower to provide his own rating, and then compute the average ratings per book - to make recommendations for the highest rated books. Thanks for the example in the reply too. I will try out the SQL update shortly. @ Russ: Thanks too for the input. I will read up on signals - this is news! The denormalization - same comment as above. I'm going to try the SQL computation first, then will look at signals. The probem: I want to calculate the average rating in the BookRatings model each time an individual rating of a book is captured in the Loan model. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: link to a text file without "txt" extension
Wiadomość napisana w dniu 2008-12-28, o godz. 19:05, przez Alan: > A external program generate files and I want to access then via > django. I have a file "report" and buit the link to it. But when I > click on the link to "report", instead of getting the "report" text > content showed by my browser, I got a prompt to download it. > > How can I do in my template file to tell to the browser that the > link is to a content-type "text/html"? > This is handled by Content-disposition HTTP header - you have to go to your HTTP server config and modify it to treat and serve this particular file as readable plain text, not a binary file. Django templates (and HTML links) have nothing to do with this, I think. -- We read Knuth so you don't have to. - Tim Peters Jarek Zgoda, R, Redefine jarek.zg...@redefine.pl --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
link to a text file without "txt" extension
Hi List, So I have this situation: A external program generate files and I want to access then via django. I have a file "report" and buit the link to it. But when I click on the link to "report", instead of getting the "report" text content showed by my browser, I got a prompt to download it. How can I do in my template file to tell to the browser that the link is to a content-type "text/html"? Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< --~--~-~--~~~---~--~~ 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 deadlocking issues
Hallöchen! Malcolm Tredinnick writes: > On Wed, 2008-11-19 at 10:21 +0900, Ian Lewis wrote: > >> I've run into the following error in a SQL DB envornment and was >> wondering if any one else had run into problems with Deadlocking >> with MySQL. What would be the proper way to handle this kind of >> error in Django? >> >> Do most folks simply catch the OperationalError and show some >> sort of error to the user? > > That sounds reasonable. > > More substantive for our purposes, though, would be knowing why > this occurred and if there was any way to avoid it. I got an OperationalError (1213, 'Deadlock found when trying to get lock; try restarting transaction') with an M2M relationship. With class Process(models.Model): ... class Sample(models.Model): ... processes = models.ManyToManyField(Process, blank=True, related_name="samples", verbose_name=_(u"processes")) the line my_process.samples = self.samples_form.cleaned_data["sample_list"] triggered the exception. I was running the Django app with Apache, having MySQL on the same machine (one core). I started two client bots that connected with high frequency to the Apache and executed this line in the Django app quasi-parallely. I used InnoDB with the transaction middleware (one transaction per request). Apparently, a M2M relationship may lead to this exception in this scenario. I can't tell whether this needs to be improved in Django, or whether I have to catch and retry it on the view level. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de --~--~-~--~~~---~--~~ 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: enumerate in templates
On Dec 27, 6:20 am, Vickywrote: > Is there a way to access the previous value of a for loop in > templates. Can anyone tell the template representation for the python > code like: > > for i,j in enumerate(item): > ... I think the various forloop variables are what you want. {% for j in item %} {{ forloop.counter0 }} {% endfor %} See : http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for -- 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: A Django Comic Site Issues
On Dec 28, 5:35 am, tsopwrote: > Hey, > I'm quite new to django but I ran into a small problem maybe someone > can shed some light onto: > > models.py > > class Comic(models.Model): > title = models.CharField(max_length=80, help_text='Title of > comic.') > series = models.ForeignKey(ComicSeries, help_text='Which > series comic belongs to.') > image = models.ImageField(upload_to='tmp', help_text='A > comic.') > page_number = models.IntegerField(editable=False) > def __unicode__(self): > return "%s - %s" % (self.title, self.series) > > def get_absolute_url(self): > #return "/comics/%s/?page=%d" % (self.series.slug, > self.page_number) > return "/comics/%s/%d" % (self.series.slug, > self.page_number) > > def save(self): > if not self.page_number: > count = len(Comic.objects.filter > (series=self.series)) > self.page_number = count + 1 > > super(Comic, self).save() > > -- > > admin.py > > class ComicInline(admin.StackedInline): > model = Comic > extra = 20 > > (Multi form uploading) > > When saving a comic it should also save the right page number, the > reason I'm using my own page_numbers is because each comic belongs to > a series and if its the first in that series it should be page number > one, so we're not using comic id or anything. > > It works for the most part, the page number increments as the comics > are saved, but when you start deleting previous comics and adding new > ones it doesn't save in the right order anymore. > > All I really need to know is if there's a way we can make sure that > when multi form saves, it saves them in either the right order, or pre- > populates the page_number field with the right values. Instead of getting the total number of comics in the series, what you want to do is get the highest existing page number. This is one way to do it: Comic.objects.filter(series=self.series).order_by('-page_number') [0].page_number This just reverse-orders the comic series by page number, and takes the page_number from the first object - which will be the highest. -- 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 -~--~~~~--~~--~--~---
A Django Comic Site Issues
Hey, I'm quite new to django but I ran into a small problem maybe someone can shed some light onto: models.py class Comic(models.Model): title = models.CharField(max_length=80, help_text='Title of comic.') series = models.ForeignKey(ComicSeries, help_text='Which series comic belongs to.') image = models.ImageField(upload_to='tmp', help_text='A comic.') page_number = models.IntegerField(editable=False) def __unicode__(self): return "%s - %s" % (self.title, self.series) def get_absolute_url(self): #return "/comics/%s/?page=%d" % (self.series.slug, self.page_number) return "/comics/%s/%d" % (self.series.slug, self.page_number) def save(self): if not self.page_number: count = len(Comic.objects.filter (series=self.series)) self.page_number = count + 1 super(Comic, self).save() -- admin.py class ComicInline(admin.StackedInline): model = Comic extra = 20 (Multi form uploading) When saving a comic it should also save the right page number, the reason I'm using my own page_numbers is because each comic belongs to a series and if its the first in that series it should be page number one, so we're not using comic id or anything. It works for the most part, the page number increments as the comics are saved, but when you start deleting previous comics and adding new ones it doesn't save in the right order anymore. All I really need to know is if there's a way we can make sure that when multi form saves, it saves them in either the right order, or pre- populates the page_number field with the right values. --~--~-~--~~~---~--~~ 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 Comments framework
Hello, I removed the preview button as it did not preview, it posted. To redirect the "post" add the following line to the comment form: where <> is what page you want to view after posting. Sean On Dec 27, 4:30 pm, stereoitwrote: > Hi, > I tried to add comments > apphttp://docs.djangoproject.com/en/dev/ref/contrib/comments/, > now few things works but Preview sometimes acts as Submit when there > are no errors and I have no idea how to override Posted screen to > include link (or just redirect) to original page. > > The documentation is kinda sparse and i had to look into source code > to see there are some templates I can override. Any good tutorial on > new comments framework? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
HBase and Django
Hi, I was wondering whether anyone has made any headway into getting HBase working with Django? I think the existence of such an option would be definite boon to the framework. Cheers Mark --~--~-~--~~~---~--~~ 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: Invalid block tag: 'get_comment_count'
Am 28.12.2008 um 00:42 schrieb Russell Keith-Magee: > > On Sun, Dec 28, 2008 at 12:27 AM, Florian Lindner >wrote: >> >> Hello, >> >> I'm trying to use the comment framework from Django 1.0.2. >> >> I've followed all the steps in >> http://docs.djangoproject.com/en/dev/ref/contrib/comments/ >> >> (added it to installed apps, added to urls.py and loaded in the >> template) but I get: >> >> TemplateSyntaxError at /blog/1/ >> Invalid block tag: 'get_comment_count' >> >> from: >> >> {% get_comment_count for object as comment_count %} > > django.contrib.comments is an extension application, so the template > capabilities provided by this application aren't included in the > default template tag set. In order to use {% get_comment_count %} in > your template, you need to direct the template engine to load the > comment template tags. This means putting {% load comments %} at the > start of the template that is using {% get_comment_count %. > > This is covered right at the start of the page you referenced: > > http://docs.djangoproject.com/en/dev/ref/contrib/comments/#comment-template-tags Hello, I have {% load comments % } right at the top of my template. That is what I meant with " and loaded in the template". Any other ideas? Thanks, Florian --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---