Re: shortcut for assigning values to model?

2007-07-20 Thread canen

I may be mistaken but isn't this what form_for_model is for?


On Jul 20, 11:23 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
> 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
> > > attribute?
>
> > > if Book is a model then
>
> > > b = Book(request.POST)
> > > b.save()
>
> > > the assignment will be done on all the match key of  the request.POST
> > > QueryDict and data attribute of the Book Model.
>
> > > or
>
> > > if BookForm is a newform then
>
> > > bf = BookForm()
> > > if bf.is_valid():
> > > b = Book(bf.cleaned_data)
>
> > > thanks
> > > james
>
> > You could run through the request.POST's keys and assign them to the
> > Model's attributes:
> > b = Book()
> > for key in request.POST.keys():
> > ---b.__setattribute__(key, request.POST[key])
> > b.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: Stand-alone Django ORM question

2007-08-30 Thread canen

I'm not sure but maybe you need the INSTALLED_APPS setting.


On Aug 30, 10:21 am, ceeed <[EMAIL PROTECTED]> wrote:
> Hello,
> I am a Django newbie and trying to learn it.
>
> As a project, I am trying to use the Django ORM in a stand-alone sense
> (i.e., without creating a project and app). I am using SQLITE and have
> defined the models. I would like to a) create the table in the
> database based on my models, b) populate the table, and c) do queries.
>
> I am running into various problems. My models.py file looks like this:
>
> from django.db import models
> class Template(models.Model):
> name = models.CharField("Name of template", max_length=30)
> type = models.CharField("Type of template", max_length=10)
> style = models.CharField("Style of template", max_length=10)
> def __unicode__(self): return u'%s' % self.name
>
> My settings file looks like this
>
> DEBUG = True
> DATABASE_ENGINE = 'sqlite3'   # 'postgresql_psycopg2',
> 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
> DATABASE_NAME = '/Users/abhijit/moad.db' # Or path to
> database file if using sqlite3.
> DATABASE_USER = '' # Not used with sqlite3.
> DATABASE_PASSWORD = '' # Not used with sqlite3.
> DATABASE_HOST = '' # Set to empty string for localhost.
> Not used with sqlite3.
> DATABASE_PORT = '' # Set to empty string for default. Not
> used with sqlite3.
>
> I tried the following:
>
> abhijit$ python
> Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import os
> >>> os.environ['DJANGO_SETTINGS_MODULE'] = 'moad_settings'
> >>> from django.db import models
> >>> from models import *
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "models.py", line 6, in 
> class Template(models.Model):
>   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/db/models/base.py", line 51, in __new__
> new_class._meta.app_label = model_module.__name__.split('.')[-2]
> IndexError: list index out of range
>
>
>
> Any help/pointers would be appreciated.
> Thanks,


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



Re: Custom_SQL_Method in a Model

2007-09-09 Thread canen

I don't think it matters much. Depends on how large your models.py is.
Just remember to add the new manager as part of the model.

On Sep 9, 4:35 pm, johnny <[EMAIL PROTECTED]> wrote:
> you create class called PersonManager(models.Manager) and define
> my_custom_sql inside there.  Do you place this class in the same
> models.py or in a separate file called apps/people/manager.py and then
> import it where ever you need it?  What is the best practice?


--~--~-~--~~~---~--~~
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: wordpress hooks and actions system in django?

2008-02-22 Thread canen

Just chiming in here. There is a Wordpress 'clone' written in Python
called Textpress [1]. It implements
a lightweight events/actions system[2] akin to the one you mentioned.


[1] http://textpress.pocoo.org/
[2] 
http://dev.pocoo.org/projects/textpress/browser/textpress/application.py#L271

