Re: Order By Calculated Value??
On Dec 5, 5:17 pm, "Tane Piper" <[EMAIL PROTECTED]> wrote: > Here is my blog application, which contains the two models: Thanks. So, as I said in the post above, Entry.save() override won't work with your M2M categories. That's because the M2M objects are saved only after the Entry is saved and rightfully so. Besides the solutions I had listed in my first reply above, you might consider another one: Create an explicit M2M table instead of the one Django implicitly creates for an M2M field. With your own M2M class/table, you will be able to override its save() method and launch appropriate count calculations there. See here for an example of how this is intermediate M2M pattern is accomplished: http://www.djangoproject.com/documentation/models/m2m_intermediary/ -Rajesh Dhawan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Order By Calculated Value??
Hi Darryl and Tane, > > [untested with Many2Many, but should work, it works for ForeignKeys] Actually, the approach below won't work for M2M even though it does for FKs. > In your Entry save() method call the save method of each of your related > categories after you do your super().save() > > {{{ > class Entry(models.Model): > ... > def save(self): > if not self.slug: > self.slug = slugify(self.title) > super(Entry, self).save() > for category in self.categories: > category.save() > ... Entry.save() is called /before/ the M2M category table is updated by Django. That means this save() can not iterate over Categories. This will work (albeit, incorrectly) when an existing Entry is being updated because it will already have some old M2M categories but it won't work when creating a new Entry as self.categories would not be available during this save(). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Order By Calculated Value??
> > Hope that makes sense, as if I can do it this way instead of > calculating it on the view, that would make this inclusion tag so much > easier. What does your Entry model look like? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems saving values from SelectDateWidget
On Dec 5, 10:31 am, Stupid Dustbin <[EMAIL PROTECTED]> wrote: > Thanks for the reply. However, after updating to the latest SVN > version of django. The same error still occurs. :( I am using the same constructs with Django rev #6652 in production. Perhaps you want to downgrade to that revision and try it out one more time? If that fails, it would be time to open a ticket. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Order By Calculated Value??
Hi, > > I'm wondering if there is any way possible to get this value in my > inclusion tag? You can use the "extra" method to bring in your entry counts into the query set. See the following for an example: http://www.djangoproject.com/documentation/db-api/#extra-select-none-where-none-params-none-tables-none > I had tried before to store this value in a field, but > couldn't get it to save, otherwise I would just pass in a field > 'num_entries' so if anyone can suggest anything, that would be great. Can you describe what you did that prevented you from saving the computed count? Another solution is to batch compute your counts using a shell script at some frequency. The script could iterate over each category and recompute its counts and store them. Yet another solution is to convert your cats queryset to a list, loop over it to get an entry count, and then sort the list in Python to pass on to your template. So there seem to be many ways to skin this cat. -Rajesh Dhawan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: dynamic newforms validation etc
> This data needs to be saved in Options. A record for each product > selected with the name and price in it. This is because the product > name can change in the future and the price can change. So this should > be stored in Options. > > My problem is that I don't know yet how to do this. > > Can somebody explain me how I should do this with newsforms... You will need a dynamically generated form as you don't know ahead of time how many Products you might have. Here's something to get you started (hastily put together and completely untested): import django.newforms as forms import django.newforms import widgets from products import models class MyForm(forms.Form): def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) i = 0 for p in models.Product.objects.select_related().all(): self.fields['product_%s' % i] = forms.CharField( widget=widgets.HiddenInput(), initial=p.pk) self.fields['checkbox_%s' % i] = forms.CheckboxField(initial=False) self.fields['name_%s' % i] = forms.CharField(initial=p.name) self.fields['price_%s' % i] = forms.DecimalField(initial=p.price) options = p.option_set.all()[:1] # assumes at most one Option per product if options: self.fields['checkbox_%s' % i].initial = True self.fields['name_%s' % i].initial = options[0].name self.fields['price_%s' % i].initial = options[0].price i += 1 Note that the above assumes your model class names to be Product and Option (singular). It's good practice to not use plural names. Also the above assumes at most one Option per product. -Rajesh D. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems saving values from SelectDateWidget
On Nov 29, 4:51 am, Stupid Dustbin <[EMAIL PROTECTED]> wrote: > Hi, encountered a problem recently with SelectDateWidget. I'm not very > sure what I did wrong. Your usage of that widget is correct. Note that a recent Django revision (the excellent "autoescape" feature) had introduced a bug that caused this widget to fail. It's been fixed in SVN rev. 6723: http://code.djangoproject.com/changeset/6723 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to make such query with django ORM?
> > I need to get all blogs that belong to certain user and are empty (do > not have any articles). I can't figure out how to make it with without > extra() method. As others have recommended, just use the extra() method. It's not so bad :) If you really really want to avoid that, you could add a count integer field to your Blog model and maintain its value from overridden methods Article.save() and Article.delete(). So Blog.count would get refreshed every time you add/update/delete articles and your desired query becomes a straight lookup on Blog. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Use of newforms prefixes in html templates
> > I have a list of forms that I want to pass to my template but I am not > sure how to include the prefix. When you are creating each instance of your form, just specify the appropriate prefix for it: form = MyForm(prefix='my-prefix') When you render this form instance, Django will include the prefix in the name of each field of that form. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Access urls in template tags?
> Is there a simple way to do this within the template tag or would I > need to create a context processor and would this be available within > the templatetag or only within the template itself? You can do this inside a template tag. Assuming that you already have the request available in your views' context[1], your template tag has access to that context so you will be able to get the request within your template tag's render method: request = context['request'] [1]http://www.djangoproject.com/documentation/templates_python/ #subclassing-context-requestcontext --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: question about list_display
> > It is about how to use color in list_display. > When i use it, I didn't correctly get the colored field of > first_name. > Only get strings like '%s' in this > field. > Is there anything I misunderstand to make it work correctly? Your use of "allow_tags" looks good. A recent release of Django introduced this bug (the auto-escape update). See this ticket: http://code.djangoproject.com/ticket/5973 The quickest fix is to update to the latest Djagno SVN release as this bug is already fixed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: generic views and form templates
> that work ok, when a user want to create an entry it opens > komentar_form.html and it's displayed right. but when user clicks > submit, it always returns a error for slug field. since user doesn't > write slug field (should be prepopulated, right?), No. That only happens in the admin and even there if you use the "prepopulate_from" option. In your own object creation form, slug fields are not automatically populated by Django. So, it may be that an empty slug field is getting stored in your DB and when you try to store a second object (with yet another emtpy slug field), your unique=True constraint on the slugfield is causing that error. One solution is to generate the slug field from another suitable field of your model (say, title or name). You can do that auto slugification in an overridden save() method on your model. If you need slugification code, take a look at the slugify() method in django.templates.defaultfilters. You can simply call it directly even though it's primary use is as a template filter. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Permissions and user.has_perm
> > >>> u.has_perm("person.add_person") > False What's your app_label (usually the lowercase name of the app whose models.py contains your Person class")? The has_perm method should be called with .add_person and not with .add_person --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Complicated question
> > That's interesting, but I think that leaving the models untouched > would be better. > Do you think there is a different way? There might be. First, you'd have to explain what you didn't like about doing queries like: Image.objects.filter( book__library_owner=request.user) Since you don't want to change your models, only your Library model maintains the source of ownership and so, by definition, all your queries would have to lead to a check on the Library.owner field thereby ending up with filters like xyz__library_owner=some_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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: local dev them publish out to the real world
> hey I am new to django? Welcome. > so is it possable to devlop a django site on my mac and then publish > to another webserver or EC2/S3 Yes, not only is it possible but it happens to be the most common case: develop on your workstation (Mac, Windows, Linux, doesn't matter) and then push to a production environment. > would I face any problems along the way? That depends on your experience with web application development and deployment as well as how well your ISP supports Python and all other dependencies of your application. Start with the Deployment section under here: http://www.djangoproject.com/documentation/ You can always come back here if you experience any specific problems. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Complicated question
>From what I understand, you want a generic ability to declare an owner item for any model object. Django's generic relations work that way. Take a look at the examples here: http://www.djangoproject.com/documentation/models/generic_relations/ Specially, instead of TaggedItem in that example, you could have an ObjectOwner model class. And instead of TaggedItem.tag you would have TaggedItem.owner_user Your other objects will not need an owner field anymore. They would be like the Mineral class in the example linked above. Hope this gives you a starting point. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: prepopulate_from delimiter
On Nov 20, 1:11 am, Mogga <[EMAIL PROTECTED]> wrote: > great article... very interesting and answered some old questions... > not using it for URLS... > i'm developing some file system mgmt tools for software packages that > don't like hyphens. i'll have to hack the slugifier or create my own > js... You could also override the save method of your model and simply replace all hyphens with underscores there for the slugfield. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using "select_related" .Does it works?
> The docs say select_related() does not follow foreign keys that have > null=True. In your example it would do nothing. > It would. As Samuel points out, select_related's only job is to save you some database trips. The examples I cooked up above will work fine with or without select_related(). In this case, select_related won't save him any DB trips but the image.instrument and image.channel statements would still lead to the related objects (Django will simply make additional DB calls to follow those relations.) You can also get the same DB savings as select_related() by explicitly joining the instrument and channel tables using the .extra method and its tables keyword[1] [1] http://www.djangoproject.com/documentation/db-api/#extra-select-none-where-none-params-none-tables-none --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with date based list_filter in django admin
> Does this have something to do with the autoescape revisions that were > just put out? I'm working off of the latest revision if that's of any > help. Thanks. It's likely. If you've the time, perhaps revert to a revision just prior to when the autoescape changes were committed and report back here if the problem goes away (or even better, open a ticket.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: prepopulate_from delimiter
> is it possible to specify a custom delimeter for the prepopulate_from > option for slugfields? ie. underscore instead of hyphen? > thanks in advance!! The delimiter is part of a hardcoded regular expression used by the "slugifier" Javascript. So, it's not customizable short of providing your own JS or hacking Django's. If you plan on using your slugfields to build URLs, you might want to first read about the virtues of using hyphens in favor underscores: http://www.mattcutts.com/blog/dashes-vs-underscores/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using "select_related" .Does it works?
> > I just want to make a join through this tables with the select_related > to be able to print Image.name, Instrument.name, Channel.name Your query would be something like this: images = Image.objects.select_related() You can use this query set in your templates or in Python: Template example: {% for image in images %} {{ image.name }} {{ image.instrument.name }} {{ image.channel.name }} {% endfor %} Python: for image in images: print image.name, image.instrument.name, image.channel.name > And i don't know how to do this Hope the above helps. Also, you should understand how select_related works. Ot's main purpose is to save you DB trips but it can cause performance problems if not used properly. Read on here for further details: http://www.djangoproject.com/documentation/db-api/#select-related --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: validating fields with newforms
> I would like to validate a field if another field is defined. So i > have two fields (state and state (international) ) -- one of them > needs to be defined. How would i do this with newforms? By adding a clean() method to your form class. See the 3rd cleaning method described here: http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validation --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: add/change user via 'Admin'
On Nov 19, 12:25 pm, Nader <[EMAIL PROTECTED]> wrote: > I have done it: 'python manage.py syncdb' and started the server. I > have got the same error as before. It seems that your content types and permissions got messed up somehow. See this thread for a discussion of a similar problem with some tips by Adrian: http://groups.google.com/group/django-users/browse_thread/thread/2e873fa0309122e/56c2d5277e73d93d?lnk=gst&q=ContentType+matching+query+does+not+exist.+#56c2d5277e73d93d > I'm in development phase but I > wouldn't use the "DROP table' sql statements, because I have to > installed a lot of data again. I thing there has a solution, maybe via > 'model API'! You can always backup your current app data with "manage.py dumpdata". Then after a full reset and syncdb, load it back in with "manage.py loaddata". Moreover, if any of this data is required for your app to run, you can turn it into an "initial_data" fixture (start with the django-admin doc link I included in my previous response.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: add/change user via 'Admin'
On Nov 19, 11:14 am, Nader <[EMAIL PROTECTED]> wrote: > I use the 'Admin' class in my project to do administration of > applications. For the user I have defined a 'admin' and the other > user. If I go to the 'user' page and want to do something with the > 'admin' user and with the other user, I get the next error. I have > read some documents, but I couldn't find the appropriate answer for my > question. > > DoesNotExist at /admin/auth/user/1/ > ContentType matching query does not exist. Have you changed your INSTALLED_APPS setting after you first set it? It looks like you may have added 'django.contrib.contenttypes' later. Try "manage.py syncdb" again, then restart your server. Alternatively, if you are in development mode and don't mind losing your data, start over again by dropping and recreating all tables (See: http://www.djangoproject.com/documentation/django-admin/#sqlreset-appname-appname) and then running a "manage.py syncdb". --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: save() doesn't save a removed parent-child relationship to self?
> > The print self.parents.all() line does print a [] line with self > removed from the parents. Apparently this just does not get saved. Right. The admin always calls the save on the primary object first, followed later by saving the ManyToMany "parents". So, whatever you are doing in your overridden save() is being overridden again by the Admin save manipulator. > Any ideas? 1. Check if the newforms-admin branch has been endowed with anything in that area (especially, in the limit_choices_to attribute of the ManyToManyField.) 2. Use your own form and view to maintain that object instead of relying on the Admin. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Questions about css in templates
> > MEDIA_ROOT = 'C:/Documents and Settings/Nserc2/My Documents/ > mytemplates/media' > > > MEDIA_URL = /mymedia/ > > You also mentioned to activate the appropriate context processor. I > didn't have any TEMPLATE_CONTEXT_PROCESSOR in my settings file to > begin with so I added the lines: > > TEMPLATE_CONTEXT_PROCESSORS = ( > "django.core.context_processors.auth", > "django.core.context_processors.debug", > "django.core.context_processors.i18n", > "django.core.context_processors.media" > ) > > So, I saved settings.py and edited my base.html file to have > > http://localhost:8000/mymedia/css/base.css{% endblock %}" > > in the Once you have the media context processor you can make the above link tag much cleaner like so: That way, when you deploy your app to a production server, you won't have to go back and change that reference to localhost. > > I can view a page that uses base.html fine. The problem that I am > having is that when I view a page that uses my base.html file, it > doesnt have the styling that I laid out in the css file. I think the > problem is how I am refering to the path of my css file. The problem is that there's nothing serving your CSS file :) Again, see the documentation[1] about how to make Django serve static files (like your CSS) from your MEDIA_ROOT and MEDIA_URL settings: BIG DISCLAIMER: This static serving via Django is highly discouraged in a production environment where you are recommended to use a proper web server (say, Apache or Lighttpd) to serve such files. [1] http://www.djangoproject.com/documentation/static_files/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Method 'allow_tags' doesn't work?
On Nov 15, 2:34 pm, wowar <[EMAIL PROTECTED]> wrote: > Today, after updating django to revision 6678 method 'allow_tags' > doesn't work. Despite it is set to True I've got html code. If it used to work previously, this may have to do with the auto- escaping code commit from revision 6671. See the backwards incompatibility update[1] and follow links to other references there. You might also want to revert back to a revision earlier than 6671. If it works that way, it's almost certainly the aforementioned update. [1] http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Auto-escapingintemplates --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: No module named views
Since the error you are seeing is in 'project.app.urls' and the error says "No module named views", it seems that the statement that's failing in / project/app/urls is this one: from voting.views import vote_on_object This would mean that voting.views is not a valid Python module: 1. Is there an __init__.py file in the "voting" directory? 2. Is the "voting" directory in your Python path? 3. Check that /voting/views.py has no errors and that it defines the method vote_on_object. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Deploying Django
> Well, just to know. What are you using? This should also be useful for > my "little" project, the django deployer, still unnamed. I've been using Lighttpd + FCGI on Joyent containers (my favorite production deployment enviroment). In my setups, the Lighty/FCGI combo seems to use server memory more effectively than Apache/mod_python (in my tests. YMMV) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Questions about css in templates
On Nov 15, 6:54 pm, Chris Rich <[EMAIL PROTECTED]> wrote: > Ok, > I just got it to work by using the {% include %} tag. Is this a > fine way to include css stuff or should I not use this for some > reason? Unless your CSS is very short, you should not use this technique because it inserts the entire CSS into the body of your HTML. Thus, a user's browser can not cache that CSS resource. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: No module named views
> > I'm sorry for this long paste.. i could you dpaste. > thanks, martin Yes, it's probably better to dpaste it when you have a lot of code like that. That way, your indentation is preserved and it's easier for others to review your code. I should've recommended it when I asked you to paste here. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Simple save() override not working
On Nov 13, 3:36 pm, "Mike Feldmeier" <[EMAIL PROTECTED]> wrote: > I know, I've seen a million posts about this, but they all seem to relate to > m2m fields. While I do have an m2m field in the table (blog entry <-> > tags), it's one of the simple fields I'm having trouble with. > > def save(self): > > > import datetime > > if not self.publish_date and self.state == 2: > > self.publish_date = datetime.date.today() > > return super(BlogEntry, self).save() > > This override works when in the shell, but not through the admin interface. > I am just not understanding why it would fail on this simple field. You do have a conditional statement there. I would put a couple of debug prints just before that if statement and one inside the if statement to see what's going on. May be the condition is not being satisfied so that self.publish_date is never getting set? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Questions about css in templates
> > > ...but it doesnt like that. I've tried typing in the full path name > and that doesn't seem to work either. You need to define "doesn't seem to work" more clearly. For example, if you request that stylesheet URL from your browser's URL bar, does the stylesheet come up? Also, serving of CSS (or any other static files for that matter) is not automatic in Django. See this for more details: http://www.djangoproject.com/documentation/static_files/ > My template folder path is > indicated in my TEMPLATE_DIRS in my settings.py file for the site. So > my big question is how do I pass the appropriate path for my css to my > template? A good place to store your CSS is in /css/*.css where MEDIA_ROOT is whatever you defined it to be in your settings file. If your settings.MEDIA_ROOT and settings.MEDIA_URL are consistent with each other, you can reference the MEDIA_URL in your template once you activate the appropriate context processor mentioned here: http://www.djangoproject.com/documentation/templates_python/#django-core-context-processors-media --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Flat return list from MultipleChoiceField
> > When there is more than one form B, the posted data for the 'b' field > is flattened. Are the input fields of your two form B's being presented inside one HTML tag? If the answer is yes *and* if the two multiple choice fields have the same "name", then your browser will post all their selected data in a single list. You could control the names of the multiple choice fields by giving each form B a prefix[1]. [1] http://www.djangoproject.com/documentation/newforms/#prefixes-for-forms --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: No module named views
> could someone please point me where to look to solve this? since i'm a > newbie in django, this is probably a stupid question: if i'm getting > no module named views, does this mean that django can't find urls.py > or is it because views.py is empty (everything is in urls.py)? Care to paste here your urls.py file from the project/apps directory? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: custom forms, models and django 0.96
On Nov 9, 12:37 pm, schlam <[EMAIL PROTECTED]> wrote: > I am a developing in django 0.96 and therefor don't have the option to > use form_for_model with fields, so having developed a custom form to > add users to the database am experiencing minor problems with model > validation. > so my form is this : > > > class UserForm(forms.Form): > username = forms.CharField() > first_name = forms.CharField() > last_name = forms.CharField() > email = forms.EmailField() > password = forms.CharField() > > I process the form by > > form = UserForm() > if request.method == 'POST': > form = UserForm(request.POST) > if form.is_valid(): > a=User() > for i,j in form.data.items(): > setattr(a,i,j) > if not a.validate(): > a.save() > > if I remove the validation step, this works fine, how ever trying to > validate raises the error > Exception Value:expected string or buffer > Exception Location: c:\Python25\lib\_strptime.py in strptime, line > 328 Set your application in DEBUG mode and paste the entire stack trace so people can see the sequence of events that are leading up to that exception. Secondly, you should be using form.clean_data instead of form.data. > caused by the validation step... Am i just being thick? Actually you're being thin on the info you've provided ;) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: German dates (with date filter)
On Nov 9, 8:12 am, Florian Lindner <[EMAIL PROTECTED]> wrote: > Hello, > I use this line in my template: > > geschrieben am {{ entry.creationDate|date:"D, j.n.y, H:i" }} > > (geschrieben am == writen at) > > It produces output like "Wed, 26.9.07, 16:49" > > is there any way I can make this output German which means in this case to > print Mi instead of Wed? Have you tried the following? {% load i18n %} {{ entry.creationDate|date:_("D, j.n.y, H:i") }} Note the use of _() around the date format to force a locale sensitive output. See the following doc where it mentions how translation hooks are available inside templates: http://www.djangoproject.com/documentation/i18n/#in-template-code --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: strange custome sql
> > 1. cursor.execute( "insert into popo_status( id , author_id , body , > type ) VALUES (NULL , '1', body, '1') ") > no error, but insert nothing Try committing after that statement: connection.commit() > > 2. cursor.execute( "select * from popo_status where id=21 ") > no error, but ok > > i cannot image no error exist, but i cannot insert data into table. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: "You don't have permission to access /doc/lookup/ on this server."
> > "You don't have permission to access /doc/lookup/ on this server." > > Note that /doc/lookup/ is a URL, not a folder, so there are no > permissions to set. I'm wondering if /doc might mean something special > to Apache? If not then any other ideas? > > My Apache2.conf can be viewed here:http://dpaste.com/hold/24636/ Your apache config imports additional settings from: Include /etc/apache2/sites-enabled/ Look there to see if any config files in that directory may have defined the Location /doc and restricted permissions on it. It's likely that you've installed the apache2-doc Ubuntu package and that it's hooked up to the /doc URL path. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Will there be a django 0.97 release ?
> as far as i understand it, django applications are ment to be > pluggable.. how big are the odds that you'll find two applications > which would work with the same django trunk revision ? I didn't mean that your app would stop working at all on any other revisions. Just that you can "officially certify" that it's known to work with a certain revision (that you've had a chance to test). Your users can still use it with future revisions (see below for more thoughts on this.) > SCT is not (just) meant as a final product which runs separately, but > as applications which can be integrated into a django project.. i > can't force people to use a given revision .. having a release which > holds for 2-4 months would make things easier imho .. Not every new trunk commit creates a backward incompability problem. Furthermore, there are around 4 changes a month that are backward- incompatible (based on the list here: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges) and not all of them affect everyone who's using a trunk release. As an example, the change from FloatField to DecimalField in trunk revision 5302 would only prevent your app from working if your app has models that use that field. Perhaps, you want to consult with other app writers (django-tagging, django-voting, registration, etc.) and see how they handle this issue. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Django Blogs
A lot of the Blogs on the community aggregator are worth following. To me, the B-List deserves a special mention for its valuable tips and tricks -- it's invaluable to newbies, and often has insightful write ups for the seasoned users as well. Thanks, James! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: context_instance needs documenting on the same page as render_to_response?
> This page doesn't even show up on the first page of results so it > isn't surprising people miss it. Worth adding a mention to the docs? Worth opening a ticket too :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multiple arguments to a template filter
On Nov 8, 4:49 pm, jim <[EMAIL PROTECTED]> wrote: > I am writing some custom template filters. How does one transmit > multiple arguments to a filter. eg. > > {{ form.errors|dynamicformfield:"pass",1,"firstname" }} > > my dynamicformfield filter has the following signature: > > def dynamicformfield(value, firstpart, midpart, lastpart): > > I always get a error saying that the filter expects 3 args and I am > sending in only 1. Filters always take either one or two arguments but not more. See: http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters Here's how you can pass in multiple parameters. Change your filter function to take in just one real parameter that multiplexes three comma-separated parameters: def dynamicformfield(value, parts): firstpart, midpart, lastpart = parts.split(',') # you've got your three parameters now to run with The filter usage would be: {{ form.errors|dynamicformfield:"pass,1,firstname" }} In other words, you specify all 3 parts as a single string with comma- separated values that you can then demultiplex in your filter function. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Will there be a django 0.97 release ?
> > So are there any plans on releasing a 0.97 ? I hope you understand my > concerns - django is really great and the trunk is stable but I understand the concern, but how does having a 0.97 release change this for you? There would still be potentially backwards-incompatible changes moving forward from 0.97 to the next official release. If you just want to be able to announce which snapshot of the Django trunk your application supports, you could point to the svn release number (e.g. app supports Django trunk svn release #6650 and that future releases are not guaranteed to work.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with "auto_now_add" in Admin interface
On Nov 8, 2:17 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > Here's a ticket that looks like it describes your problem: > > http://code.djangoproject.com/ticket/1030 > > It's still open but it looks like the last comment might provide a > workaround, depending on the version of Django you are running. Just a note: the code in that last comment in this ticket has a bug: default=datetime.now() should be replaced with default=datetime.now --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: AUTH_PROFILE_MODULE usable with v0.96?
On Nov 7, 6:46 am, paulc <[EMAIL PROTECTED]> wrote: > I'm trying to follow the example in the Django book, to make a simple > extension of the standard User object. > > I'm hoping someone may be able to give me a quick yes or no on this: > is the AUTH_PROFILE_MODULE setting expected to work with Django 0.96, > or do I need to upgrade to the SVN release? I have a couple of sites on 0.96 where it's been working without a problem. > > Within a very simple view that I'm using just to try this out, I can > pick up the User object and access some of its fields (e.g. username) > and custom methods (e.g. is_authenticated); but if I call the > get_profile() method, I see the following error: > > Exception Type: AttributeError > Exception Value:'NoneType' object has no attribute > '_default_manager' > > I'm pretty sure I have AUTH_PROFILE_MODULE set correctly (I do not get > the `too many values to unpack' error). > > I do not see the SiteProfileNotAvailable error, which again seems to > suggest I have all the necessary middleware and settings present in > the configuration. Actually, it would help if you would paste here your AUTH_PROFILE_MODULE setting as well as your profile model class. Also, what Django app name does this profile model live under? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: site is built with django, but my server doesn't know that...
> Here is what I do and > what it all looks like: > > log in as [EMAIL PROTECTED] > > [EMAIL PROTECTED]:~# python > Python 2.5.1, Ubuntu 4.1.2 etc. etc. > > So Python is installed and I've opened the interpreter, right? > > Then this: > > >>> import django [to verify that django is installed] > > and I get > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named django > This just means that django is not in your PYTHONPATH. If your server is already running the original Django app, it means that Django is installed. Take a look at the installation documentation to learn more about setting up your PYTHONPATH and other environment. http://www.djangoproject.com/documentation/install/ Also, as an aside, try using some kind of source control (subversion, for example) so that you avoid changing your production source code directly on your production server. A better way to do this is to change things on your development/test environment, test it there, commit your stable changes to a source control repository and then grab and install them on your production server from the repository. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Does anyone know a good method for creating one time pages with Django?
On Nov 7, 10:11 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Thanks, flat pages look really useful. > > Unfortunately I don't think they solve my problem here - the rest of > the page needs to be dynamic and driven by custom content; it's only a > subset of the page elements that I want to be static in this way. Actually, you could use the flatpages model for this if not the whole Flatpages application. Here's how: Have your end users enter their text in a flatpage with the URL say '/ homepage_text/'. In your view that builds the full homepage (dynamic + static), make an explicit query to get the flatpage text: from django.contrib.flatpages.models import FlatPage static_text = FlatPage.objects.get(url='/homepage_text/') Pass this text on to your template along with your dynamic parameters. If your user entered text is really a bunch of properties and such, you may be better off creating your model to capture them. In short, you can treat the FlatPage model as a storage for elementary key, value type properties with a key being FlatPage.url and a value being FlatPage.content. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form_for_instance and form argument, empty form?
> > > Paste here your FooForm and Foo model code that doesn't work for you. > > class Foo(models.Model): > title = models.CharField(_("Title"), core=True, maxlength=100) > > class FooForm(forms.Form): > title = forms.CharField(label = _("Title")) Now, I am more confused about your actual problem. You say in the original post that when you use FooForm as a base "form" parameter in form_for_instance, you don't get fields from Foo. But in the code above, both FooForm and Foo have the same field named 'title'. In such a case, you wouldn't need to use the form=FooForm parameter at all. Just form_for_instance(foo) and form_for_model(Foo), would work. Here is an example of using a custom form base class that is intended to add a new field to the set of fields that are created from the Foo model. Notice how this adds the new field 'another_title' in the __init__ method instead of adding it as a class field: class FooForm(forms.BaseForm): def __init__(self, *args, **kwargs): super(FooForm, self).__init__(*args, **kwargs) self.fields['another_title'] = forms.CharField(label = _("Title2")) More details here: http://www.djangoproject.com/documentation/newforms/#using-an-alternate-base-class --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form_for_instance and form argument, empty form?
On Nov 7, 9:42 am, David Larlet <[EMAIL PROTECTED]> wrote: > I thought that it was more appropriated to post it on the devlist > because it sounds like a bug but ok let's move it on the userlist, sorry > for the noise here. I'll be glad to hear your solution. Paste here your FooForm and Foo model code that doesn't 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Does anyone know a good method for creating one time pages with Django?
> However this seems messy > and I feel like I'm working against Django. Is there a better way of > doing it? Consider using "flatpages": http://www.djangoproject.com/documentation/flatpages/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: permissions on media files
> So is my only solution to read and serve the file > using django ? Or is there a mod_python extension that can do this > more efficiently ? Perhaps Amazon S3 would serve your needs? http://www.amazon.com/gp/browse.html?node=16427261 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newforms validation error not displayed:
> > def clean_guess_the_number(self): > if self.max_number > self.cleaned_data['guess_the_number']: Change that to: if self.max_number < self.cleaned_data['guess_the_number']: > raise forms.ValidationError('Your Number have to be lower > or equal to Max Number.') > if self.min_number < self.cleaned_data['guess_the_number']: And this one to: if self.min_number > self.cleaned_data['guess_the_number']: > raise forms.ValidationError('Your Number have to be higer > or equal to Min Number.') > return self.cleaned_data['guess_the_number'] > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: encoding problem in instance signal / dispatcher?
Take a look at your Tag model's __unicode__ method (or paste your Tag model here). I suspect that's where the problem is. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: i18n and choices from database
> Question is how to show query from database on template with localized > output Try this in your template (assuming p is a person model instance available to your template): {{ p.get_gender_display }} See: http://www.djangoproject.com/documentation/db-api/#get-foo-display Also, another suggestion: consider using more intuitive keys for your gender field instead of 0, 1. You could define it as a CharField and change choices keys to M, F instead of 0, 1 (or even better "male", "female"). If you're worried about performance, you can even set db_index=True on the gender field. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a simpler solution?
Disregard the overflow:hidden piece in my CSS above. It's not needed: .article {width:32%;float:left;} .clear_all {clear:both;} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a simpler solution?
On Nov 2, 4:05 pm, "Ramdas S" <[EMAIL PROTECTED]> wrote: > Hi, > > I am sure there is something absolutely simple, but I guess I am missing it. > I need to display some content/ news articles over 3 columns on a home page, > where the order is latest stories coming in top rows from left to right. If > you've seen web sites like theinquirer.net or theregister.co.uk you will > understand what I mean! > > I was searching for a solution that is a lot simple, like a template tag > which will let me implement this easily. But I have not found one. Have you considered using plain CSS floating boxes? Here's some hastily put together snippet: Your template: -- {% for a in articles %} render article a here {% if forloop.counter1|divisibleby:"3" %} Ā {% endif %} {% endfor %} Your CSS: -- .article {width:32%;float:left;overflow:hidden;} .clear_all {clear:both;} Experiment further to make things look nicer from here ;) -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Limiting Foreign Key choices to members of a certain group using generic views
> > # run with this form following the examples in the newforms > documentations. You can also change the domain "choices" after the form class is created for you by modifying the form class's base_fields as I see you have done in your post in another thread here: http://groups.google.com/group/django-users/msg/b2c960e64a06b666 The callback method pattern I mentioned above is still nice to know as you can do many other customizations that way as the form class is being created instead of later. Cheers, -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Limiting Foreign Key choices to members of a certain group using generic views
On Nov 2, 4:02 pm, rm <[EMAIL PROTECTED]> wrote: > On Nov 2, 3:54 pm, RajeshD <[EMAIL PROTECTED]> wrote: > > > When you acquire a Customer newform instance in your view, you will be > > able to modify the choices attribute of its domain field so that these > > choices only contain the relevant domains that you mentioned you can > > trivially derive knowing the request.user. > > Could you give an example of how to do this? That sounds like what I > am after as well. Sure. But I will assume that you've read the newforms documentation or will be reading it to continue with the starter code below: # First create a form call back that will allow you # to have our custom choice field on the domain field class CustomDomains(object): def __init__(self, queryset): self.queryset = queryset def __call__(field, **kwargs): if field.name == 'domain': # the following single line is the whole point \ # of the solution we are building return forms.ModelChoiceField(queryset=self.queryset) else: return field.formfield(**kwargs) # The following goes into your view # Scroll down to "def contact_edit(request, msg_id)" in the newforms docs for # the general idea of this view. # http://www.djangoproject.com/documentation/newforms/#form-for-instance # create a queryset that contains # your domain choices for the request.user your_list_of_reseller_ids = [left for you to populate] valid_domains = Domain.objects.filter(reseller__id__in=your_list_of_reseller_ids) custom_domains_callback = CustomDomains(queryset=valid_domains) if your_customer_instance is not None: # we are in update mode CustomerForm = forms.form_for_instance(your_customer_instance, formfield_callback=custom_domains_callback) else: # we are creating a new customer CustomerForm = forms.form_for_model(Customer, formfield_callback=custom_domains_callback) form = CustomerForm() # run with this form following the examples in the newforms documentations. Note: I have not tested the above for errors but have used similar patterns in my own code with no problems. Also, please mind the indentation. If GoogleGroups screws it up, I hope you can put it back together. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Limiting Foreign Key choices to members of a certain group using generic views
> > I'm after a way of limiting what choices are populated into a drop-down > box from a foreign key field when I'm using the generic create/update views: I would recommend not using the generic create/update views as those views use old forms and manipulators which are going away in favor of "newforms". Take a look at the newforms documentation here: http://www.djangoproject.com/documentation/newforms/ In particular, read the sub-sections on "form_for_model" and "form_for_instance" which will let you get handy newforms instances that can respectively create and update a Customer record. > > What I am trying to achieve is to be able to limit the list of domains > that a reseller can apply to their customer objects to domains that they > have control of: When you acquire a Customer newform instance in your view, you will be able to modify the choices attribute of its domain field so that these choices only contain the relevant domains that you mentioned you can trivially derive knowing the request.user. > I think I need to be able to resolve the logged in username into a list > of groups (which I can do with request.user.groups) and then resolve > that into the list of resellers and then resolve that into a list of > domains. I don't think I can access the request object from the model can I? Its possible to do this through a hack that (http://lukeplant.me.uk/ blog.php?id=1107301634) but it's not a good practice to closely couple your view code (i.e. the request object) with your model code. You won't need to resort to this anyway if you are willing to write your own newforms based view suggested above. -Rajesh D. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying error messages if form data not valid
On Nov 2, 12:08 pm, jim <[EMAIL PROTECTED]> wrote: > OK. This approach works. Thanks. > > Would you have any link to a best practice where such a approach is > detailed? The very first simple view example in the New forms documentation shows what Malcolm recommended to you. http://www.djangoproject.com/documentation/newforms/#simple-view-example --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: template question
On Nov 1, 9:56 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have this code in my view, for example: > > a=['a','b','c'] # a list of row labels > b=[1,2,3] # a list of col label > c=tab # an array (list of list) with len(a) rows and len(b) cols. If c[i, j] previously had a value of x, change it to have a tuple of the form: c[i, j] = (x, a[i], b[j]) Thus, each c element now has its own value as well as its 'a' and 'b' labels. > then on the template side, it's easy to print c > {% for row in c %} > > {% for col in row %} > {{ col }} > {% endfor %} > > {% endfor %} Change: {{ col }} to {{ col.0 }}, {{ col.1 }}, {{ col.2}} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Standard place for signal processing code?
> I'm looking for a hint as to where put signal processing code. Various > objects in many apps in my project emit one signal, that has to be > processed in single place and is not directly related to any particular > app nor object. I do not want it in any app, since apps can be turned on > and off, eventually making the signal to go unprocessed. I know the > module that contains signal processing code has to be already imported > to be able to run the code. What is the standard practice in such case? > Separate app? Or...? I would create a module called 'common' under the project and have a signalhandlers.py there to hold your signal processing code. This Python module doesn't need to be a Django app but if it is, you could also keep your globally used templatetags and template files in there (for example, in /common/templatetags/commontags.py and /common/ templates/ respectively.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django newbie, URL resloving problem
On Nov 1, 7:26 am, gizmo <[EMAIL PROTECTED]> wrote: > Hello, > I started learning about Django and I followed an example > athttp://www.djangobook.com/en/beta/chapter03/ > > I've done: > from django.conf.urls.defaults import * > from gizmo_site.datetime import current_datetime This suggests that you have a Django app called 'datetime'. I would recommend renaming it as Python has a built-in 'datetime' module. It may be possible for the two to co-exist, but the error you are seeing (django.contrib.auth: 'module' object has no attribute 'timedelta') is because Django is looking for the Python built-in datetime module's timedelta function and it encounters your module of that name instead which has no timedelta function (and even if it did, it would be the wrong one.) Jakub already explained why your URL match is failing. Hope the above helps too. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using newforms, an uncommon case.
Here's a different approach: You could serialize an incomplete form instance to another table (could just be serialized to the user's session too.) Then, when the user requests to continue filling out an incomplete form, just deserialize the form instance and you have the form exactly as the user last left it. This allows you to have the right "required=True" values and other validation rules on your core model keeping it clean and not having it serve double duty. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: bypassing reverse relation (related_name)
> > Is there a way to express that I don't need the reverse relation? No. Even if you don't need them, Django will want to dynamically endow your Location objects with them. And, as you know, it can't do it if two reverse relations have the same name. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom Managers and Model Methods
Hi Jason, > Using the models below I'd like to be able to create Querysets such as: > > a = Treatment.objects.filter(total_dose__range=(4000,1)) > b = a.filter(tumor__patient__gender = 'M') > > Both of the above work, but then I'd like to have an additional filter: > c = b.filter(tumor__patient__get_followup_length__gt = 5) This is not possible because get_followup_length is not a field in the DB table but a model class method and Django doesn't support that (because it can't build a SQL statement out of this queryset definition.) Here are some alternatives: Option #1. Add a followup_length field to your Patient model. Rename the method get_followup_length to compute_followup_length and change it so that it stores its computed value into the new followup_length field. Then, call compute_followup_length() from delete() and save() methods in Tumor. In other words, everytime Tumor is changed, its Patient's followup_length gets computed. You can also achieve this via signals if you don't want to override Tumor.delete() and Tumor.save(). See: http://code.djangoproject.com/wiki/Signals Option #2. Filter the result set in memory using standard Python: c = [x for x in b if x.tumor.patient.get_followup_length() > 5] Note that, if you expect c to have a lot of rows, this will load them all in memory. And, obviously, c will be a list rather than a queryset. Hope this helps. -Rajesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newform: Why Doesn't This work
Aaargh...the indentation got screwed up. Here's another attempt: class myForm(forms.Form): def __init__(self, *args, **kwargs): self.q_prime = [] # default choices here? try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) self.fields['choice'] = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newform: Why Doesn't This work
class myForm(forms.Form): def __init__(self, *args, **kwargs): try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) choice = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I As Joe says above, the choice field is a class-level field whereas "self.*" is instance level. So, this doesn't work. Try this instead: class myForm(forms.Form): def __init__(self, *args, **kwargs): self.q_prime = [] # default choices here? try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) self.fields['choice'] = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I Note the indentation of that last line -- it now belongs to the __init__ method and not to the class. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: problem in uploading image
> > if form.is_valid(): > clean_data = form.clean_data > t = Image If Image is a model class, the above should read: t = Image() > > but it is showing an error saying 'module' object has no > attribute 'save_photo_file' --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Fastcgi always gives 301
On Oct 15, 10:23 am, maqr <[EMAIL PROTECTED]> wrote: > Does anyone have any suggestions as to why this 301 MOVED PERMANENTLY > is the only response I can get out of my FCGI script? Did you follow the official FCGI docs over here? http://www.djangoproject.com/documentation/fastcgi/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: select choices
> > Arn't stings slower against integers? You can always set db_index=True on the type field if you'll be using it a lot in your lookups and if the number of records in that table is going to be huge. http://www.djangoproject.com/documentation/model-api/#db-index --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multiple app environments on the same machine - settings & more
> The idea is I would like to set up a production (prod) and pre- > production (preprod) and have preprod updated and unit tests run > everytime I commit changes to the SVN repo from my local machine (this > can be easily done with svn-hooks). > > No problems so far, however what worries me is how to solve the > settings riddle - I would like to have them dynamically imported > depending of which environment (in this case it's simply another > directory on my webserver) it is run on. > > So I had the concept to tag each environment with some marker file > like "__DEV", "__PREPROD", "__PROD" and import specific settings from > inside the main settings.py, depending on which tag-file exists in my > cwd. Didn't succed, but wait, there's more. As I said, each > environment is configured to different directory, so I have symlinks > to site-packages/myapp for PROD (which is myapp.com:80) and site- > packages/myapp_preprod for PREPROD (myapp.com:8080). > Then I realised, that even if I get the dynamic-import issue solved, > the preprod app will work with hardcoded "myapp." module instead of > "myapp_preprod." for views dispatching (urls.py). > > Are there any hacks or, preferably, some simple and obvious > solutions ;-) to accomplish my goal? May be this is simple enough (if I understand your problem correctly ;) 1. Don't add myapp_* to site-packages at all. Instead keep them in two directory roots say /home/apps/prod and /home/apps/preprod. Similarly, you can have two different settings files for the two environments. 2. In your Apache vhost config for myapp.com:80, add /home/apps/prod to the PYTHONPATH setting. And, for myapp.com:8080, add /home/apps/ preprod. See these two sections in the Django deployment documentation: http://www.djangoproject.com/documentation/modpython/#basic-configuration http://www.djangoproject.com/documentation/modpython/#multiple-django-installations-on-the-same-apache --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: select choices
> Does anybody know a more easy way? Any particular reason you have to have type as an IntegerField? If you had it as a CharField, you could do: TYPE = (('foo', 'foo'), ('BAR', 'BAR')) type = models.CharField(choices=TYPE) Foo.objects.filter(type='BAR') And, possibly add db_index=True to the type field. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newforms problems
> 1) pass_matched always return False > how can i compare two fields in my class??? def pass_matched(self): if self.fields['pass'] == self.fields['repass']: return True else: return False 1. use self.cleaned_data instead of self.fields 2. call pass_matched from a method called clean in your form or rename the method pass_matched to clean_repass See this for details: http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validation --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Accessing many-to-many relations in save()
On Oct 12, 1:04 pm, Adam Endicott <[EMAIL PROTECTED]> wrote: > > How about something along these lines (a lazy initialization pattern): > > Well, the point of saving that boolean was so I could do database > queries on it (MyModel.objects.filter(has_m2m_thing=True)). That > wouldn't really work with this lazy initialization pattern, unless I'm > missing something. No, you're right -- that won't work. > Sorry, I guess I should have mentioned that. No problem. I had assumed that you needed the boolean in a template or a view. I don't think there's a clean solution to this (as far as making the Admin work with it). I don't think the admin can make use of a custom manipulator without hackish code. If you are open to patching Django itself, you could add a custom signal to django.db.models.manipulators.AutomaticManipulator.save() to transmit a "post_full_save" signal at the very end of that method call. That would give you the appropriate hook you need. Another idea is to use a database trigger on the m2m table to update the count/boolean field on the parent table. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Accessing many-to-many relations in save()
> Sure. I'm trying to set a boolean property on the object based on the > existence (or absence) of a ManyToMany relationship. So I originally > thought something like: > > def save(self): > self.has_m2m_thing = bool(self.m2m_relation.count()) > super(MyModel, self).save() > > This works fine if you save it twice, but that's not the behavior I > was looking for :). Right. How about something along these lines (a lazy initialization pattern): 1. Change MyModel's has_m2m_thing to m2m_count and make it an integer field and default it to -1. 2. Add a method and property to MyModel: def _has_m2m_thing(self): if self.m2m_count == -1: # compute count self.m2m_count = self.m2m_relation.count() super(MyModel, self).save() return self.m2m_count > 0 has_m2m_thing = property(_has_m2m_thing) 3. Add this to MyModel.save() def save(self): self.m2m_count = -1 # reset count super(MyModel, self).save() Caveat: This doesn't work if you add or remove your m2m objects outside of the Admin (because MyModel.save() won't get called so the m2m_count won't get reset.) You will have to explicitly reset m2m_count in such cases by calling MyModel.save(). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Accessing many-to-many relations in save()
On Oct 11, 6:54 pm, Adam Endicott <[EMAIL PROTECTED]> wrote: > I've got an app where I'd like to set some properties in an object's > save method based on ManyToMany relationships. Can you describe generally what you are trying to update in the parent object when its ManyToMany relationships are changed. Perhaps there's a way to solve your specific problem without requiring more general purpose solutions (like Custom Manipulators). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Possible ifequal and/or ifnotequal bug
> > The above code is NOT catching the first instance of an NAICS > description which begins with "A". The filter on the first parameter there won't work (as you've already discovered.) 1. If you are using Django SVN trunk, try assigning that filtered value first to a variable using the 'with' templatetag: http://www.djangoproject.com/documentation/templates/#with 2. Another, probably simpler, solution is to use CSS to hide that first "Back to the top" link like this: Back to the topĀ Then, in your CSS add: a.letter-A {display:none;} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Signals error - I can't do a import
Perhaps try the import this way: // sig.py def thesignal(sender, instance, signal, *args, **kwargs): from mysite.plush.models import Photo assert False, "It got here" // --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Random objects in view
Hi Alessandro, Replace: items.filter(provincia__iexact=provincia) with items = items.filter(provincia__iexact=provincia) Similarly, replace items.filter(tipo__iexact=tipo) with items = items.filter(tipo__iexact=tipo) Remember that whenever you filter an existing queryset in order to progressively develop a query, you get a new queryset. So, you need to assign it back to a variable otherwise it's lost in the ether :) -Rajesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: sharing django on production and dev
Hi, On Sep 28, 1:46 pm, Milan Andric <[EMAIL PROTECTED]> wrote: > Is there some standard practice on a machine that has production code > running in mod_python but also has developers running their django- > python web server? Is that discouraged? Yes absolutely discouraged. The standard practice is to not have development code and environment on the same machine that also happens to be your production machine. Developers tend to do weird things on their setups -- some which can crash your production app. Developers also need to have an environment where they don't need to tip-toe around their environment; they should be able to experiment with new versions of libraries, Django, etc. Having a shared prod/dev setup completely defeats that. > I figure a regular user > would not share the same django with mod_python because of .pyc files > and permissions? So developers would maintain separate django > installs. This makes it difficult because then they can't develop > using the same python or need to override the library path? - Have a separate development machine or have each developer use her own workstation along with Django's built-in web server for development. You could have a shared development machine too (but don't mix it with production). Linux is great for that. Each developer can setup their own Python path if they need to. They can also start with a default Python path and override only those libraries that they need a specific version of. - Use subversion or another version control system to manage and share code between the devs. - Have a staging machine or a staging environment on one of the dev machines. The staging should mimic the hardware and software on the production server as closely as possible. When an app release is ready for production, install it on staging first and make sure things work OK. - Of course, it's highly recommended to have a quality test plan for your setup too. > > Seems like the appropriate configuration is for production to have a > django and developers to each have their own django. Yes. And to be even clearer, the production should be on a machine that's isolated from the development machine(s). > Then the > developers would just modify their python include path to include > their copy of django? Right. > Is there a simple way to do this or do most > developers just choose to have their own dev environment running > locally? Most developers doing serious amounts of work would want their own environment, yes. They don't want to be tripping on another dev's work on the same machine. Again, use version control to share code updates between devs. > Does this discourage sharing of a dev server and hence more > admin work for everyone instead of one stable dev environment. Not at all. Most open source successes come from each dev being able to code away on their own favorite machine and when they feel they have a worthy release, they check it into a common source repository. That's a more established way of collaborative development. > Looking for answers since I'm still pretty new to Django and python. Most of this is standard stuff even for non-Django development, but I hope this helps anyway. -Rajesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Signals not working correctly
On Sep 13, 11:13 am, Greg <[EMAIL PROTECTED]> wrote: > Hello, > I'm trying to use signals so that when a Publication gets deleted from > within the Admin it will 'assert False, "Here"' (This will obviously > change at a later date). Currently, when I delete a Publication (in > the django admin) no assert statement is raised. So I guess that > means that my dispatcher.connect is not getting called. Anybody know > what I'm doing wrong? Try moving the dispatcher.connect statement to your models.py. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form_for_instance + user profile
> > Basic example: > > user = User.objects.get(id=1) > user_profile = user.get_profile() This should work if you have settings.AUTH_PROFILE_MODULE pointing to your UserProfile model. See: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-voting question
> > Problem is, I can't manage to do anything with posts in my template. What exactly are you trying to do that's not working? > When I view source, I see an object reference, so I know it's getting > there, and I know this is probably a terribly dumb question, but how > do I access posts? How about something like this: {% for p in posts %} {{ p.headline }} {{ p.body }} {% endfor %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Decoupling templates
> How can I decouple my templates to an app specific directoy? The way that my > apps are self contained also regarding their templates? That feature is built in to Django. Create a templates sub-directory in your app directory and place your app specific templates in there. Look at the the django.contrib.admin app directory for an example. For this to work, you will need to make sure your TEMPLATE_LOADERS setting includes: django.template.loaders.app_directories.load_template_source See: http://www.djangoproject.com/documentation/templates_python/#loader-types --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: data manipulation in templates or views?
> I hope I am not inviting a quasi-religious war > on this issue, but I am wonder if people could provide some insight on > when or why I should do this sort of thing within the template (via > template tag or not) or if I should continue doing that within the > view, which not only currently makes sense to me, but I think is what > the official documentation suggests. In real life, not all applications are created equal. Think about categorizing your "data manipulation" needs: - manipulations involving DB updates, traversing relations, incremental query set build-up, and generally complex work. I would most definitely not do these in a template. - manipulations that don't make DB updates: translation of a field's value to a different language, simple excel like calculations, conversion of a queryset value to a logged-in user's currency, and other "lightweight" work. These could be done either in a view or in a template using custom templatetags. Generally, you can make a case for a templatetag if you are going to be able to use it in several independent templates (say, a currency conversion tag.) If your manipulation consists of transforming a field purely for the sake of rendering it on screen, consider doing it in a template. There is no single correct answer to this. But there's usually a natural way to make this decision for every individual case; a solution that "feels" elegant (not-hackish), simplest, and most maintanable. If in doubt, post a specific usecase here and get some recommendations on what would be best. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: User Administration
> > please have a method to add one user to a specific group? Try this: grp = Group.objects.get(name='registered') us.groups.add(grp) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: hidden fields
On Sep 7, 9:55 am, Ana <[EMAIL PROTECTED]> wrote: > Hi, > I'd like to have "last modified by" and "owner" fields in my > application. I'd like to set fields value automatically, and I want > those fields to be hidden. Is there any way I can do that? Yes. Here's one way to do it: Add those two fields to your model and set editable=False on them so they don't show in the Admin. Override your model's save method and set "last modified by" to current time i.e. datetime.datetime.now(). Also set the owner to the request user. Here's an article on how to get request.user using a custom middleware: http://lukeplant.me.uk/blog.php?id=1107301634 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Storing Lookup Data
> > It seems like the Choice table is easier on the user. You tell them > to go to the Choices table to enter all the look-up data, as opposed > to giving them X tables to wade through. As you said, it is probably a DB design question -- even within a single project, you might need to use both approaches. My $.02: If you need special validation based on the type of the lookup data, the separate tables option works better. You can still make them go to one screen to manage all the lookup data (you're just going to have to build that screen yourself ;) Also, if you want foreign key relations to the choice data, separate tables might work better. I would personally never mix person name prefix data with a list of states in the same table even if you have a "type" field to qualify such data. To me, that kind of user convenience is not worth the loss in data integrity because one can always unify those lookups in a user- friendly UI. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using querysets to populate a form
> I have a requirement to use querysets as choices in various elements > of a form, and as the data grows this is clearly going to have a big > hit on the database every time this form is loaded. Can anyone think > of a way around this? Is there a way to cache the query set and only > update it every so often? Has anyone done anything similar? You can always turn the queryset into a list and cache it with Django's caching framework. However, that doesn't solve the usability issue of a huge drop-down list. A few options: 1. Do what the Django raw_id_admin interface does (http:// www.djangoproject.com/documentation/model-api/#many-to-one-relationships). It uses a popup-window in which the user sees the set of available options (they could be paginated if it's a big list); clicking a row results in its pk being fed back to the parent field being selected. 2. ExtJS (and possible other Javascript) libraries provide fancy AJAX based interfaces that let you load a custom drop down list on demand as the user scrolls down. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: unique_true option of the fields works as case-sensitive, how can we make it case-insensitive?
On Sep 4, 9:28 am, parabol <[EMAIL PROTECTED]> wrote: > When I mark a field as unique_true is works as case-sensitive and does > not catch something like "problem" and "Problem". What is the correct > way of making it case-insensitive? Thus it will catch even "problem" > and "ProBLem". > > I tried to override the save() method, but this time the thrown > exception (Integrity Error) is not catched by the admin form. > > What do you suggest? 1. Use a custom validator (you will need to make a DB call within your validator to look for the existence of another record with the field value in question) 2. Add a SlugField to your model, define it to be unique, and prepopulate it from the field that's supposed to be case-insensitively unique. Then, you will get the right validation errors in the admin (but they will be shown against the slug field.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: overriding save, non-admin error
On Sep 4, 7:18 am, canburak <[EMAIL PROTECTED]> wrote: > I have a problem on overriding the save() method. > my new save is: > class ClassName: > def save(self): > self.title = self.title.title() > super(ClassName, self).save() > > when admin site uses this save(), I get the non-unique exception at > django/python level but I hope to see a red box in the admin. How can > I do that? You will need to add a custom validator to the title field of your Model to check for uniqueness of its titlecased version. The admin will check for uniqueness of self.title but it doesn't know that you are titlecasing it later in your Model.save. So, it won't know that the title "canburak" is not allowed even if you already have a record with the title "Canburak" (before the Admin hits the save method, those two strings look different to it.) Another option is to add a slug field to your model, prepopulate it from title, and make it unique (that will give you case-insensitive uniqueness which you may or may not want.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom template tags within a textarea field
On Sep 5, 12:03 pm, MichaelMartinides <[EMAIL PROTECTED]> wrote: > Hi, > > Just to be sure. > > If I have custom template tags within a TextAreafield of a model. I > would do something like to following: > > def view(request, page): > p = Page.objects.get(name=page) > t = Template( p.content ) > content = t.render() > return render_to_response('page.html', {content:content}) > > right? Right. Some gotchas to watch for: - If your template needs a context, be sure to call t.render with the context dictionary - p.content would've to be a self-contained template i.e. it should "load" the template tag libraries it needs like you would with a standard html template. Alternatively, you could add your custom templatetags to the built-in tag libraries using django.template.add_to_builtins. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Translating strings with placeholder in template
> I think this would work with Python code. However, can I do the > translation in Django's Template language? If so, how? See blocktrans: http://www.djangoproject.com/documentation/i18n/#in-template-code In short, you would use: {% blocktrans %}login.before.you.proceed {{ login_url }}{% endblocktrans %} The .po file would be exactly what you have above: msgid "login.before.you.proceed %(login_url)s" msgstr "Please Login before you proceed" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: forms, views and foreign key
> -- > so.. the problem is: > > Request Method: GET > Request URL:http://127.0.0.1:8000/profile/ > Exception Type: AttributeError > Exception Value:'Profile' object has no attribute 'get' > > what's wrong? :( > What line of code are you getting this error on? Can you paste the stack trace as well? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multi page article
I would second Michael's suggestion to use a page break marker. I have used that in many instances with great succcess -- your content admins will thank you :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: site/section/app
1. You could use a GenericForeignKey in your 'App' model: http://www.djangoproject.com/documentation/models/generic_relations/ Quote: "Generic relations let an object have a foreign key to any object through a content-type/object-id field. A generic foreign key can point to any object, be it animal, vegetable, or mineral." 2. App could have two nullable ForeignKeys (Site and Section). Then you would need validators that require that one of the two must be not- NULL for every record (and, if it makes sense, disallow both having a NULL value.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: queryset cache
On Aug 22, 10:21 am, sean <[EMAIL PROTECTED]> wrote: > That's the problem, I don't know how to cache the queryset. > But for what it's worth, here's something i tried. I tried to take > advantage of the default caching of querysets, but that doesn't work > here. > > mediaform = CustomMediaForm > # get the initial queryset fo a large table > qs=mediaform.base_fields['somefield'].queryset You could just evaluate this query set once and turn it into a list of tuples: my_choices = [(o.id, o.name) for o in qs] Then use my_choices in all your forms in the below loop. > > forms = [] > > for i in requested_forms: > form=mediaform(data, auto_id="some_generated_id") > # assign the queryset to the choices > form.base_fields['somefield'].queryset = qs That would become: form.base_fields['somefield'].choices = my_choices > forms.append(form) > > And yes, I know it's hackish and not nice at all ;-) Another option is to define your queryset outside this view method rather than fetching it from form.field.queryset that you do above. That way, the same instance of the queryset gets used in all the forms you build in that loop. How many choices does the queryset return on average? Is it a huge drop down list? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: queryset cache
On Aug 22, 8:08 am, sean <[EMAIL PROTECTED]> wrote: > Hi all, > I'm running into a performance problem with some pages i created. The > page has multiple forms, which are all the same, with the exception of > the initial data (it's a kind of batch insert functionality), but all > foreign keys and such are identical (and as such lead to the same > querysets, that populate the select fields). > > the view code looks like this: The form code snippet doesn't show how you are caching the querysets. Consider pasting in your form class in its entirety so we can help you. -Rajesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---