Re: value for choices arguments for newforms.MultipleSelectField

2007-08-02 Thread Nathan Ostgard
You can use ModelMultipleChoiceField for this: items = newforms.ModelMultipleChoiceField(queryset=Items.objects.all()) On Aug 2, 1:24 am, james_027 <[EMAIL PROTECTED]> wrote: > hi > > somewhere on the django documentation I saw the choice provided for > MultipleSelectField is from a Database but

Re: Admin & Models

2007-08-02 Thread Nathan Ostgard
list_display can use functions as their value... so, you can have: class Employee(models.Model): sub_dept = ForeignKey(SubDept) def company(self): return sub_dept.dept.company def dept(self): return sub_dept.dept class Admin: list_display = ('first_name, 'last_name', 'compa

Re: How do I echo template variables?

2007-07-30 Thread Nathan Ostgard
Try: {{ data|pprint }} On Jul 29, 10:42 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm coming from CakePHP and I would typically set a variable for use > in my view with a call to findAll. Since there is a lot of data in the > array, I typically do something like: > > > > > > This wa

Re: Is there any way to associate a view with a template?

2007-07-28 Thread Nathan Ostgard
I could be wrong, but I think the problem he's having is having to specify the menu variable in the context for every view, not the template end of it... To fix that, you will want to check out context processors: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-re

Re: Looping through my POST data?

2007-07-28 Thread Nathan Ostgard
To illustrate with the Python shell: >>> 0 == "0" False >>> 0 == int("0") True On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote: > On Jul 27, 2007, at 10:36 PM, Greg wrote: > > > AssertionError at /rugs/cart/addpad/ > > [u'0'] > > > Does that mean that the value is 0? below is my view

Re: ifequal not working?

2007-07-28 Thread Nathan Ostgard
ifequal can't do filters, unfortunately. But you can do this: {% for item in menu_items %} {% if forloop.last%} class="last-item"{% endif %} {% endfor %} Or class="{{ forloop.first|yesno:"first," }} {{ forloop.last| yesno:"last," }}" On Jul 27, 11:42 pm, Eloff <[EMAIL PROTECTED]> wrote: > T

Re: Looping through my POST data?

2007-07-27 Thread Nathan Ostgard
request.POST is a dictionary, not a list, so a for loop like yours is iterating over the keys of the dict. to get the values, you can do: for value in request.POST.itervalues(): to iterate over both keys and values: for a, value in request.POST.iteritems(): On Jul 27, 2:54 pm, Greg <[EMAIL PRO

Re: Displaying the contents of a Dict (Using POST)...showing 'x' and 'y' keys?

2007-07-27 Thread Nathan Ostgard
You can define a list of valid keys to look for: keys = ['one', 'two', 'three', 'four', 'five'] for key in keys: if not key in request.POST: continue .. do stuff .. Or you can delete the keys you don't want before looping: for key in ['x', 'y', 'submit']: del request.POST[key] for key

Re: Syndication with kwargs from url

2007-07-25 Thread Nathan Ostgard
You shouldn't be capturing the args yourself -- the syndication framework will automatically split up anything after the feed name and pass it to get_object on your Feed class. So, if "/feeds/latest/foo/ bar/" was requested, it would call your feed class with the bits ['foo', 'bar']. You can then

Re: Problems with i18n of field labels (newforms)

2007-07-25 Thread Nathan Ostgard
What import are you aliasing as _? You have three options for gettext calls: - ugettext, which translates as soon as it's *called*. - ugettext_lazy, which does not translate until the attribute is *accessed*. - ugettext_noop, which translates at the last possible moment, such as when the value is

Re: Problem creating choices in Tutorial Part 1

2007-07-25 Thread Nathan Ostgard
As the error says, you're using self.question in the Choice model -- it should be self.choice. e.g., change this: class Choice(models.Model): # ... def __unicode__(self): return self.question to this: class Choice(models.Model): # ... def __unicode__(self): return self.choice

Re: Form_for multiple models

2007-07-24 Thread Nathan Ostgard
You can specify it upon form creation. Here is an example of how you could use prefixes for multiple model forms: In your views: from django import newforms as forms from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from yourproject.yourapp.models impor

Re: Should I give up on dreamhost?

2007-07-23 Thread Nathan Ostgard
First, I've recently setup a Dreamhost account myself with no problems -- feel free to email me directly if you want some help, and I'll see what I can do. That said... Django and Python are still going through growing pains in the shared hosting department. The same thing was going on with Ruby

Re: Instant Django

2007-07-23 Thread Nathan Ostgard
Pretty sweet, good job! I would recommend echoing some info when one runs start.bat. I thought it wasn't working right at first because it just opened a normal command prompt. Just telling people a few of the Django commands that are available to them would probably be enough. On Jul 23, 8:14 am

Re: Some questions on Django's authentication system

2007-07-20 Thread Nathan Ostgard
Regarding the first question, you can do this by creating a middleware class which checks for authenticated users by default. You could also created a decorator to tag view functions as public. For example... in file yourproject/yourapp/middleware.py: from django.conf import settings from dj

Re: Newbie Question: Static Media With Development Server - Not The Same Old Question

2007-07-20 Thread Nathan Ostgard
Interesting! Didn't know document_root would figure out relative paths. Glad you got it working. Re. media -- yeah, sorry about that, I've taken to renaming the admin's to media_admin. On Jul 20, 12:26 pm, cjl <[EMAIL PROTECTED]> wrote: > Nathan: > > Thank you for your reply. > > Your solution s

Re: Newbie Question: Static Media With Development Server - Not The Same Old Question

2007-07-20 Thread Nathan Ostgard
Assuming cwd is the projects folder: settings.py: import os.path MEDIA_ROOT = os.abspath('./media') urls.py: from django.conf import settings urlpatterns = patterns('', (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), ) On Jul 20, 6:13 am, cjl <[EMA

Re: shortcut for assigning values to model?

2007-07-20 Thread Nathan Ostgard
Python also allows you to use ** to unpack a dict into a set of kwargs: b = Book(**bf.cleaned_data) On Jul 20, 4:28 am, LaundroMat <[EMAIL PROTECTED]> wrote: > On 20 jul, 10:53, james_027 <[EMAIL PROTECTED]> wrote: > > > > > hi, > > > is there a short cut for assigning input data to model's data

Re: Problem with image upload

2007-07-20 Thread Nathan Ostgard
Use forms.ModelChoiceField instead: immagine = forms.ModelChoiceField(queryset=Pics.objects.all().order_by('immagine'), cache_choices=False, label='Pic', required=False) On Jul 20, 1:15 am, ilDave <[EMAIL PROTECTED]> wrote: > I've a form that handles file uploading to the database: it works > fi

Re: setting up login required pages massly

2007-07-19 Thread Nathan Ostgard
You can define a custom decorator instead, specifying a custom login_url: from django.contrib.auth.decorators import user_passes_test my_login_decorator = user_passes_test(lambda u: u.is_authenticated(), login_url='/my/login/url') Then you can use: @my_login_decorator def someview(request): .

Re: login() method conflict

2007-07-19 Thread Nathan Ostgard
You may find it easier to avoid these conflicts by doing: from django.contrib import auth Then use: user = auth.authenticate(username='foo', password='bar') auth.login(request, user) On Jul 19, 1:02 am, james_027 <[EMAIL PROTECTED]> wrote: > hi, > > i've been trying to get started with django an

Re: django foreignkey

2007-07-18 Thread Nathan Ostgard
manage.py syncdb won't add new fields to the database if the table already exists. You'll have to do this yourself. See manage.py sqlall for some help. Otherwise, if you have: user = models.ForeignKey(User), then look for a field named user_id in your table. ---- Nathan Ostgard

Re: Multiple URLconfs per app?

2007-07-18 Thread Nathan Ostgard
If you just want to specify the urls as listed, you could always create a urls folder in myapp, put an __init__.py in there, and create myapp/urls/feature1.py and myapp/urls/feature2.py. Nathan Ostgard On Jul 18, 7:37 pm, Collin Grady <[EMAIL PROTECTED]> wrote: > You'll

Re: How do I know if fastcgi is installed correctly? (using dreamhost)

2007-07-18 Thread Nathan Ostgard
)$ dispatch.fcgi/$1 [QSA,L] In my case, I have my Django projects/apps installed under ~/django, and my Virtual Python installation in ~/python. Nathan Ostgard On Jul 18, 9:54 am, walterbyrd <[EMAIL PROTECTED]> wrote: > I am trying to follow jeff croft's tutorial for inst

Re: Picture in admin

2007-07-18 Thread Nathan Ostgard
Here's something on djangosnippets.org for displaying thumbnails in the admin list: http://www.djangosnippets.org/snippets/239/ Or do you mean on the page for editing a record? Nathan Ostgard On Jul 18, 2:11 pm, Naco <[EMAIL PROTECTED]> wrote: > Does anybody know

Re: newforms and models unique=True validation

2007-07-18 Thread Nathan Ostgard
rror('some error message') MyForm = forms.form_for_model(MyModel, form=MyBaseForm) ---- Nathan Ostgard On Jul 18, 7:06 am, stereoit <[EMAIL PROTECTED]> wrote: > Hi, > I have model with field that has attribute unique set to True. I know > newforms are not able to han

Re: newforms and models unique=True validation

2007-07-18 Thread Nathan Ostgard
raise forms.ValidationError('some error message') MyForm = forms.form_for_model(MyModel, form=MyBaseForm) ---- Nathan Ostgard On Jul 18, 7:06 am, stereoit <[EMAIL PROTECTED]> wrote: > Hi, > I have model with field that has attribute unique set to True. I know > new

Re: MEDIA_URL MEDIA_ROOT problem.

2007-07-17 Thread Nathan Ostgard
You can also refer to this page in the documentation for more information: http://www.djangoproject.com/documentation/static_files/ Nathan Ostgard On Jul 17, 11:35 am, Dmitriy Sodrianov <[EMAIL PROTECTED]> wrote: > Hello everyone! > > Let me ask for help with the fo

Re: anybody help me! raise EnvironmentError

2007-07-17 Thread Nathan Ostgard
3. Actually setting the environment variable DJANGO_SETTINGS_MODULE in your shell. If you don't know how to do that already, you should probably use one of the other two options. Nathan Ostgard On Jul 17, 2:43 pm, Collin Grady <[EMAIL PROTECTED]> wrote: > If you don't use &quo

Re: is there any host servers that supports Django based sites?

2007-07-14 Thread Nathan Ostgard
It's a question of value to the customer. Of course they don't necessarily care about Django -- they care about the product. It's up to you to illustrate to them, using Django, that you can deliver a better product to them than the competition, and that the costs are worth it. I've found that the

Re: JavaScript in template

2007-07-14 Thread Nathan Ostgard
If you're using an SVN copy (not 0.96), there is already a context processor for this. Add 'django.core.context_processors.media' to TEMPLATE_CONTEXT_PROCESSORS in settings.py and you will be able to use {{ MEDIA_URL }} in your templates. On Jul 14, 6:43 am, skam <[EMAIL PROTECTED]> wrote: > It

Re: Template variable when None displays None

2007-07-11 Thread Nathan Ostgard
It's the default behavior of Python: >>> str(None) 'None' I don't agree that it should be the default. None and "" are two distinct values -- especially with a database. In databases, None (or NULL) normally represents a _missing_ value, whereas a "" is one that was intentionally specified to be

Re: ForeignKey(User, list_display=full?

2007-07-11 Thread Nathan Ostgard
I really think you should define a custom field and override the choices. For example: from django.utils.encoding import smart_unicode class UserForeignKey(models.ForeignKey): def get_choices(self, include_blank=True, blank_choice=models.BLANK_CHOICE_DASH): "Returns a list of tuples used as

Re: multiple inner joins in sql

2007-07-10 Thread Nathan Ostgard
On Jul 10, 2:58 pm, novice <[EMAIL PROTECTED]> wrote: > but I get error that the offers_offerprice.offerseller_id column > doesnt exist. I think you're missing an underscore. Your model has the field named offer_seller... shouldn't it then be offers_offerprice.offer_seller_id? --~--~-~-

Re: ForeignKey(User, list_display=full?

2007-07-10 Thread Nathan Ostgard
ForeignKey fields use the Field.get_choices() method to build a list of options. Perhaps you could subclass the ForeignKey field and customize the method? On Jul 10, 10:30 am, Carl Karsten <[EMAIL PROTECTED]> wrote: > I am using the django User like so: > > # models.py > from django.contrib.auth.

Re: Problem when filling the options of a Choice Field with information from the database

2007-07-10 Thread Nathan Ostgard
Note that this will return the primary key of an instrument for the value, rather than the name. ---- Nathan Ostgard On Jul 10, 4:41 am, AnaReis <[EMAIL PROTECTED]> wrote: > Hi, > I have a form on my project which has a drop down list with several > options that are loaded from a t

Re: forms and designers

2007-07-10 Thread Nathan Ostgard
and flexible for styling: {{ form.some_field.label }}: {{ form.some_field }} {{ form.some_field.errors }} ... more fields ... ... more fieldsets ... or cancel Nathan Ostgard --~--~-~--~~~---~--~~ You received this message because yo

Re: Remove a field from a form

2007-07-09 Thread Nathan Ostgard
Do this instead: PreventivoForm = form_for_model(Preventivo) del PreventivoForm.base_fields['codice'] f = PreventivoForm() f2 = PreventivoForm(auto_id='id_%s2') Nathan Ostgard On Jul 9, 2:33 am, ilDave <[EMAIL PROTECTED]> wrote: > Hi! > I have to show two

Re: forms and designers

2007-07-08 Thread Nathan Ostgard
hatever').focus(someJavascriptFunction); }); As for classes, I've taken to applying them to a div surrounding my input elements. So I have something like: {{ form.whatever.label }} {{ form.whatever }} The CSS isn't much longer... form .red input { color: red; } Nathan Ostgard On Jul 8, 8:04

Re: cross-table unique_together?

2007-07-06 Thread Nathan Ostgard
You would either have to duplicate the Title foreign key in the Copy model or write a custom check in the save method. To enforce uniqueness over several columns you would use the "unique_together" field of the Meta class for your Copy model. (see: http://www.djangoproject.com/documentation/model