On Feb 22, 11:27 am, Kyle Fox <[EMAIL PROTECTED]> wrote:
> The part that I'm struggling to wrap my head around is how to make
> plugins "installable".
>
> I think one of the reasons Wordpress's plugin framework is so
> successful is how easy it is to manage your plugins: install /
> uninstall buttons on a page means the user doesn't have to write any
> glue code or even do anything from the command line.
>
> I guess you could have an empty 'plugins' app somewhere, and simply
> drop py files into it for each plugin.  What are your guys' thoughts
> on how to accomplish 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Object paginator deprecated?

2008-03-26 Thread canen

This might help http://www.djangoproject.com/documentation/models/pagination/

On Mar 26, 3:16 am, shabda <[EMAIL PROTECTED]> wrote:
> What are he new capbilities of the new paginator? Is there some wiki
> page tracking the deprications, like the backwardsincompatible changes?
--~--~-~--~~~---~--~~
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 templates in database

2007-02-24 Thread canen

See this ticket http://code.djangoproject.com/ticket/632. It has an
implementation.
akonsu wrote:
> hello,
>
> if i wanted to store my templates in the database so that the users
> could edit the way the pages look through the admin interface, how
> would i go about doing that?
>
> thanks for any pointers
> konstantin


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Authenticating against Django's user database from Apache + FastCGI

2007-03-08 Thread canen

Hello,

I would like to restrict access to certain files based on user roles
and/or permission. I know about Authenticating against Django's user
database from Apache [1] but I am using FastCGI with Apache 1.3.3. I
read  this message[2] and specifically this comment [3] and I was
wondering if anyone has something like this working or could point me
in the right direction to getting this working.

Thanks.

[1] http://www.djangoproject.com/documentation/apache_auth/
[2] 
http://groups.google.com/group/django-developers/browse_thread/thread/357606bb8248e7ac/e7ad44b20fd363fb?#e7ad44b20fd363fb
[3] http://groups.google.com/group/django-developers/msg/e7ad44b20fd363fb


--~--~-~--~~~---~--~~
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: capturing urls from previous views

2007-04-04 Thread canen

Tipan,

Are you talking about the refer url? This should be available if you
use RequestContext as  your context for the new view. See the request/
response object docs 
http://www.djangoproject.com/documentation/request_response/

On Apr 4, 11:09 am, "Tipan" <[EMAIL PROTECTED]> wrote:
> I need to capture the url from the previous view to use after
> processing the new view - I expect there's a simple way of doing this,
> but I'm not sure of the best approach. I'm thinking about writing to a
> session cookie or stack when arriving at a view and then recall it
> when I get to the new view.
>
> There are two purposes:
> 1. To hold the url so that I can return to the previous view after
> I've completed validation in the current view.
> 2. To enable me to display specific graphics through all future views
> when the user comes from a certain url.
>
> Can anyone suggest a simple way to do 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I pass label's attributes in newforms

2007-04-25 Thread canen

You would use the attrs argument  when declaring the field.

.
first_name = CharField('First name', attrs={'class': 'left'})
.

On Apr 25, 1:02 pm, RollyF <[EMAIL PROTECTED]> wrote:
> How do I do this using newforms if I want my output to be:
>
> First name:
>
> I want to know how to pass the "class" to the output.
>
> TIA,
> Rolly


--~--~-~--~~~---~--~~
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.clean_data vs. newforms.cleanED_data

2007-05-15 Thread canen

This changed was committed yesterday.  See here
http://groups.google.com/group/django-developers/browse_thread/thread/c87a893a4d7c50a0/32f777bafd3cdb35#32f777bafd3cdb35
for the discussion that lead to the change.

On May 15, 10:43 pm, cornelius bolten <[EMAIL PROTECTED]> wrote:
> hi,
>
> i just tried to click through my new website (django 0.97) after
> developing it on my localhost (django latest stable).
>
> all my websites' forms (newforms) worked well on my localhost.. but
> online i got lot's of errors.
>
> after some searching, i found out that newforms.clean_data changed to
> newforms.cleaned_data. when did this change happen, and why? a lot of my
> apps stopped working now..
>
> cornelius


