Saturday, July 31, 2010

Re: Get request path without having a request object

On Sat, Jul 31, 2010 at 12:37 PM, cootetom <cootetom@gmail.com> wrote:
> Thanks Carlos but I'm trying to achieve getting the path without
> having to pass the request object.

In a word: don't.

Instead, design your system to pass the information you need where and
when you need it. This doesn't mean everything always has to sling
around a request object, just that you need to think carefully about
separation of concerns and which code needs to get at the request.

Do this, and in 6-12 months when you have to start making changes to
update your application, you'll be incredibly thankful that you did it
right the first time around.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

ANN: django-forms-builder 0.2.0 released

Hi Djangonauts,

I've released a new version of django-forms-builder. It's a small Django reusable app that allows admin users to build their own forms. 

This release is a complete rewrite that addresses the fact that previously the fields available for forms created by admin users were restricted to a fixed set of fields defined by the developer. Admin users can now create forms with any number of fields specifying their names and field types making it a much more thorough solution. I've also added some basic tests as well as the ability for admin users to export form submissions via CSV. 


Cheers,
Steve

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Django error can't adapt

Hi,
I just migrated from Linux to Mac OS, and I'm getting an error message
when I try register a new user of my django site, (at my page)
I get the error: can't adapt type 'US/Eastern'
I'm using Postgresql and psycopg2, I tried to change the TIME_ZONE to
'America/Sao_Paulo'(I'm in Brazil), but the error still happens.

I tried anothers possibilities of TIME_ZONE but no success.

Anyone know how to solve that?

Best Regards,
Daniel França

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Unable to add model in admin (but can list them)

I've been scratching my head over this for awhile now --

I have an app called "main" that has two models defined "entity"
"story" -- I am able to see a list of each via the following urls:

http://127.0.0.1:8000/admin/main/entity/
http://127.0.0.1:8000/admin/main/story/

However, I'm only able to add new entities without issue... but when I
attempt to add a new story I get a 404 error, with no other
information (I have Debug = True) set.

I'm revisiting this project after a few months, so I'm not sure what I
might've done to get my project in this state... wondering if anyone
else has ideas? (I was previously able to add stories, so clearly I
messed something up somewhere.. and didn't realize it).

This is an abridged version of my main/models.py :


class Entity(models.Model):
name = models.CharField(max_length=64)
sketch = models.TextField()

class Meta:
verbose_name_plural = 'entities'

def __unicode__(self):
return self.name

class Story(models.Model):
link = models.URLField(max_length=384)
title = models.CharField(max_length=256)
slug = models.SlugField(max_length=256)
summary = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
submitter = models.ForeignKey(User)
entity = models.ForeignKey(Entity)

class Meta:
verbose_name_plural = 'stories'

def __unicode__(self):
return self.title

# def save(self, *args, **kwargs):
# if not self.id:
# self.slug = slugify(self.title)
#
# super(Story, self).save(*args, **kwargs)

---

and here is my admin.py


class StoryAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}

admin.site.register(Entity)
admin.site.register(Story, StoryAdmin)


--

Incidentally, I've tried it with and without the overloaded save
method, and with and without the StoryAdmin customization... to no
avail.

Thanks for any help!
Fell


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Which program will run when we execute "djano-admin.py startproject mysite" command?

It runs django-admin.py using the python interpreter.

Maybe this webpage, or a windows user on this list, will have the answer:
http://docs.python.org/faq/windows.html

Hope this helps,
-- Casey

On 07/31/2010 03:57 PM, balu wrote:
> Yah... I tried it by adding python in the command line. But I couldn't
> get the actual result. Could you people can give a gist of what
> happens when we type "django-admin.py startproject mysite" i.e., which
> program will run when we type that and press return key.
>
>
> On Aug 1, 12:41 am, "Casey S. Greene"<csgre...@princeton.edu> wrote:
>> Hi,
>>
>> I'm not a windows user but I'm guessing that you want to use the python
>> executable (see if you can find something called "python".
>> Alternatively, what if you run it with:
>>
>> python django-admin.py startproject mysite
>>
>> Hope this helps,
>> -- Casey
>>
>> On 07/31/2010 03:12 PM, balu wrote:
>>
>>> Hi everybody
>>
>>> I installed python and django in my Windows 7 home premium operating
>>> system. But when I tried to execute "django-admin.py startproject
>>> mysite" command in it, the Operating system is asking me to choose the
>>> program to run this application. But this is not happened when I tried
>>> this in Windows XP.
>>
>>> Please guide me to solve this. Is Windows 7 is incompatible with this
>>> command ??
>>
>>> Looking forward for answer
>>
>>> thank you
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Which program will run when we execute "djano-admin.py startproject mysite" command?

Yah... I tried it by adding python in the command line. But I couldn't
get the actual result. Could you people can give a gist of what
happens when we type "django-admin.py startproject mysite" i.e., which
program will run when we type that and press return key.


On Aug 1, 12:41 am, "Casey S. Greene" <csgre...@princeton.edu> wrote:
> Hi,
>
> I'm not a windows user but I'm guessing that you want to use the python
> executable (see if you can find something called "python".
> Alternatively, what if you run it with:
>
> python django-admin.py startproject mysite
>
> Hope this helps,
> -- Casey
>
> On 07/31/2010 03:12 PM, balu wrote:
>
> > Hi everybody
>
> > I installed python and django in my Windows 7 home premium operating
> > system. But when I tried to execute "django-admin.py startproject
> > mysite" command in it, the Operating system is asking me to choose the
> > program to run this application. But this is not happened when I tried
> > this in Windows XP.
>
> > Please guide me to solve this. Is Windows 7 is incompatible with this
> > command ??
>
> > Looking forward for answer
>
> > thank you

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Which program will run when we execute "djano-admin.py startproject mysite" command?

Hi,

I'm not a windows user but I'm guessing that you want to use the python
executable (see if you can find something called "python".
Alternatively, what if you run it with:

python django-admin.py startproject mysite

Hope this helps,
-- Casey

On 07/31/2010 03:12 PM, balu wrote:
> Hi everybody
>
> I installed python and django in my Windows 7 home premium operating
> system. But when I tried to execute "django-admin.py startproject
> mysite" command in it, the Operating system is asking me to choose the
> program to run this application. But this is not happened when I tried
> this in Windows XP.
>
> Please guide me to solve this. Is Windows 7 is incompatible with this
> command ??
>
> Looking forward for answer
>
> thank you
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Which program will run when we execute "djano-admin.py startproject mysite" command?

Hi everybody

I installed python and django in my Windows 7 home premium operating
system. But when I tried to execute "django-admin.py startproject
mysite" command in it, the Operating system is asking me to choose the
program to run this application. But this is not happened when I tried
this in Windows XP.

Please guide me to solve this. Is Windows 7 is incompatible with this
command ??

Looking forward for answer

thank you

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Get request path without having a request object

Thanks Carlos but I'm trying to achieve getting the path without
having to pass the request object.

On Jul 31, 7:11 pm, Carlos Daniel Ruvalcaba Valenzuela
<clsdan...@gmail.com> wrote:
> Just add django.core.context_processors.request to your
> TEMPLATE_CONTEXT_PROCESSORS, this way you can access the current
> request object in your template, you will have to use however
> RequestContext class with render_to_response,
>
> From docs:
>
> django.core.context_processors.request
>
> If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every
> RequestContext will contain a variable request, which is the current
> HttpRequest. Note that this processor is not enabled by default;
> you'll have to activate it.
>
> Regards,
> Carlos Daniel Ruvalcaba Valenzuela

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: how to get parent of related m2m model instance from within a template?

http://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects

On Jul 30, 12:29 pm, J <juanvio...@gmail.com> wrote:
> I have a model, which has a related model, which then has a related
> m2m field (See defs below).
>
> I want to add a method to the m2m model (ie: "Button") which, when
> called in a template, will get me the original record that called the
> relation. Is this possible? See method attempt below in the "Button"
> model, called "get_duid". The point in this attempt is to be able to
> return the original id within the template when iterating through the
> buttons of a particular "DocumentUnit".
>
> class DocumentUnit(models.Model):
>     parent      = models.ForeignKey('self', null=True, blank=True,
> related_name='children')
>     unittype    = models.ForeignKey(DocumentUnitType,
> related_name='du')
>     content     = models.TextField()
>
> class DocumentUnitType(models.Model):
>     name                = models.CharField(max_length=40)
>     description         = models.CharField(max_length=255, blank=True)
>     buttons             = models.ManyToManyField('Button', null=True,
> blank=True, related_name='button_du_types')
>
> class Button(models.Model):
>     btn_code        = models.CharField(max_length=20)
>     title           = models.CharField(max_length=50, blank=True)
>     href            = models.CharField(max_length=150, blank=True)
>     viewname        = models.CharField(max_length=50, blank=True)
>     css_class       = models.CharField(max_length=70, blank=True)
>     text            = models.CharField(max_length=50, blank=True)
>     prefix_id       = models.CharField(max_length=20)
>     order           = models.IntegerField(blank=True, null=True)
>
>     def get_duid(self):
>         return self.button_du_types.pk
>
> Thanks for any help you can give me with this.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Get request path without having a request object

Just add django.core.context_processors.request to your
TEMPLATE_CONTEXT_PROCESSORS, this way you can access the current
request object in your template, you will have to use however
RequestContext class with render_to_response,

From docs:

django.core.context_processors.request

If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every
RequestContext will contain a variable request, which is the current
HttpRequest. Note that this processor is not enabled by default;
you'll have to activate it.

Regards,
Carlos Daniel Ruvalcaba Valenzuela

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Get request path without having a request object

I think perhaps I'll also put this problem another way. I need to
cache data against the current web request without having the Django
built request object.

On Jul 31, 4:56 pm, cootetom <coote...@gmail.com> wrote:
> Hi all,
>
> Is there any way of getting the request.path value without having the
> request object that Django pass's around. Is there something similar
> to os.environ for the web request where I can get the path?
>
> I'm developing an app that needs to cache data on a page basis but the
> data may come from any Python code that is run for the request or it
> may come from the template layer via custom template tags. I don't
> want to have to pass the request path around in order to eventually
> pass it to my caching code for use in the cache key. I just want to be
> able to find the request path from my caching code.
>
> Possible?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: How do I populate a multi-select field with a single column from a model?

Sweet. That did the trick. I found an example here:

http://www.djangoproject.com/documentation/models/str/

# Areas Model UPDATED
from django.db import models

# Create your models here.
class Area(models.Model):
name = models.CharField(max_length=40)
city = models.CharField(max_length=50)
phone = models.CharField(max_length=12)
email = models.EmailField()

def __unicode__(self):
return self.name

On Jul 31, 4:31 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 31, 10:07 am, strayhand <tobyb...@gmail.com> wrote:
>
> > I want to grab a single column in a model and use it to populate a
> > multi-select form field. Here's the code that I'm currently using:
>
> > areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> > label='Preferred Areas', help_text='Select the areas that you\'d like
> > to serve.')
>
> > This code returns the entire Model. I tried using
> > queryset=Area.values('name') and it didn't work. How am I suppose to
> > grab a single column out of a model? My model and form code have been
> > provided below. Thanks.
>
> I don't know what you mean by 'returns the entire Model'. Model choice
> fields use as their display values the __unicode__ value of the items
> in the queryset. If that isn't defined, you'll get something like
> "Area object". The solution is simply to define a __unicode__ method,
> which is good practice anyway.
> --
> DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: How do I populate a multi-select field with a single column from a model?

Ah... Well that's exactly what's happening. I'm getting "Area Object"
for each element in the select box. I've seen the __unicode__ method
on a few model examples, but my book and other resources never really
showed or explained it. I'll see if I can find some explanation of it.
Thanks for the clue.

On Jul 31, 4:31 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 31, 10:07 am, strayhand <tobyb...@gmail.com> wrote:
>
> > I want to grab a single column in a model and use it to populate a
> > multi-select form field. Here's the code that I'm currently using:
>
> > areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> > label='Preferred Areas', help_text='Select the areas that you\'d like
> > to serve.')
>
> > This code returns the entire Model. I tried using
> > queryset=Area.values('name') and it didn't work. How am I suppose to
> > grab a single column out of a model? My model and form code have been
> > provided below. Thanks.
>
> I don't know what you mean by 'returns the entire Model'. Model choice
> fields use as their display values the __unicode__ value of the items
> in the queryset. If that isn't defined, you'll get something like
> "Area object". The solution is simply to define a __unicode__ method,
> which is good practice anyway.
> --
> DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: moving to django 1.2.1

On Sat, Jul 31, 2010 at 9:45 PM, Michael P. Soulier
<msoulier@digitaltorque.ca> wrote:
> On 30/07/10 tiemonster said:
>
>> I cover some of the new changes in Django 1.2 in this article:
>> http://www.tiemonster.info/a/24005/
>>
>> Most of this information comes straight from the changelist. Others
>> were things that the core developers must have assumed were common
>> sense, but that I didn't think about when upgrading. If you run across
>> anything that's not on the list, let me know and I'll update the
>> article.
>
> That's helpful, thanks. What would be more helpful is backwards compatability
> in Django. Now I have to sell the upgrade to my peers at work, since work will
> be involved.

Ok - I'm repeating myself here, but we take backwards compatibility
*very* seriously. If anyone can point at a specific backwards
incompatible change that was introduced in Django 1.2, then that is a
bug that we need to address, and would in all likelihood be a trigger
for a new point release.

It has been my experience that you can upgrade from 1.1 to 1.2 without
any code changes. If your project was written against Django 1.0,
upgrading to 1.2 will cause some noisy warnings to be raised (about
features that have been on the deprecation path since 1.1 -- most
notably, the way of importing admin urls), but your code will still
work as is. This has also been the experience of others that I have
spoken to.

The only work is required is if you take the opportunity of the
upgrade to introduce some of the new features from Django 1.2 -- such
as CSRF protection, multiple databases, or cookie-based/anonymous
messaging. However, these are entirely optional activities. The only
change I would encourage you to make is the CSRF changes, and that's
purely for your own security. In my experience (and I've heard similar
stories from others), a reasonably large site can be migrated to use
the new CSRF protection in a matter of hours, especially if you've
been a good developer and you have lots of unit tests.

So - I would kindly ask that anyone who has what they feel is a
backwards incompatibility problem to reduce that issue to a
reproducible test case and submit a ticket. If they've already done so
and the ticket hasn't received any attention, then please speak up. To
the best of my knowledge, Django 1.2 has no backwards compatibility
issues.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Get request path without having a request object

Hi all,

Is there any way of getting the request.path value without having the
request object that Django pass's around. Is there something similar
to os.environ for the web request where I can get the path?

I'm developing an app that needs to cache data on a page basis but the
data may come from any Python code that is run for the request or it
may come from the template layer via custom template tags. I don't
want to have to pass the request path around in order to eventually
pass it to my caching code for use in the cache key. I just want to be
able to find the request path from my caching code.

Possible?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: moving to django 1.2.1

On Fri, Jul 30, 2010 at 8:14 PM, tiemonster <mark@tiemonster.info> wrote:
> I cover some of the new changes in Django 1.2 in this article:
> http://www.tiemonster.info/a/24005/
>
> Most of this information comes straight from the changelist. Others
> were things that the core developers must have assumed were common
> sense, but that I didn't think about when upgrading. If you run across
> anything that's not on the list, let me know and I'll update the
> article.

Hi Mark,

Since this conversation is happening in the context of a backwards
compatibility discussion, I want to provide some clarification to a
couple of elements of your blog post:

* Although we have introduced a new format for defining databases,
you aren't required to make any modifications in order to upgrade.
Old-style DATABASE_* settings will continue to work, as the release
notes describe [1].

[1] http://docs.djangoproject.com/en/dev/releases/1.2/#specifying-databases

* The problem with database caching isn't a backwards incompatible
problem; it's a bug with the database cache backend when used with
multiple database support. Since Django 1.1 didn't have support for
multiple databases, it's impossible for a Django 1.1 project to
experience a backwards incompatibility problem here. It is, however, a
bug in the a Django 1.2 feature. Ticket #13946 is tracking the
problem; it is on my radar, and I've just updated the triage state to
ensure that it doesn't get forgotten.

* If you have an existing project, the introduction of CSRF
protection in Django 1.2 shouldn't pose any obstacle to upgrading.
CSRF protection is turned on by default in new projects, but you need
to manually turn it on for existing projects (i.e., you need to add
the new middleware). If you don't add the new middleware, you don't
need to do anything in order to run your project under Django 1.2. The
only potential backwards incompatibility is if you have written custom
templates to override the default templates provided by Django's admin
-- but this is clearly highlighted in the release notes [2].

[2] http://docs.djangoproject.com/en/dev/releases/1.2/#csrf-protection

* Your comments about messages correctly points out that the changes
are completely transparent, and require no immediate action for
compatibility.

* I don't know where you've got your information on the changes to
the unit test system, but your comments are (to use a complex Latin
term) wrong :-) The example you point to [3] is exactly the same
example that existed in the docs for Django 1.1 [4] and Django 1.0
[5]. Django's Test Client has never had a dependency on either the
base unittest library or Django's own unittest extensions. Django 1.2
didn't introduce any significant changes to the test client. There
were some changes to the test runner -- the utility that sets up and
executes the test environment -- but again, those changes should be
completely transparent, and require no immediate change when
upgrading.

[3] http://docs.djangoproject.com/en/1.2/topics/testing/#example
[4] http://docs.djangoproject.com/en/1.1/topics/testing/#example
[5] http://docs.djangoproject.com/en/1.0/topics/testing/#example

* Your point about admin media is generally good advice, but isn't a
backwards compatibility problem. Yes, Django 1.2 has new admin media
files, and you will need to have a complete and correct checkout of
those files served by your media provider (CDN or otherwise).

As I said previously, we take backwards compatibility very seriously
as a project. Unless you have been tinkering with internals or relying
on behavior that is buggy, you should be able to upgrade from Django
1.1 to Django 1.2 without being required to make *any* changes to your
code. This has been my experience on all projects that I have updated.
If anyone can provide a documented example to the contrary, then that
is a bug that should be fixed, and may well be sufficient to trigger a
point release.

Note that I said *required* to make changes. There are many updates
that are worthwhile making that aren't required (and won't be until
Django 1.4 is released). Enabling CSRF protection is a good idea for
security sake. Updating database settings will enable new
architectural options. Switching to the new messaging framework allows
for anonymous users to receive messages, and also allows for cookie
based messaging. However, none of these modifications are required in
order to update to Django 1.2.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

django-admin.py not working

Im using ubuntu

I managed to get through the poll project working on the django tut.
then tried another project

At the prompt i get

gino@gino-laptop:~/djangoDEV$ django-admin
The program 'django-admin' is currently not installed. You can
install it by typing:
sudo apt-get install python-django

what is the matter?

I verified that django is installed:

gino@gino-laptop:~/djangoDEV$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: How do I populate a multi-select field with a single column from a model?

Area.objects.values('name','city')

On Jul 31, 5:07 pm, strayhand <tobyb...@gmail.com> wrote:
> I want to grab a single column in a model and use it to populate a
> multi-select form field. Here's the code that I'm currently using:
>
> areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> label='Preferred Areas', help_text='Select the areas that you\'d like
> to serve.')
>
> This code returns the entire Model. I tried using
> queryset=Area.values('name') and it didn't work. How am I suppose to
> grab a single column out of a model? My model and form code have been
> provided below. Thanks.
>
> #register.forms
>
> from django import forms
> from django.db import models
> from django.forms import ModelForm
> from ylbbq.areas.models import Area
>
> STATES = (
>         ('AK', 'Alaska'),
> ...
>         ('YT', 'Yukon'),
> )
>
> COUNTRIES = (
>         ('USA', 'United States'),
>         ('Canada', 'Canada')
> )
>
> class RegisterForm(forms.Form):
>         username = forms.CharField(max_length=30)
>         first_name = forms.CharField(max_length=30)
>         last_name = forms.CharField(max_length=30)
>         password1 = forms.CharField(max_length=60)
>         password2 = forms.CharField(max_length=60)
>         email = forms.EmailField(help_text='Enter a valid e-mail address.')
>         phone = forms.CharField(max_length=12)
>         address = forms.CharField(max_length=70)
>         city = forms.CharField(max_length=50)
>         state_province = forms.ChoiceField(choices=STATES, label='State or
> Province')
>         country = forms.ChoiceField(choices=COUNTRIES)
>         zip_code = forms.CharField(max_length=5)
>         birth_date = forms.DateField()
>         areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> label='Preferred Areas', help_text='Select the areas that you\'d like
> to serve.')
>
> # areas.model
>
> from django.db import models
>
> class Area(models.Model):
>         name = models.CharField(max_length=40)
>         city = models.CharField(max_length=50)
>         phone = models.CharField(max_length=12)
>         email = models.EmailField()

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: moving to django 1.2.1

On 30/07/10 tiemonster said:

> I cover some of the new changes in Django 1.2 in this article:
> http://www.tiemonster.info/a/24005/
>
> Most of this information comes straight from the changelist. Others
> were things that the core developers must have assumed were common
> sense, but that I didn't think about when upgrading. If you run across
> anything that's not on the list, let me know and I'll update the
> article.

That's helpful, thanks. What would be more helpful is backwards compatability
in Django. Now I have to sell the upgrade to my peers at work, since work will
be involved.

Mike

Form label suffix

Hello,

If i do following, it works:

>>> form = ContactForm(label_suffix=":")
>>> print form
<tr><th><label for="id_name">Your name:</label>...


but here it is missing ':':

>>> form['name'].label_tag()
u'<label for="id_name">Your name</label>'

I need to customize form output, so I can not use print form or as_p(),
etc. and I am using following:

{% for field in form %}
{% if not field.is_hidden %}
<div>
{{ field.label_tag }}
{{ field.errors }}
{{ field }}
<p>
{{ field.help_text}}
</p>
</div>
{% else %}
{{ field.as_hidden }}
{% endif %}
{% endfor %}

What I have to do to add the label suffix?

Thanks,
Martin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: How do I populate a multi-select field with a single column from a model?

On Jul 31, 10:07 am, strayhand <tobyb...@gmail.com> wrote:
> I want to grab a single column in a model and use it to populate a
> multi-select form field. Here's the code that I'm currently using:
>
> areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> label='Preferred Areas', help_text='Select the areas that you\'d like
> to serve.')
>
> This code returns the entire Model. I tried using
> queryset=Area.values('name') and it didn't work. How am I suppose to
> grab a single column out of a model? My model and form code have been
> provided below. Thanks.

I don't know what you mean by 'returns the entire Model'. Model choice
fields use as their display values the __unicode__ value of the items
in the queryset. If that isn't defined, you'll get something like
"Area object". The solution is simply to define a __unicode__ method,
which is good practice anyway.
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Getting http://http://domain.com/sitemaps.xml on production server using django sitemaps

I'm trying to get sitemaps configured properly for http://newsley.com,
but I'm having weird issues with the URLs that are being created for
the sitemaps.xml on my production server. e.g. http://newsley.com/sitemap.xml

When I run the code on my development server, using ./manage.py
runserver, the urls are produced correctly, but when I run the code on
my production server (apache running on Windows server), it's adding
an extra "http://" to every url in the sitemaps.xml file.

For what it's worthy, my sitemaps.py, urls.py and models.py are here:
http://dpaste.com/hold/223712/

I'm guessing that I have apache configured wrong somehow, but this is
the first time I've run into this problem, and I'm stumped.

Any suggestions?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

How do I populate a multi-select field with a single column from a model?

I want to grab a single column in a model and use it to populate a
multi-select form field. Here's the code that I'm currently using:

areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
label='Preferred Areas', help_text='Select the areas that you\'d like
to serve.')

This code returns the entire Model. I tried using
queryset=Area.values('name') and it didn't work. How am I suppose to
grab a single column out of a model? My model and form code have been
provided below. Thanks.

#register.forms

from django import forms
from django.db import models
from django.forms import ModelForm
from ylbbq.areas.models import Area

STATES = (
('AK', 'Alaska'),
...
('YT', 'Yukon'),
)

COUNTRIES = (
('USA', 'United States'),
('Canada', 'Canada')
)

class RegisterForm(forms.Form):
username = forms.CharField(max_length=30)
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
password1 = forms.CharField(max_length=60)
password2 = forms.CharField(max_length=60)
email = forms.EmailField(help_text='Enter a valid e-mail address.')
phone = forms.CharField(max_length=12)
address = forms.CharField(max_length=70)
city = forms.CharField(max_length=50)
state_province = forms.ChoiceField(choices=STATES, label='State or
Province')
country = forms.ChoiceField(choices=COUNTRIES)
zip_code = forms.CharField(max_length=5)
birth_date = forms.DateField()
areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
label='Preferred Areas', help_text='Select the areas that you\'d like
to serve.')


# areas.model

from django.db import models

class Area(models.Model):
name = models.CharField(max_length=40)
city = models.CharField(max_length=50)
phone = models.CharField(max_length=12)
email = models.EmailField()

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: UnicodeEncodeError

On Jul 30, 11:17 pm, EricBrian <ericbr...@gmail.com> wrote:
> Daniel, if I don't do that, I get the unicode error in the list of
> dashboards in the admin section.
>

You'd better post the traceback for that, then.

Just to be clear, your method should look like this:

def __unicode__(self):
return self.name
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Friday, July 30, 2010

Flexigrid

Hi,

I want to use Flexigrid for my project. I have used it before on
TurboGears and it's really nice.

Can somebody please help me how can I use flexigrid for my project?
tutorials link to start for using Flexigrid on django?

Thanks a lot in advance,
RB

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

how to get parent of related m2m model instance from within a template?

I have a model, which has a related model, which then has a related
m2m field (See defs below).

I want to add a method to the m2m model (ie: "Button") which, when
called in a template, will get me the original record that called the
relation. Is this possible? See method attempt below in the "Button"
model, called "get_duid". The point in this attempt is to be able to
return the original id within the template when iterating through the
buttons of a particular "DocumentUnit".

class DocumentUnit(models.Model):
parent = models.ForeignKey('self', null=True, blank=True,
related_name='children')
unittype = models.ForeignKey(DocumentUnitType,
related_name='du')
content = models.TextField()


class DocumentUnitType(models.Model):
name = models.CharField(max_length=40)
description = models.CharField(max_length=255, blank=True)
buttons = models.ManyToManyField('Button', null=True,
blank=True, related_name='button_du_types')


class Button(models.Model):
btn_code = models.CharField(max_length=20)
title = models.CharField(max_length=50, blank=True)
href = models.CharField(max_length=150, blank=True)
viewname = models.CharField(max_length=50, blank=True)
css_class = models.CharField(max_length=70, blank=True)
text = models.CharField(max_length=50, blank=True)
prefix_id = models.CharField(max_length=20)
order = models.IntegerField(blank=True, null=True)

def get_duid(self):
return self.button_du_types.pk


Thanks for any help you can give me with this.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: django_session not in "default" DB

Hi, Thanks for your previous reply. I'm still having problems... now
I'm getting the following error:

NameError: global name 'Session' is not defined

I check up the documentation, I understand that
'django.contrib.sessions.backends.db' makes the Session model
available in the DB router .... so, just by setting the
'django.contrib.session' in my INSTALLED_APPS is enough ? What am I
missing ?

Thanks again.

On Jul 29, 3:39 pm, Dennis Kaarsemaker <den...@kaarsemaker.net> wrote:
> On do, 2010-07-29 at 13:03 -0700, Jocelo wrote:
>
> > Hi,
>
> > I have two DB configured on my django project... one in oracle and the
> > other one in MySQL...
> > My Oracle DB is the default one, and on MySQL I store data that is not
> > really related to my main application.
>
> > I want to store session data in MySQL, since oracle is legacy but
> > whenever I try to store something on my session object
> > ("request.session['temp']=1"), django looks for django_session table
> > on Oracle, crashing completely my app.
>
> > I have read something about dabatase routing, but I'm not sure if this
> > is the way to go for this.
>
> It is the way to go.
>
> > How can I make django look for django_session's table on my
> > "secondary" MySQL  DB ?
>
> http://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-da...has all the details. your router would look like:
>
> class MyRouter(object):
>     def db_for_read(model, **hints):
>         if model == Session:
>             return 'secondary'
>     db_for_write = db_for_read
>
> --
> Dennis K.
>
> They've gone to plaid!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: field.label in template converts to lower case in 1.2.1

Thanks Jason! That fixed the issue.

On Fri, Jul 30, 2010 at 10:23 AM, Jason <goodrichj@gmail.com> wrote:
Actually - make that change to the rest of the field options too. The
word wrap threw me off there at the end.

On Jul 30, 8:16 am, Jason <goodri...@gmail.com> wrote:
> Looks like you are generating the fields in two different cases.
> Here's the second one:
>
>                 self.fields[config.ConfigurationName] =
> forms.ChoiceField(
>                                         choices=choicelist,
>                                         required=False)
>
> Change that to:
>
>                 self.fields[config.ConfigurationName] =
> forms.ChoiceField(
>                                         label =
> config.ConfigurationName,
>                                         choices=choicelist,
>                                         required=False)
>
> (and make the same change to the multiple select as well)
>
> Assuming the ConfigurationName has proper capitalization it should
> work.
>
> On Jul 30, 5:26 am, Jeff Green <jeffhg2...@gmail.com> wrote:
>
> > Here is my form class
>
> > class StationInfo( forms.Form):
>
> >     def __init__( self, *args, **kwargs):
> >         super( StationInfo, self).__init__( *args, **kwargs)
>
> >         request = args[1]
> >         selecttuple = "choice0", "--Select One--"
>
> >         userid = threadlocals.get_current_user()
> >         user = '%s' % userid
> >         userrec = User.objects.get(username=user)
> >         projrecs = UserProj.objects.filter( User=userrec)
> >         self.projlist = []
> >         phaselist = []
> >         for proj in projrecs:
> >             self.projlist.append( proj.ProjectId)
>
> >         # Get all the configurations for a station
> >         stationrec = request.session['stationrec']
> >         configlist1 = Configuration.objects.filter(
> > ConfigurationType='Station', AdditionalEquipFlag=False)
> >         configlist2 = Configuration.objects.filter(
> > ConfigurationType='Station',
> >                     AdditionalEquipFlag=True).order_by('ConfigurationName')
> >         configlist = list(chain(configlist1, configlist2))
>
> >         for config in configlist:
> >             config_str = '%s' % config
> >             foundconfig = True
> >             # Get station configuration record for given station
> >             configstr_list = []
> >             try:
> >                 stationconfiglist = StationConfig.objects.filter(
>
> > ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName,
> >                     EndDate__isnull=True,
> >                     StationId=stationrec
> >                     )
> >                 if len(stationconfiglist) == 0:
> >                     foundconfig = False
> >                 else:
> >                     for stationconfigrec in stationconfiglist:
> >                         configstr = '%s' % stationconfigrec.ConfigValueId
> >                         configstr_list.append( configstr)
>
> >             except:
> >                 foundconfig = False
>
> >             # Get choice list
> >             choicelist = []
> >             if config_str == 'Phase' or config_str == 'Project':
> >                 configvalues = ConfigValues.objects.filter(
>
> > ConfigurationId__ConfigurationName=config.ConfigurationName
> >                     ).order_by( 'ConfigValue')
> >             else:
> >                 configvalues = ConfigValues.objects.filter(
>
> > ConfigurationId__ConfigurationName=config.ConfigurationName,
> >                     ProjectId__in = self.projlist).order_by( 'ConfigValue')
> >             if not foundconfig:
> >                 if config.MultiSelectFlag:
> >                     choicelist.append( selectmoretuple)
> >                 else:
> >                     choicelist.append( selecttuple)
> >             select_fieldlist = []
> >             allchoiceslist = []
> >             for configrec in configvalues:
> >                 configvalstr = '%s' % configrec
> >                 allchoiceslist.append( configvalstr)
> >                 choicestr = "choice%s" % str( configrec.id)
> >                 choicetuple = choicestr, configrec.ConfigValue
> >                 if configrec.ConfigValue in configstr_list:
> >                     choicelist.insert( 0, choicetuple)
> >                     select_fieldlist.append( choicestr)
> >                 else:
> >                     choicelist.append( choicetuple)
>
> >             for stationconfigrec in stationconfiglist:
> >                 configstr = str( stationconfigrec.ConfigValueId)
> >                 # Tried if not in list but it gave incorrect result
> >                 found = False
> >                 for choice in allchoiceslist:
> >                     if configstr == choice:
> >                         found = True
> >                         break
> >                 if not found:
> >                     choicestr = "choice%s" % str(
> > stationconfigrec.ConfigValueId.id)
> >                     choicetuple = choicestr, configstr
> >                     choicelist.insert( 0, choicetuple)
> >                     select_fieldlist.append( choicestr)
>
> >             if config.MultiSelectFlag:
>
> >                 self.fields[config.ConfigurationName] =
> > forms.MultipleChoiceField(
> >                         choices=choicelist,
> >                         required=False,
> >                         widget =
> > MyMultiSelectWidget(initial=select_fieldlist ))
>
> >             else:
> >                 print 'config name is ', config.ConfigurationName
> >                 self.fields[config.ConfigurationName] = forms.ChoiceField(
> >                                         choices=choicelist,
> >                                         required=False)
> >             if config.ExpireFlag:
> >                 for stationconfigrec in stationconfiglist:
> >                     config_valuestr = '%s' % stationconfigrec.ConfigValueId
> >                     print 'config value string is ', config_valuestr
> >                     fieldname = ( config_valuestr + ' ' +
> >                                 config.ConfigurationName +
> >                                 ' CalibrationDueDate (US/Central Time)')
> >                     print 'field name is ', fieldname
> >                     if stationconfigrec.ExpireDate == None:
> >                         self.fields[fieldname] = forms.SplitDateTimeField(
> >                         required=False,
> >                         widget = MySplitDateTimeWidget())
> >                     else:
> >                         startdatetime = '%s' % stationconfigrec.ExpireDate
> >                         datelist = startdatetime.split(' ')
> >                         self.fields[fieldname] = forms.SplitDateTimeField(
> >                         required=False,
> >                         widget =
> > MySplitDateTimeWidget(datevalue=datelist[0],
> >                         timevalue=datelist[1]))
> >             if config.ConfigurationName != 'Phase':
> >                 delete_field = config.ConfigurationName + 'DeleteFlag'
> >                 self.fields[delete_field] = forms.BooleanField(
> >                                         required=False)
>
> > On Thu, Jul 29, 2010 at 5:31 PM, Jason <goodri...@gmail.com> wrote:
> > > Post the form class (or model if you are generating it from a model).
>
> > > On Jul 29, 3:17 pm, Jeff Green <jeffhg2...@gmail.com> wrote:
> > > > For example, the field name is Programmer Serial Number but it is being
> > > > displayed
> > > > as Programmer serial number
>
> > > > I have not had this issue in 1.1.1. I was wondering if there was a way to
> > > > ignore the conversion.
>
> > >  > On Thu, Jul 29, 2010 at 5:02 PM, Jason <goodri...@gmail.com> wrote:
> > > > > I think Django's been doing that for a long time (not just 1.2.1).
>
> > > > > Probably the quick and easy way to change case would be to use just
> > > > > field.label and pump it into whatever format you want:
>
> > > > > {{ field.label|upper }}
>
> > > > > You'll have to manually create the rest of the html for the label
> > > > > using field.html_name
>
> > > > > I've run into some slight problems figuring out the proper id's for
> > > > > the corresponding labels... Normally it's just
> > > > > id_{{ field.html_name }} but if you get into auto_id's as well as
> > > > > labels for more complex things (radio button lists, etc) it can get a
> > > > > little bit funky.
>
> > > > > On Jul 29, 2:42 pm, Jeff Green <jeffhg2...@gmail.com> wrote:
> > > > > > With Django 1.2.1 it seems that my html template causes the
> > > > > > field.label to display
> > > > > > in lower case except for the first character. Has anyone experienced
> > > > > > this before and how do you
> > > > > > get it display without lower case conversion
>
> > > > > > My html template snippet is:
>
> > > > > > {% for field in form %}
>
> > > > > >     {{ field.label_tag}}
>
> > > > > > Thanks,
> > > > > > Jeff
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Django users" group.
> > > > > To post to this group, send email to django-users@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > django-users+unsubscribe@googlegroups.com<django-users%2Bunsubscribe@googlegroups.com>
> > > <django-users%2Bunsubscribe@googlegroups.com<django-users%252Bunsubscribe@googlegroups.com>
>
> > > > > .
> > > > > For more options,
>
> ...
>
> read more »

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Form Validation

On Jul 30, 4:49 pm, rupert <evan.fer...@gmail.com> wrote:
> Here's the view template:
>
> def respondant(request):
>
>         user = request.user
>
>         if set(RESPONDANT_FIELDS).issubset(set([key for key,value in
> request.POST.items()])):
>                 form = RespondantForm(request.POST)
>                 if form.is_valid():
>                         form.save()
>                         template = "feedback/success.html"
>                 else:
>                         form = RespondantForm()
>                         return render_to_response('feedback/index.html', {
>                         'form': form,
>                 })
>
>         else:
>                 key = request.REQUEST.get('key')
>                 if key:
>                         respondant = Respondant.objects.check_key(key)
>                 else:
>                         form = RespondantForm()
>                         return render_to_response('feedback/index.html', {
>                         'form': form,
>                 })
>
>         return render_to_response(template)

This is an unusual structure for a form view, but the problem happens
in the first `else` clause. Previously you've instantiated the form,
passing it the POSTed values, and checked it for errors. But now you
re-instantiate a *blank* form, which obviously won't have any errors
attached to it. Instead of doing that, you should simply be passing
the existing form object into the template - in other words, you don't
need that `else` clause at all (I'm assuming that the extra
indentation of `return render_to_response` is just a cut-and-paste
error, and it's actually at the same level as the `if form.is_valid()`
line.)
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Form Validation

Here's the view template:

def respondant(request):

user = request.user

if set(RESPONDANT_FIELDS).issubset(set([key for key,value in
request.POST.items()])):
form = RespondantForm(request.POST)
if form.is_valid():
form.save()
template = "feedback/success.html"
else:
form = RespondantForm()
return render_to_response('feedback/index.html', {
'form': form,
})

else:
key = request.REQUEST.get('key')
if key:
respondant = Respondant.objects.check_key(key)
else:
form = RespondantForm()
return render_to_response('feedback/index.html', {
'form': form,
})

return render_to_response(template)

On Jul 30, 11:44 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 30, 4:42 pm, rupert <evan.fer...@gmail.com> wrote:
>
> > I'm trying to use this line of code in form validation, and it is not
> > working:
>
> > {{ form.field_name.errors }}
>
> > The following lines do output:
> > {{ form.filed_name}}
> > {{ form.field_name.help_text }}
>
> > Any thoughts? Could it be something in the view?
>
> Very likely. Has the form been validated?
> --
> DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Form Validation

On Jul 30, 4:42 pm, rupert <evan.fer...@gmail.com> wrote:
> I'm trying to use this line of code in form validation, and it is not
> working:
>
> {{ form.field_name.errors }}
>
> The following lines do output:
> {{ form.filed_name}}
> {{ form.field_name.help_text }}
>
> Any thoughts? Could it be something in the view?

Very likely. Has the form been validated?
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Form Validation

I'm trying to use this line of code in form validation, and it is not
working:

{{ form.field_name.errors }}


The following lines do output:
{{ form.filed_name}}
{{ form.field_name.help_text }}

Any thoughts? Could it be something in the view?

Here is the index.html page:
#############################################################################
{% extends "feedback/base.html" %}


{% block content %}


<div id="survey-form">
<form action="" method="post" class="survey-form">
<table>
<div id="topForm">
<div class="survey-form">
{{ form.event.errors }}
<label for="id_event">Event you participated in:</label>
{{ form.event }}
</div>
<div class="survey-form">
<label for="id_unit">Your unit:</label>
{{ form.unit }}
{{ form.unit.help_text }}
</div>
<div class="survey-form">
<label for="name">Your name:</label>
{{ form.name }}
{{ form.name.help_text }}
</div>
<div class="survey-form">
<label for="title">Title</label>
{{ form.title }}
{{ form.title.help_text }}
</div>
<div class="survey-form">
<label for="email">Your email address:</label>
{{ form.email }}
{{ form.email.help_text }}
</div>
</div>
<!-- Delete -->
{% if form.name.errors %}
<ol>
{% for error in form.name.errors %}
<li><strong>{{ error|escape }}</strong></li>
{% endfor %}
</ol>
{% endif %}
<!-- Delete Above -->
<!--Middle-->
<div id="middleForm">
<div class="survey-form">
{{ form.errors }}
<p class="question"></p>
<p class="bullets">{{ form.question_1 }}</p>
</div>
<div class="survey-form">
{{ form.question_2.errors }}
<p class="question"></p>
<p class="bullets">{{ form.question_2 }}</p>
</div>
<div class="survey-form">
{{ form.question_3.errors }}
<p class="question"></p>
<p class="bullets">{{ form.question_3 }}</p>
</div>
<div class="survey-form">
{{ form.question_4.errors }}
<p class="question"></p>
<p class="bullets">{{ form.question_4 }}</p>
</div>
<div class="survey-form">
{{ form.question_5.errors }}
<p class="question"></p>
<p class="bullets">{{ form.question_5 }}</p>
</div>
</div>
<!--Bottom -->
<div id="bottomForm">
<div class="survey-form">
{{ form.comment_6.errors }}
<label for="id_comment_6"></label>
{{ form.comment_6 }}
</div>
<div class="survey-form">
{{ form.comment_7.errors }}
<label for="id_comment_7"></label>
{{ form.comment_7 }}
</div>
<div class="survey-form">
{{ form.comment_8.errors }}
<label for="id_comment_8"></label>
{{ form.comment_8 }}
</div>
<div class="survey-form">
{{ form.comment_9.errors }}
<label for="id_comment_9"></label>
{{ form.comment_9 }}
</div>
<div class="survey-form">
{{ form.comment_10.errors }}
<label for="id_comment_10"></label>
{{ form.comment_10 }}
</div>
</div>
<tr>
<th colspan="2">
<div id="submit"><input type="submit" value="Submit" /></div>
</th>
</tr>
</table>
</form>
</div>


{% endblock 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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: field.label in template converts to lower case in 1.2.1

Actually - make that change to the rest of the field options too. The
word wrap threw me off there at the end.

On Jul 30, 8:16 am, Jason <goodri...@gmail.com> wrote:
> Looks like you are generating the fields in two different cases.
> Here's the second one:
>
>                 self.fields[config.ConfigurationName] =
> forms.ChoiceField(
>                                         choices=choicelist,
>                                         required=False)
>
> Change that to:
>
>                 self.fields[config.ConfigurationName] =
> forms.ChoiceField(
>                                         label =
> config.ConfigurationName,
>                                         choices=choicelist,
>                                         required=False)
>
> (and make the same change to the multiple select as well)
>
> Assuming the ConfigurationName has proper capitalization it should
> work.
>
> On Jul 30, 5:26 am, Jeff Green <jeffhg2...@gmail.com> wrote:
>
> > Here is my form class
>
> > class StationInfo( forms.Form):
>
> >     def __init__( self, *args, **kwargs):
> >         super( StationInfo, self).__init__( *args, **kwargs)
>
> >         request = args[1]
> >         selecttuple = "choice0", "--Select One--"
>
> >         userid = threadlocals.get_current_user()
> >         user = '%s' % userid
> >         userrec = User.objects.get(username=user)
> >         projrecs = UserProj.objects.filter( User=userrec)
> >         self.projlist = []
> >         phaselist = []
> >         for proj in projrecs:
> >             self.projlist.append( proj.ProjectId)
>
> >         # Get all the configurations for a station
> >         stationrec = request.session['stationrec']
> >         configlist1 = Configuration.objects.filter(
> > ConfigurationType='Station', AdditionalEquipFlag=False)
> >         configlist2 = Configuration.objects.filter(
> > ConfigurationType='Station',
> >                     AdditionalEquipFlag=True).order_by('ConfigurationName')
> >         configlist = list(chain(configlist1, configlist2))
>
> >         for config in configlist:
> >             config_str = '%s' % config
> >             foundconfig = True
> >             # Get station configuration record for given station
> >             configstr_list = []
> >             try:
> >                 stationconfiglist = StationConfig.objects.filter(
>
> > ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName,
> >                     EndDate__isnull=True,
> >                     StationId=stationrec
> >                     )
> >                 if len(stationconfiglist) == 0:
> >                     foundconfig = False
> >                 else:
> >                     for stationconfigrec in stationconfiglist:
> >                         configstr = '%s' % stationconfigrec.ConfigValueId
> >                         configstr_list.append( configstr)
>
> >             except:
> >                 foundconfig = False
>
> >             # Get choice list
> >             choicelist = []
> >             if config_str == 'Phase' or config_str == 'Project':
> >                 configvalues = ConfigValues.objects.filter(
>
> > ConfigurationId__ConfigurationName=config.ConfigurationName
> >                     ).order_by( 'ConfigValue')
> >             else:
> >                 configvalues = ConfigValues.objects.filter(
>
> > ConfigurationId__ConfigurationName=config.ConfigurationName,
> >                     ProjectId__in = self.projlist).order_by( 'ConfigValue')
> >             if not foundconfig:
> >                 if config.MultiSelectFlag:
> >                     choicelist.append( selectmoretuple)
> >                 else:
> >                     choicelist.append( selecttuple)
> >             select_fieldlist = []
> >             allchoiceslist = []
> >             for configrec in configvalues:
> >                 configvalstr = '%s' % configrec
> >                 allchoiceslist.append( configvalstr)
> >                 choicestr = "choice%s" % str( configrec.id)
> >                 choicetuple = choicestr, configrec.ConfigValue
> >                 if configrec.ConfigValue in configstr_list:
> >                     choicelist.insert( 0, choicetuple)
> >                     select_fieldlist.append( choicestr)
> >                 else:
> >                     choicelist.append( choicetuple)
>
> >             for stationconfigrec in stationconfiglist:
> >                 configstr = str( stationconfigrec.ConfigValueId)
> >                 # Tried if not in list but it gave incorrect result
> >                 found = False
> >                 for choice in allchoiceslist:
> >                     if configstr == choice:
> >                         found = True
> >                         break
> >                 if not found:
> >                     choicestr = "choice%s" % str(
> > stationconfigrec.ConfigValueId.id)
> >                     choicetuple = choicestr, configstr
> >                     choicelist.insert( 0, choicetuple)
> >                     select_fieldlist.append( choicestr)
>
> >             if config.MultiSelectFlag:
>
> >                 self.fields[config.ConfigurationName] =
> > forms.MultipleChoiceField(
> >                         choices=choicelist,
> >                         required=False,
> >                         widget =
> > MyMultiSelectWidget(initial=select_fieldlist ))
>
> >             else:
> >                 print 'config name is ', config.ConfigurationName
> >                 self.fields[config.ConfigurationName] = forms.ChoiceField(
> >                                         choices=choicelist,
> >                                         required=False)
> >             if config.ExpireFlag:
> >                 for stationconfigrec in stationconfiglist:
> >                     config_valuestr = '%s' % stationconfigrec.ConfigValueId
> >                     print 'config value string is ', config_valuestr
> >                     fieldname = ( config_valuestr + ' ' +
> >                                 config.ConfigurationName +
> >                                 ' CalibrationDueDate (US/Central Time)')
> >                     print 'field name is ', fieldname
> >                     if stationconfigrec.ExpireDate == None:
> >                         self.fields[fieldname] = forms.SplitDateTimeField(
> >                         required=False,
> >                         widget = MySplitDateTimeWidget())
> >                     else:
> >                         startdatetime = '%s' % stationconfigrec.ExpireDate
> >                         datelist = startdatetime.split(' ')
> >                         self.fields[fieldname] = forms.SplitDateTimeField(
> >                         required=False,
> >                         widget =
> > MySplitDateTimeWidget(datevalue=datelist[0],
> >                         timevalue=datelist[1]))
> >             if config.ConfigurationName != 'Phase':
> >                 delete_field = config.ConfigurationName + 'DeleteFlag'
> >                 self.fields[delete_field] = forms.BooleanField(
> >                                         required=False)
>
> > On Thu, Jul 29, 2010 at 5:31 PM, Jason <goodri...@gmail.com> wrote:
> > > Post the form class (or model if you are generating it from a model).
>
> > > On Jul 29, 3:17 pm, Jeff Green <jeffhg2...@gmail.com> wrote:
> > > > For example, the field name is Programmer Serial Number but it is being
> > > > displayed
> > > > as Programmer serial number
>
> > > > I have not had this issue in 1.1.1. I was wondering if there was a way to
> > > > ignore the conversion.
>
> > >  > On Thu, Jul 29, 2010 at 5:02 PM, Jason <goodri...@gmail.com> wrote:
> > > > > I think Django's been doing that for a long time (not just 1.2.1).
>
> > > > > Probably the quick and easy way to change case would be to use just
> > > > > field.label and pump it into whatever format you want:
>
> > > > > {{ field.label|upper }}
>
> > > > > You'll have to manually create the rest of the html for the label
> > > > > using field.html_name
>
> > > > > I've run into some slight problems figuring out the proper id's for
> > > > > the corresponding labels... Normally it's just
> > > > > id_{{ field.html_name }} but if you get into auto_id's as well as
> > > > > labels for more complex things (radio button lists, etc) it can get a
> > > > > little bit funky.
>
> > > > > On Jul 29, 2:42 pm, Jeff Green <jeffhg2...@gmail.com> wrote:
> > > > > > With Django 1.2.1 it seems that my html template causes the
> > > > > > field.label to display
> > > > > > in lower case except for the first character. Has anyone experienced
> > > > > > this before and how do you
> > > > > > get it display without lower case conversion
>
> > > > > > My html template snippet is:
>
> > > > > > {% for field in form %}
>
> > > > > >     {{ field.label_tag}}
>
> > > > > > Thanks,
> > > > > > Jeff
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Django users" group.
> > > > > To post to this group, send email to django-users@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > django-users+unsubscribe@googlegroups.com<django-users%2Bunsubscribe@googlegroups.com>
> > > <django-users%2Bunsubscribe@googlegroups.com<django-users%252Bunsubscribe@googlegroups.com>
>
> > > > > .
> > > > > For more options,
>
> ...
>
> read more »

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.