b.py:
import a
...
def test():
print a.x
--
Jeff Bauer
Rubicon, Inc.
On Mar 30, 6:43 am, "Aidas Bendoraitis" <[EMAIL PROTECTED]>
wrote:
> Let's say I have the files main.py, a.py and b.py
>
> main.py:
> ---
> x="some local value"
> import a
> ...
>
> a.py:
>
On Mar 29, 4:28 pm, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote:
> Strange -- I rarely (if ever) have had the runserver crash on me, and
> I use it almost every day.
Ditto. I don't think I've crashed it but once in three month's
of development.
--
Jeff Bauer
Rubicon, Inc.
On Mar 20, 4:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I have explained the technique with example code here:
> http://code.djangoproject.com/wiki/TemplatedForm
Very nice, Alex. You might consider adding this code
to the djangosnippets.org site. FWIW, you can replace
the first 4
My second favorite talk at PyCon 2007 (excepting only
the first day's keynote) was Titus Brown's discussion and
demo on testing. He demonstrated twill, nose,
wsgi_intercept, pinocchio, and scotch -- on both
TurboGears and Django frameworks.
He's now put together all the source code and demos
On Mar 16, 8:17 pm, "johnny" <[EMAIL PROTECTED]> wrote:
> >self.data.get('p_id')
>
> I tried it, getting error:
> Exception Type: AttributeError
> Exception Value: 'str' object has no attribute 'get'
You are calling this as a method from SalesForm?
Perhaps you'd better post a minimal
On Mar 17, 2:47 pm, enquest <[EMAIL PROTECTED]> wrote:
> Would you
> A. use the view type1 = article.objects.filter(...)
> type2 = article.objects.filter(...)
> idem
> idem
>
> OR
> B. use the template and use in the template IF condition
I think most people here will
On Mar 16, 4:49 pm, "johnny" <[EMAIL PROTECTED]> wrote:
> Now within SalesForm, how do I get p_id?
self.data.get('p_id')
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django
The quick answer would be to check through
the session data for a matching user id, but
there's one possible wrinkle: How do you
know when a user has logged off?
In my case (not yet implemented), I'll have
a timeout, but that still doesn't address
the issue of a user losing a connection and
I don't work much with form_for_model, but you
could probably do something like this:
IconForm = forms.models.form_for_model(Icon)
if request.method == 'POST':
form = IconForm(request.POST)
Then perform your own validation, assigning an error
to the field and returning:
context =
johnny,
Place p_id as a field in the template (it can be a hidden)
so you don't need to pass it as a parameter to SalesForm.
If you still need to override the __init__ method in
SalesForm, do it in the following manner:
class SalesForm(forms.Form):
def __init__(self, *args, **kwargs):
On Mar 16, 2:18 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> And that distinction -- between Field-level
> validation and Form-level validation -- also
> makes intuitive sense to me; it feels right
> that a Field only needs to know about itself,
I'm not particularly concerned about field
Just use a ChoiceField with a radio or checkbox widget.
http://www.djangosnippets.org/snippets/26/
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to
Benedict,
You add a clean_XXX method to your form class,
where XXX corresponds to the field name you wish
to validate.
In your clean_XXX method, you return
self.clean_data['XXX'] if your data validates,
otherwise raise a ValidationError exception.
I just posted a similar response on this
On Mar 15, 3:13 pm, "Grupo Django" <[EMAIL PROTECTED]> wrote:
> Note: I can't use "form_for_model" because it doesn't validate the
> date fields all right.
Define validation methods for your date fields, e.g.:
def clean_fecha_inicio_publicacion(self):
dt =
On Mar 15, 12:30 pm, "Tipan" <[EMAIL PROTECTED]> wrote:
> Realised my daft error in creating the dictionary. I've resolved that
> now and can happily pass the queryset data to the Form class by
> creating the dict. However, I'm still not sure how to pass the number
> of records to the Form class.
Bram,
Try removing (commenting out) the transaction decorator
and transaction.commit(), then re-run your code. The
ProgrammingError exception may be hiding the real
exception. At least that's been my experience.
--
Jeff Bauer
Rubicon, Inc.
On Mar 14, 7:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I've just added an entire page to the wiki about tutorials
> (http://code.djangoproject.com/wiki/Tutorials), with subcategories etc.
Very nice, especially the categories. Thanks!
--
Jeff Bauer
Rubicon, Inc.
Assuming you've got a 'mydate' attribute:
mydate = models.DateField(null=True)
You can conditionally assign it if null:
import datetime
art = Article.objects.get(pk=1)
if not art.mydate:
art.mydate = datetime.date.today()
art.save()
--
Jeff Bauer
Rubicon, Inc.
Roland,
The error message isn't the most helpful. ;-)
I had a similar problem back in January and tracked it
down to ticket #2536. My workaround was changing
the name of the ForeignKey attribute -- in your case
'project' -- to another name.
--
Jeff Bauer
Rubicon, Inc.
Tipan,
I've posted a code snippet that I think addresses your
issue: http://www.djangosnippets.org/snippets/82/
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To
Gustav, you're probably going to want a third table:
EmployeeDeptHistory
=
id
employee_id
department_id
transfer_date
Add a field attribute in the employee table
that references this history.
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
On Mar 13, 10:27 am, "Aljosa Mohorovic" <[EMAIL PROTECTED]>
wrote:
> what's the status of newforms?
http://tinyurl.com/2mtctq
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django
On Mar 13, 9:17 am, Jens Diemer <[EMAIL PROTECTED]> wrote:
> My sources are on a linux samba share. I used this share under windows
> xp and start the django developer server from this share.
>
> The reload mechanism don't work!
>
> When i copy the source from the share into my local filesystem,
Grupo Django:
> I'm programming a website in django and I'd
> like to know more about newfors, since I left
> the forms to the end, but now I have to start
> with them.
I think newforms is almost production-ready
and would advise anyone starting a new project
to consider using it in favor of
Anders,
I think the simple answer is for foreign keys (including
ChoiceFields when they're foreign keys), you want
to pass it the id/pk of the object. If the ChoiceFields
are a list of tuples, just pass it the value.
For multiple selection values, pass it a list of the values
you want
On Mar 7, 7:33 pm, "Jay Parlar" <[EMAIL PROTECTED]> wrote:
> When I render a calendar, I render one month at a time. Any
> suggestions on an efficient way to query the db for all the events in
> a given month?
I don't know enough about your calendar application,
but since we're talking about RFC
You can do something like this (all in a single command line),
assuming "myproject" is in PYTHONPATH:
DJANGO_SETTINGS_MODULE="settings" ./daily_cleanup.py
-or-
DJANGO_SETTINGS_MODULE="myproject.settings" ./daily_cleanup.py
Note: You won't be able to run the above script, unless you can do
Jay,
I would think you'd want to do a custom form for something like this.
I'll be doing something similar soon for a scheduling system. You're
familiar with the dateutil module?
http://labix.org/python-dateutil
--
Jeff Bauer
Rubicon, Inc.
If the goal is to write the actions to a log file, limodou's
recommendation for using signals is easier to implement. I'm more or
less duplicating the admin approach in my application.
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message
My solution is this: I've ripped out some stuff
from the old admin code and written AppLogModel
with three methods:
def add(self, request):
def remove(self, request):
def update(self, request):
The add/update methods call save() and remove
calls delete(). Each method invokes a log
There's no set data field for models, but if you wanted
to store the value as a string you could serialize it:
>>> from django.utils import simplejson
>>> simplejson.dumps(list(set(('tag1', 'tag2', 'tag1'
'["tag1", "tag2"]'
Then when you retrieve it, reverse the process:
>>>
Choices needs to be a sequence of (id, value) tuples. List
comprehensions are probably the most convenient way to
do this: http://www.djangosnippets.org/snippets/26/
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are
Can you add 'required=False' to your MultipleChoiceFields?
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to
In just the past few days, while djangosnippets.org was under active
development (and even down for several hours), the number of
submissions has grown to 45. Pretty cool. Anyone care to guess when
it will break 100? Kudos to James for setting up this site.
--
Jeff Bauer
Rubicon, Inc.
Responding to Arvind's post on Django developer: http://tinyurl.com/39d4vc
In some models, I have add() and update()
methods which call save() so I can perform
extra operations. Since my app knows
whether I want to add vs. update, there's
no extra query involved unless I choose
to make one by
> Is it possible to have the ID field be unique across several classes
> or tables? What i would like to do is, given the ID, load the object
> of that type out of the database. Does this make sense, and is it
> possible?
No, it doesn't make sense <0.5 wink>, but here's
how you might do it.
newsforms doctest demonstrates how to use SelectDateWidget:
trunk/tests/regressiontests/forms/tests.py
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post
You could assign DATABASE_PREFIX as an
environment variable, then have settings.py
get the value (untested):
# settings.py
import os
DATABASE_PREFIX = os.environ['DATABASE_PREFIX']
DATABASE_NAME = "site_%s_foo" % DATABASE_PREFIX
Then run manage.py from the command line:
$
Use the 'initial' keyword arg:
http://www.djangoproject.com/documentation/newforms/#initial
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group,
On Feb 18, 12:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Looks like you are rendering out the form class itself rather than an
> instance of the form.
Monster,
Thanks, but Honza had the correct reply. I need to access the
individual fields in the template, and BoundField is the
Hi, I'm the 985th person to attempt dynamic fields
in newforms. ;-)
Actually I've been able to do lots of dynamic stuff
in newforms. It's rendering the forms in templates
that sometimes confuses me. For example, given
the following code to build a form based on an
arbitrary number of
I find myself occassionally tripping over how
field attributes are handled in newforms because
it follows a Python convention of declaration,
but doesn't assign them directly to the form
instance.
>>> from django import newforms as forms
>>> class XForm(forms.Form):
... xattr = '42'
...
On Feb 12, 4:46 pm, "oggie rob" <[EMAIL PROTECTED]> wrote:
> You can specify the key/passkey files in the virtual
> host directive, which would probably be the most
> manageable way to do it:
> http://www.apache-ssl.org/docs.html#SSLCertificateFile
> However, if you use a wildcard you can use the
Have you looked into passing a widget attribute into your field? You
can either subclass a widget or create one from scratch.
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django
On Feb 12, 2:37 pm, "oggie rob" <[EMAIL PROTECTED]> wrote:
> For the cons, not true, really. You can use the same IP address.
Your advice contradicts my (very limited) understanding
of how SSL works, so please inform me of where my
ignorance lies ...
We're talking about *named* virtual
On Jan 28, 2:50 pm, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote:
> The "manage.py shell" command doesn't take into account your
> .pystartup file, but that would be a nice improvement if it would. If
> you could figure out how to make that happen and provide a patch,
> we'll integrate it into
Since Python 2.3 compatibility is an issue, per
ticket #3238, here are a couple possibilities:
(a) try/except import decimal and fall back to
float if decimal is not available.
(b) offer separate FloatField and a DecimalField
in newforms.
I'm -1 on (a) and +0 on (b). I find the
You can do something like this (untested):
class Survey(models.Model):
question = models.CharField(maxlength=100)
class SurveyForm(forms.form):
def __init__(self, *args, **kwargs):
super(SurveyForm, self).__init__(*args, **kwargs)
for o in Survey.objects.all():
On Jan 23, 9:16 pm, Le Van <[EMAIL PROTECTED]> wrote:
> I need to run manage.py sync to reflect the change.
> I don't like it at all. Do I need to run mange.py sync or is there
> another way to test ?
You can call the django.core.management functions from your
own code. I do something similar
Here's another possibility if you're still having problems
with __init__.py. Assuming you've got your other modules
in the directory:
mymodules/
othermodels.py
Put a conventional models.py file in your app directory:
myapp/
models.py
Then import othermodels classes into models:
#
Adrian Holovaty wrote:
Note that this behavior is up for discussion if many people find it
inconvenient. My initial thought is that it's a bit unbalanced to
allow for the definition of extra fields in a subclass but not
allowing the *removal* of fields in the same way.
Building forms is is
I don't think TinyRML is as powerful as RML, but you can't beat the price!
Is TinyRML being actively maintained?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send
Bram - Smartelectronix wrote:
I'm trying to do subclassing using newforms, but anything in the
subclass just doesn't get passed on to the superclass:
Maybe this would work for you?
class ExtendedForm(BaseForm):
def __init__(self, *args, **kwargs):
super(BaseForm,
Honza Král wrote:
definitely, if you have more that one user, you should definetely run
a dedicated db server, preferably one that supports transactions -
MySQL with InnoDB engine or postgreSQL (my choice ;) )
You may have already known this, but SQLite does support
transactions. I'm
ashwoods wrote:
using ical would probably be interesting too...
http://www.devoesquared.com/Software/iCal_Module
Some additional icalendar modules written in Python:
http://codespeak.net/icalendar/
http://vobject.skyhouseconsulting.com
--
Jeff Bauer
Rubicon, Inc.
Adrian Holovaty wrote:
Disclaimer: It does not yet map all database field types to the
correct form field/widget types, but it's a start.
FWIW: I've been putting a little helper function in my
views.py to conditionally tweak any rough edges ...
def model2form(pk):
if not pk:
Ramdas, in your template:
{{ form.as_ul }}
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to
I just read Honza Král's post where he describes handling this in
__init__:
http://tinyurl.com/ync6y9
--
Jeff Bauer
Rubicon, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to
I've been using newforms for a few days now and just
ran across something in ChoiceField that might be worth
sharing.
The most common use case for a choice field is to
pass a static list of choices. In the example
below, it's a list of flavor choices:
model.py:
class Flavor(models.Model):
Stefan Foulis wrote:
> what I'm trying to do is divide up the views.py file into multiple
> files because the single views.py file in some of my apps is getting
> very cluttered.
>
> I tried just making a views subdirectory and then placing multiple
> files with groups of views inside
Ditto to
When a user logs on, I want to invoke a special method.
There doesn't appear to be a way to add a hook/callback
to django.contrib.auth.views.login, so my approach is to:
1. Create mysite/login/views.py and copy the login/logout
methods from django into it. Add code to invoke post-login
Russell Keith-Magee wrote:
You have imported the 'source' model to allow access to referral type
as a Python module - but have you added 'source' to INSTALLED_APPS? If
you don't do this step, Django doesn't know about the model, so it
can't validate the foreign key.
Of course. Thanks for the
I'm responding to a thread over 60 days old:
http://tinyurl.com/ycmj9l
Guillermo implies that a model should be easily shared
between Django applications via import. However, if I
attempt to move Model class to a shared module, the
model won't validate. For example:
class
63 matches
Mail list logo