--~--~-~--~~~---~--~~
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: search engine

2006-10-17 Thread canen

http://www.mercurytide.com/knowledge/white-papers/django-full-text-search
is a good article on adding full-text search to django using mysql. A
search api branch of django can also be found here
http://code.djangoproject.com/browser/django/branches/search-api.

I hope that helps.

On Oct 17, 9:58 am, Eric Walstad <[EMAIL PROTECTED]> wrote:
> Hi Enquest,Enquest wrote:
> > How hard is it to set up a search engine with Django?Easy!  Just search the 
> > model documentation for 'search_fields'.  That
> is, the admin interface has this feature built in, you just need to tell
> it which fields you want searched.
>
> > In PHP I used to explode, implode all words of an insert, update. Each
> > word I would put in to a table words and an other tabel that referred to
> > the words and id of where it came. You know the drill.I do something 
> > similar with the mine but I use my table data to create
> 'documents' (in memory) that are indexed by the Xapian indexing engine.
>   This resulted in searches that are many orders of magnitude faster
> than searching the db table directly (postgres, 8M recs).
>
> > In my own little failed framework in php I used to add in the model view
> > =>search ... My system would then know this field needs to be
> > search-able.
>
> > How hard would it be to set something similar in Django.Easy ;)
>
> > PS. is there any tutorial or plugin for this task to make it more easy
> > to adept?I suggest trying Django's built-in "search engine" first as it's a 
> > snap
> to setup and test.  See the second page of the Django tutorial.  If it's
> not fast or flexible enough for you, then have a look at some of the
> full-text search engines available.  If you are using MySQL, it has one
> built-in, I've heard.  I've read that others here have had success with
> "Swish-e" but I found, and it states this on its website, that the
> indexer really slows down after a couple million documents.  I chose
> Xapian because the indexing my 8M records was accomplished in a
> reasonable amount of time and the search engine is really quite fast;
> that and because it has Python bindings.
>
> Search the mailing list archives for more on this subject as it's been
> discussed here before.
> 
> Best,
> 
> Eric.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Help with List_display in Admin class

2006-10-23 Thread canen

MerMer,

I think what you are looking for can be found in tutorial 2
(http://www.djangoproject.com/documentation/tutorial2/).

In your case you could probable do:

class UserProfile(models.Model):
  

  def fullname(self):
return "%s %s" %(self.user.first_name,self.user.last_name)
  fullname.short_description = 'Full Name'

  class Admin:
list_display=('fullname','city_address','postcode')

or something to that effect. That is the general principle anyway.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: So I made a forum with Django

2006-11-03 Thread canen



On Nov 3, 1:15 pm, "argh44z" <[EMAIL PROTECTED]> wrote:
> Here:http://huzzah.cc/
>
> I'm thinking about cleaning up the code and open-sourcing it. Is anyone
> interested?

Sure we are. Can't have too many Django apps.

I ask this because 3 weeks ago when I started working on
> it, I didn't really see much forum software written with Django that
> was in much actual usage. There were things like Zyons and Myghty, but
> I didn't see many sites using them.
>
> I'm very impressed with Django btw. I hadn't heard of Django 4 weeks
> ago, picked it up, very easy to learn and use, and quite powerful.


--~--~-~--~~~---~--~~
 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: Automatically adding http:// to a URLField

2006-11-15 Thread canen



On Nov 15, 2:45 pm, "Julio Nobrega" <[EMAIL PROTECTED]> wrote:
>   Override the save method on your model to check if the "http://";
> string is not in the self.field_name, and if it's not, add it.
>  http://www.djangoproject.com/documentation/model_api/#overriding-defa...
>
If it fails validation I don't think it would reach the save method, I
could be wrong.  You can always add an extra validator
http://www.djangoproject.com/documentation/model_api/#validator-list

> On 11/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hey,
>
> > Am trying to use a URLField in my app, but if the user doesn't stick
> > http:// on the front of it, it fails vaildation. Is there a way to
> > automatically add one if one isn't present - rather than it just
> > failing validation?
>
> > Many Thanks,
> > Oliver--
> Julio Nobrega -http://www.inerciasensorial.com.br


--~--~-~--~~~---~--~~
 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: View on Site link from Admin

2006-11-28 Thread canen


Define the get_absolute_url method in your model. E.g

class Entry(models.Model):
title = models.CharField(maxlength=200)
..
def get_absolute_url(self):
return "/entry/%s/" % (self.title)

Hope that helps.

On Nov 28, 12:12 pm, Dirk Eschler <[EMAIL PROTECTED]> wrote:
> Am Dienstag, 28. November 2006 18:03 schrieb conrad22:
>
> > How do I get the 'View on site' link that appears in the Django
> > interface to work?
> > I've tried adding the following to my urls.py
>
> > (r'^r/', include('django.conf.urls.shortcut')),
>
> > But didn't do anything!
>
> > Thanks!You have to activate the sites framework, resp. add 
> > 'django.contrib.sites' to
> your INSTALLED_APPS, and then set your hostname in the admin interface. At
> least i had to...
>
> http://www.djangoproject.com/documentation/sites/
>
> Hope that helps,
> Dirk
>
> --
> Dirk Eschler http://www.krusader.org


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



newforms: MultiValueField and MultiWidget

2007-01-24 Thread canen

Hello All,

I am resending this -- seems it didn't reach the last time, sorry if it
turns up twice


I've been messing around with the new MultiValueField and MultiWidget.
I don't  know if the shortcoming is with me or with the implementation
of the field and widget. Let's say I want to create a field that
displays two select fields that are related, I'll use currency display
as an example. The resulting HTML should look like:


USD
EU


1000
2000


and returns a value like "USD 1000". The implementation I have so far
is:

# Field
class MoneyField(MultiValueField):
def __init__(self, currency=(), amount=(), required=True,
widget=None, label=None, initial=None):
fields = (ChoiceField(choices=currency),
ChoiceField(choices=amount))
super(MoneyField, self).__init__(fields, required, widget,
label, initial)

def compress(self, data_list):
if data_list:
return " ".join(i for i in data_list)
return None

# Widget
class MoneyWidget(MultiWidget):
def __init__(self, attrs=None, currency=(), amount=()):
widgets = (Select(attrs=attrs, choices=currency),
Select(attrs=attrs, choices=amount))
super(MoneyWidget, self).__init__(widgets, attrs)

def decompress(self, value):
if value:
return value.split(' ', 1)
return ['', '']

The problem is,  when I use the field I have to repeat the choices for
both  widget and the field, like so:

CURRENCY_CHOICES = [('USD', 'USD'), ('EU', 'EU')]
AMOUNT_CHOICES = [('1000', '1000'), ('2000', '2000')]

class MyForm(forms.Form):
budget = MoneyField(
label="Vacation budget (hotel amount only)",
currency=CURRENCY_CHOICES,
amount=AMOUNT_CHOICES,
required=False,
widget=MoneyWidget(currency=CURRENCY_CHOICES,
amount=AMOUNT_CHOICES)
)

Am I doing something wrong here are is it just a caveat with using
ChoiceField? Any guidance would be appreciated.

Cheers!


--~--~-~--~~~---~--~~
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: MultiValueField and MultiWidget

2007-01-25 Thread canen

Answering my own question:

The widget can be declared as part of the field, e.g.

# Field
class MoneyField(MultiValueField):
def __init__(self, currency=(), amount=(), required=True,
widget=None, label=None, initial=None):
widget  = widget or MoneyWidget(currency=currency,
amount=amount)
.

Or  something like that.

On Jan 24, 8:36 pm, "canen" <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I am resending this -- seems it didn't reach the last time, sorry if it
> turns up twice
> 
>
> I've been messing around with the new MultiValueField and MultiWidget.
> I don't  know if the shortcoming is with me or with the implementation
> of the field and widget. Let's say I want to create a field that
> displays two select fields that are related, I'll use currency display
> as an example. The resulting HTML should look like:
>
> 
> USD
> EU
> 
> 
> 1000
> 2000
> 
>
> and returns a value like "USD 1000". The implementation I have so far
> is:
>
> # Field
> class MoneyField(MultiValueField):
> def __init__(self, currency=(), amount=(), required=True,
> widget=None, label=None, initial=None):
> fields = (ChoiceField(choices=currency),
> ChoiceField(choices=amount))
> super(MoneyField, self).__init__(fields, required, widget,
> label, initial)
>
> def compress(self, data_list):
> if data_list:
> return " ".join(i for i in data_list)
> return None
>
> # Widget
> class MoneyWidget(MultiWidget):
> def __init__(self, attrs=None, currency=(), amount=()):
> widgets = (Select(attrs=attrs, choices=currency),
> Select(attrs=attrs, choices=amount))
> super(MoneyWidget, self).__init__(widgets, attrs)
>
> def decompress(self, value):
> if value:
> return value.split(' ', 1)
> return ['', '']
>
> The problem is,  when I use the field I have to repeat the choices for
> both  widget and the field, like so:
>
> CURRENCY_CHOICES = [('USD', 'USD'), ('EU', 'EU')]
> AMOUNT_CHOICES = [('1000', '1000'), ('2000', '2000')]
>
> class MyForm(forms.Form):
> budget = MoneyField(
> label="Vacation budget (hotel amount only)",
> currency=CURRENCY_CHOICES,
> amount=AMOUNT_CHOICES,
> required=False,
> widget=MoneyWidget(currency=CURRENCY_CHOICES,
> amount=AMOUNT_CHOICES)
> )
>
> Am I doing something wrong here are is it just a caveat with using
> ChoiceField? Any guidance would be appreciated.
> 
> Cheers!


--~--~-~--~~~---~--~~
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: Initial data for a Select widget in newforms

2007-01-27 Thread canen

my_field = ChoiceField(choices=[(1, 1), (2, 2)], initial=1)
doesn't work?

On Jan 26, 7:04 pm, "Denis Frère" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm discovering newforms.
>
> It works pretty well, but I can't manage to give an initial selection
> in a ChoiceField (Select widget).
> I tried to read the code. I understand I have to give a "value"
> parameter to Select.render(), but how do I pass that value in the form
> initial data dictionary ?
> 
> Thank you.
> 
> Denis


--~--~-~--~~~---~--~~
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 MultiValueField

2007-02-06 Thread canen

Phil,

I think you must subclass it and define the compress method. See the
comments here http://code.djangoproject.com/browser/django/trunk/
django/newforms/fields.py#L412.  You will also need a MultiWidget to
go with the field.

On Feb 6, 10:04 am, "Phil Powell" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Can anyone provide any pointers on how I use MultiValueField?  Can I
> use it straight out of the box, or do I have to subclass to create a
> new field and a new MultiValueWidget?
>
> I thought that this code would just work:
>
> postcode = forms.MultiValueField(fields=(forms.CharField(max_length=4),
> forms.CharField(max_length=4)))
>
> But all I ever get rendered in my template (using {{ form.postcode }})
> is a single text input.
>
> Any advice would be much appreciated.
>
> -Phil


--~--~-~--~~~---~--~~
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 MultiValueField

2007-02-06 Thread canen

Phil,

Thought an example might help.

class VacationBudgetField(MultiValueField):
def __init__(self, required=True, label=None, widget=None,
initial=None, f_type=(), currency=(), amount=None):
fields = (ChoiceField(choices=f_type),
ChoiceField(choices=currency), IntegerField())
widget = widget or BudgetWidget(f_type=f_type,
currency=currency, amount=amount)
super(VacationBudgetField, self).__init__(fields, required,
widget, label, initial)

def compress(self, data_list):
if data_list:
return " ".join(str(i) for i in data_list)
return None

## Where BuggetWidget is
class BudgetWidget(MultiWidget):
def __init__(self, attrs=None, f_type=(), currency=(),
amount=None):
widgets = (Select(attrs=attrs, choices=f_type),
Select(attrs=attrs, choices=currency), TextInput())
super(BudgetWidget, self).__init__(widgets, attrs)

def decompress(self, value):
if value:
return value.split(' ', 2)
return ['', '', '']

## Used it like so...
budget = VacationBudgetField(f_type=[('a', 'a'), ('b', 'b')],
currency=[('d', 'd'), ('e', 'e')])

Hope that helps.

On Feb 6, 4:51 pm, "canen" <[EMAIL PROTECTED]> wrote:
> Phil,
>
> I think you must subclass it and define the compress method. See the
> comments herehttp://code.djangoproject.com/browser/django/trunk/
> django/newforms/fields.py#L412.  You will also need a MultiWidget to
> go with the field.
>
> On Feb 6, 10:04 am, "Phil Powell" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > Can anyone provide any pointers on how I use MultiValueField?  Can I
> > use it straight out of the box, or do I have to subclass to create a
> > new field and a new MultiValueWidget?
>
> > I thought that this code would just work:
>
> > postcode = forms.MultiValueField(fields=(forms.CharField(max_length=4),
> > forms.CharField(max_length=4)))
>
> > But all I ever get rendered in my template (using {{ form.postcode }})
> > is a single text input.
>
> > Any advice would be much appreciated.
>
> > -Phil


--~--~-~--~~~---~--~~
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 set the choices of Select Widget by code in the newforms

2007-02-10 Thread canen

If I understand what you are asking, choices can be set to a function,
as long as it returns the correct format. If you return a generator I
think there is a  bug that will only call it the first time the form
is rendered (e.g. if there is an error in the form the choices won't
show up when it renders again). To get around this wrap the function
call in  a list so it is forced to be evaluated, i.e choices =
list(my_function())..

Hope that helps.

[EMAIL PROTECTED] wrote:
> how?


--~--~-~--~~~---~--~~
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: are the Installed apps settings necessary?

2007-02-10 Thread canen

You don't need INSTALLED_APPS for views, it's more for models if I am
not mistaken, for example, syncdb won't work if your app is not in
INSTALLED_APPS.

voltron wrote:
> I posted this yesterday, but It did not show up, strange.
>
> According to the manual, one has to add apps to the INSTALLED_APPS
> setting tuple to make the usable in a project. I have created several
> test apps with views wired to urls in the projects url conf file, I
> was able to call up all urls without any problems.
>
> What is the main advantage of listing the apps in the INSTALLED_APPS
> variable? Not that I`m complaining, Im just curious, in fact if its
> not a necessity, It makes my apps more portable, I just copy the apps
> I need to another Project folder, wire up the urls  and they work, one
> step less to take.


--~--~-~--~~~---~--~~
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 django go to 11?

2006-05-21 Thread canen

I think this may solve at least one of your problems.
http://lukeplant.me.uk/blog.php?id=1107301634

Cheers.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Class name display when editing inline

2006-05-27 Thread canen

Does the class have a __repr_ method?

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


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Help with multiple object added on a single form with addManipulator.

2006-05-31 Thread canen

http://www.djangoproject.com/documentation/tutorial2/#adding-related-objects

I think that may be what you are looking for.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Repetitive background tasks

2006-06-27 Thread canen

You could use kronos.py, found here
http://snakelets.cvs.sourceforge.net/snakelets/Plugins/scheduler/kronos.py?view=markup
turbogears uses it for its scheduler. You can find the tg
implementation here
http://trac.turbogears.org/turbogears/browser/branches/1.0/turbogears/scheduler.py?rev=1363


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---