On Oct 22, 5:10 pm, Ardesco <[EMAIL PROTECTED]> wrote:
> Taking an example from Chapter 7 of the Django Book:
>
> from forms import PublisherForm
>
> def add_publisher(request):
> if request.method == 'POST':
> form = PublisherForm(request.POST)
> if form.is_valid():
>
When I get an error on viewing a snippet I copy the URL into Google
and click the Cached version.
On Oct 22, 5:08 pm, Gmail <[EMAIL PROTECTED]> wrote:
> i found lots of snippets to download,but the server always says it is
> down.
--~--~-~--~~~---~--~~
You receiv
On Oct 22, 3:56 pm, "Matthew Talbert" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am being considered for a project that would involve re-writing an
> application which is currently in MS Access/VBA. The application is an order
> entry/shop management software for a small vertical market. I am st
Have you written a unit test that executes the view? If so, and if it
doesn't always happen, you can run the unit test over and over quickly
to see if it has something strange to do with the order of how things
are important or something crazy like that.
By the way, writing tests can often help fi
On Oct 22, 1:23 pm, Net_Boy <[EMAIL PROTECTED]> wrote:
> Hi,
> I am trying to make a view function to get the posted values and
> make some comparison (if x.value >= y.value)..
> where x is the model that I got it's values from the post
> and y is the other model .
>
> example:
>
> def comp
I don't see what splitting it up into "sub apps" has anything to do
with it?
What happens when you add the related_name attribute to your model
fields?
Here's some code from one of my apps:
class M(models.Model):
...
from_user = models.ForeignKey(User, null=True,
related_name='from')
On Oct 22, 8:24 am, MrMuffin <[EMAIL PROTECTED]> wrote:
> I'm generating html forms from models using ModelForm. When I do
> something like :
>
> >>> article = Article.objects.get(pk=1)
> >>> form = ArticleForm(instance=article)
>
Change it's widget to hidden I think should work
>>> from django
It's definitely possible. Here's an example:
from django.contrib.auth.models import User
staff = User.objects.create_user(username='s', password='s',
email='[EMAIL PROTECTED]')
#staff.is_staff = True
client = Client()
assert client.login(username='s', pass
Not down but you get lots of errors. They're probably working on it. I
hope.
On Oct 22, 5:08 pm, Gmail <[EMAIL PROTECTED]> wrote:
> i found lots of snippets to download,but the server always says it is
> down.
--~--~-~--~~~---~--~~
You received this message becau
If I publish
http://someurl/myview?foo=1&foo=2&foo=3
How do I turn this into foo = ['1','2','3']?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-user
On Nov 14, 9:31 pm, Javier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've create a model:
>
> class ImagenesLugar(models.Model):
> archivo = models.ImageField(upload_to="imageneslugar/")
> texto = models.CharField(max_length=400)
>
> The thing is that when i create a new instance of this mode
What's faster, locmem or memcache?
I know that the docs rave on about how fast memcache is but what about
locmem? That sounds pretty fast to me since it doesn't need another
TCP service and just uses the RAM.
My particular site (for mobile phones without any media) is so tiny
that I wouldn't worr
The trick is to use .query.group_by.
Here's an example that will work::
>>> from collection.models import Edition, User, Rating
>>> Rating.objects.all().delete()
>>> Edition.objects.all().delete()
>>>
>>> e1 = Edition.objects.create(title=u'Title1', binding=u'')
>>> e2 = Edition.objects.create(ti
Is there an alternative to the test runner that comes by defauly with
Django (svn version)? The one that you get doesn't have colour coding
and it doesn't have the option to stop all other tests after the first
failure.
--~--~-~--~~~---~--~~
You received this messag
>From http://www.djangoproject.com/documentation/testing/
"4. Looking for unit tests and doctests in the models.py and tests.py
files in each installed application."
Next to models.py I have forms.py which does exactly what the filename
suggests: it defines forms. I've put some doctests in these
> If your looking for an example to follow, the code for
> django.test.simple isn't too hard to tear apart and customize for your
> own purposes.
OK. Here's how I solved it:
from django.test.simple import *
from django.test.simple import run_tests as orig_run_tests
# my app is called 'classes'
I've got something like this:
class Class(models.Model):
...
date = models.DateTimeField()
I'm trying to filter and get all objects on a particular day:
>>> Class.objects.all()[0].date
datetime.datetime(2008, 9, 4, 15, 10, 23, 359032)
>>> Class.objects.filter(date=datetime(2008,
On Sep 25, 8:41 pm, "Frédéric Sidler" <[EMAIL PROTECTED]>
wrote:
> What it the best Django stack today.
>
> In django doc, it says that apache with mod_python is the best
> solution in production. But in the same time I see that everyblock use
> nginx (probably in mode fastcgi).
>
> Did you some
This works:
>>> from django.db.models import Q
>>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
>>> Books.objects.filter(qset)
But what if the list of things I want to search against is a list.
E.g.
>>> possible_authors = [u"Foo", u"Bar"]
???
I have a solution but it's very
I write a lot of tests and with using DATABASE_NAME = ':memory:' the
tests can run very fast.
Usually I save the file I'm working on (e.g. models.py, test_views.py
etc.); Alt+Tab, arrow up, Enter.
Common, right?
Is there a good script or command (linux) for automatically rerunning
the tests? I k
On 3 Aug, 10:12, Thomas Guettler wrote:
> Hi,
>
> How can I display a link to the edit page of a foreign key?
>
> Example:
>
> class Place:
> city=models.ForeignKey(City)
>
> In the admin page of the place I want a link to the city admin page.
>
class PlaceAdmin(admin.ModelAdmin):
list
Not sure I understand what you want to achive but you talked about
changing one class attribute when you change another.
Look at this for example/inspiration::
class Foo(object):
status = ''
def __init__(self):
self.name = ''
def __setattr__(self, k, v):
if k == 'sta
Look at if perhaps the project "mysite" was created somewhere else,
like for example where the django-admin.py file is located.
If so, there could be a fundamental problem with your setup or a bug
in the windows implementation for django-admin.py
At worst, search your whole hard drive for it.
On
I would write a management command and let a cron job fire off to run
it.
See this for how to write management commands:
http://docs.djangoproject.com/en/dev/howto/custom-management-commands/
Then your cron job can look something like this:
*/5 * * * * python /path/to/manage.py copyfromftp >> /de
Untested but should work (in admin.py):
class ThingAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(ThingAdmin, self).queryset(request)
qs = qs.filter(some_integer_field__gt=10)
return qs
admin.site.register(Thing, ThingAdmin)
On 3 Aug, 10:52, selcuk
r.
>
> But list_display does not get used on the edit page of an object.
>
> If you use raw_id the ID of the foreign key gets displayed right to the
> input field. It would be nice to make it a hyperlink.
>
> HTH,
> Thomas
>
> Peter Bengtsson schrieb:
>
Here's the models:
# models.py
class Article(models.Model):
title = models.CharField(max_length=100)
# urls.py
urlpatterns = patterns('',
(r'^delete-rolledback/$', delete_rolledback),
)
# views.py
def delete_rolledback(request):
transaction.enter_transaction_management()
transac
I have found that when running this as a normal server, the rollback
DOES work. It's just in tests it doesn't work.
On 5 Aug, 17:27, Peter Bengtsson wrote:
> Here's the models:
>
> # models.py
> class Article(models.Model):
> title = models.CharField
2009/8/5 Alex Gaynor :
>
> On Wed, Aug 5, 2009 at 11:31 AM, Peter Bengtsson wrote:
>>
>> I have found that when running this as a normal server, the rollback
>> DOES work. It's just in tests it doesn't work.
>>
>> On 5 Aug, 17:27, Peter Bengtsson wro
On Aug 25, 4:54 pm, John Baker wrote:
> Some of my views need to process arbitrary incoming data that isn't a
> normal web request i.e. process an incoming document and return an
> altered document.
>
> How do I get a view to process raw incoming data rather than the usual
> encoded parameters a
Suppose you have a PDF (generated or downloaded from the internet),
are you able to get it printed by scripting?
On Aug 25, 4:38 pm, mettwoch wrote:
> How do the Django people handle printing directly on Windows? I
> remembered abouthttp://timgolden.me.uk/python/win32_how_do_i/print.html,
> but
Here's an example:
http://www.djangosnippets.org/snippets/1322/
On Aug 25, 5:43 pm, John wrote:
> > Isn't it just
> > request.raw_post_data
>
> Thanks and I suspected it was that but hoped there might be a little
> example somewhere as the docs don't say much only this:
>
> HttpRequest.raw_post_
Do you mean when you write tests?
If so, when you get the response you can extract all the variables
that was created inside the view if you're using locals().
That way, you can probably get the form instance (created for example
by form=MyForm(request.POST)) which you can then untangle to get all
what's wrong with turning it into a list? If you gzip it it won't be
that big.
On Aug 25, 5:16 pm, John Baker wrote:
> I need to json serialize some very large objects which include large
> arrays. How can I do this in django? The arrays will be very big and
> heavily processed before so need to
I fear your only option is to write a recursive function which you
feed with what you define to be "the end of the chain".
You can collect all the entries in a mutable list. Some example,
untested, code:
def get_all_parents(list_, current):
for entry in current.following_to.all():
lis
You can add and modify fields on a form in the form's __init__
function.
class MyForm(forms.Form):
country = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['country'].choices = \
[(c.iso_code, c
Why doesn't this work?
from django.core.management.base import BaseCommand
from django.db import transaction
class Command(BaseCommand):
help = "bla bla"
def handle(self, *app_labels, **options):
from myapp.models import MyModel
transaction.enter_transaction_management()
Crap! Just as I closed this message I found another group post and the
answer was to do::
transaction.enter_transaction_management()
transaction.managed(True)
On Apr 7, 5:24 pm, Peter Bengtsson wrote:
> Why doesn't this work?
>
> from django.core.manageme
I have this
@cache_page(MANY_HOURS)
def foo(request):
calculate_something_complex()
...
@login_required
def bar(request):
change_complex_data()
#here I want to invalid foo()'s cache
...
But other actions elsewhere will need to invalidate the cache for
this. I could do a '/
When I register my model to the admin it doesn't allow me to use a
method in list_filter :(
This pseudo code should explain my situation:
class MyModel:
gender = models.CharField()
age = models.IntegerField()
@property
def man(self):
return self.gender == 'male' and
Apparently, Adrian doesn't think it should work with anything but DB
fields
http://code.djangoproject.com/ticket/2334
Crap!
On May 29, 1:49 pm, Peter Bengtsson wrote:
> When I register my model to the admin it doesn't allow me to use a
> method in list_filter :(
> This
"wraps" (not overrides) so it does not work.
For now I've given up :(
On May 29, 1:49 pm, Peter Bengtsson wrote:
> When I register my model to the admin it doesn't allow me to use a
> method in list_filter :(
> This pseudo code should explain my situation:
One way of doing it, and to be honest the only one I know, is to set a
limit in the fronting web server.
In Nginx for example you add:
client_max_body_size 10M;
Sadly this means that if a user tries to upload a 11Mb file you won't
be able to confront them with a user-friendly "error" message.
Signals or no signals I think your profile model is wrong. By making
it a subclass of User you're effectively getting all the fields of the
User model.
Write your profile model like this instead:
class Employee(models.Model):
user = models.ForeginKey(User)
address = models.CharField(...)
On Sep 13, 1:35 pm, ramanathan wrote:
> (r'^/(.+)/$','proj.register.views.activate')
>
Change to
(r'^(.+)/$','proj.register.views.activate')
(notice the removed forward slash in the beginning otherwise you have
to expect the URL to be
http://localhost:8000//90/
> (r'^(?P.*)$', 'django.views.st
Hard to say as it depends on your app but can't you just run the app
on your laptop and see how much memory it takes up when you run some
basic stresstests.
Django is quite close to pure python but when you extract large lists
of model instance objects into lists it can push the memory
consumption
I dont know what db.UserProperty() is but my guess is that that's
something related to the model.
Your form doesn't understand that so it defaults to None.
If you omit the field owner from the form, perhaps the form won't
attempt to fiddle with this and then the model is allowed to do it's
magic.
Suppose you have a template called monster.html that looks like this:
Company name
Lorem ipsum
Then, create a Django view and make it render a template called, say,
home.html which you make to look like this:
{% extends "monster.html" %}
{% block title %}My Company!{% endbloc
ething similar as auro_current_user_add you
> would think?
>
There isn't. The current logged in user is available from the request
which is something you only have in views.
The models is just about mapping SQL to python classes.
> On Sep 13, 4:55 pm, Peter Bengtsson wrote:
>
> > I do
about2flip
You have to go through the python tutorial I'm afraid.
Python files must be written in plain text so you have to use
something like Notepad.
On 14 Sep, 08:50, about2flip wrote:
> Thanks for reply. No I get:
> SyntaxError: unexpected character after line continuation character
>
> I am
Perhaps it's this you're looking for:
current_url = request.build_absolute_uri()
On 14 Sep, 01:12, Shuge Lee wrote:
> How to get current URL ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To
Suppose I've got this code:
# template.html
Info: {{ article_instance.count_words }} words
# models.py
class Article(models.Model):
text = models.TextField()
def count_words(self):
raise AttributeError('debugging')
Then, when I render that page I get:
Info: words
When I want is
On 20 Oct, 15:48, Chris Withers wrote:
> Shawn Milochik wrote:
> > I know this doesn't answer the hard part of your question, but here's
> > a simple way I delete old stuff from a database via an external script
> > that's run by cron:
>
> > Item.objects.filter(date_updated__lte = datetime.
UPDATE!
If I raise some other error inside the python code (e.g. ValueError)
it's not suppressed.
Seems a design error in Django. Will carry on this discussion
somewhere else.
On 21 Oct, 14:05, Peter Bengtsson wrote:
> Suppose I've got this code:
>
> # t
Found the ticket for it:
http://code.djangoproject.com/ticket/11421
On 21 Oct, 14:17, Peter Bengtsson wrote:
> UPDATE!
> If I raise some other error inside the python code (e.g. ValueError)
> it's not suppressed.
> Seems a design error in Django. Will carry on this discussion
On 21 Oct, 14:29, bruno desthuilliers
wrote:
> On 21 oct, 15:05, Peter Bengtsson wrote:
>
> > Suppose I've got this code:
>
> > # template.html
> > Info: {{ article_instance.count_words }} words
>
> > # models.py
> > class Article(models.Mode
What customizations have your done in the templates/admin/ folder of
the app that isn't working?
On 21 Oct, 17:22, kkerbel wrote:
> i upgraded django 1.0.2 to 1.1 stable and I cannot see the admin
> actions bar in one of my apps...or any of them for that matter. My
> fresh install of 1.1 has th
2009/10/22 bruno desthuilliers :
>
>
>
> On 21 oct, 16:00, Peter Bengtsson wrote:
>> On 21 Oct, 14:29, bruno desthuilliers
>> wrote:> On 21 oct, 15:05, Peter Bengtsson wrote:
>>
>> > a NotImplementedError would be more appropriate !-)
>>
&g
The way you set up the ordering (e.g. 'change_date') just change that
to '-change_date'. A minus in front of the ordering keyword reverses
the sort order.
On 20 May, 06:32, rahul jain wrote:
> Hi,
>
> In my model, I have set up one filter which helps in filtering out the
> results on admin Panel.
There are much more efficient tree implementation made available for
Django.
https://tabo.pe/projects/django-treebeard/
A much better place to start.
On 20 May, 07:06, Danfi wrote:
> Hi,
> In my models, I use "parent = models.ForeignKey('self', blank = True,
> null = True) " create a Folder tree
This is a new feature of Django 1.2. I'm curious, why does it want to
do this? I want to control this for my settings so that I can things
like disabled verify_exists on my URLFields when I run tests.
# django/test/simple.py
class DjangoTestSuiteRunner(object):
def __init__(self, verbosity=1,
Without caring or even attempting to understand your business I sounds
like you just need to stop using a BooleanField() and instead use a
ForeignKey(null=True) and then judge if it's "on_premise" by a method
rather than a field something like this:
class MyModel(Model):
related_premise = Fore
By being bound it means that you will have run the .is_valid() method
of the form instance once you've instanciated it with your POST and
FILES data.
E.g.
form = BrewImageFrom(data=request.POST, files=request.FILES)
if form.is_valid():
brewimage = form.save()
On Sep 23, 3:00 pm, Joel Klabo
When not using SQLite for running my tests it takes a aweful long time
to install all the indexes.
Considering that indexes are there for speeding up selects when the
number of rows is very high I realise I don't need them during a test
run.
Is there a way to disable index creation during the sync
Keep it simple. Use nginx or apache and in your Django app you simply
write to the filesystem. "Invalidation" can be done by simply deleting
the file which is easy.
Something like nginx for serving static file is faster than anything
else. I'm sure you already know how to deploy static files such a
It's not stripped by Django. You must just have forgotten to urlencode
the parameters before it goes back into the app.
On Jan 22, 12:00 am, Sumanth wrote:
> Hi ,
>
> I am having newlines in GET data , but when the data comes to server
> newline chars are removed. Is that any way I can retain new
Just install django-tagging as normal so that it's on the system path
and included in your settings.py INSTALLED_APPS. Then you can run its
tests. Leave it like that.
Then to make it work exactly like you want it to work, subclass it.
Your other apps shouldn't pretend to depend on tagging but inste
Use signals. django-registration will create a new User so you can do
something like this:
from django.db.models.signals import post_save
def give_permission(sender, user, created, **__):
if created:
user.groups.add(u"My group")
post_save.connect(give_permission, sender=User)
If you w
Sounds like something you'd have to do with javascript by extending
the admin interface's templates.
Any other default values are best done by settings up signals for your
User class.
On a more general, yet important note, I would strongly advice against
making your own User model unless you reall
I'm running Nginx in front of Django using FCGI. I start it something
like this in my bash sysadmin scripts:
python /foo/manage.py runfcgi host=127.0.0.1 port=9000 pidfile=/var/
foo.pid \
errlog=err.log outfile=out.log
What I'm contemplating is running multiples of this s
The old django debug-toolbar used to make it possible to group
statements that were the same so you can see if a particular statement
was called repeatedly. This does not appear to be possible in the
latest version; or am I wrong?
--
You received this message because you are subscribed to the Goo
If what you want to achieve is to log in a user programmatically you
don't do that by authenticating by username and password.
Example:
def login_by_id(request):
user = FacebookUser.objects.get(...).user
from django.contrib.auth import load_backend, login
for ba
Is it possible to do
{% cycle "odd" "even" as parent_cycle_thing %}
?
If so there's your answer.
On 25 Mar, 19:57, mhulse wrote:
> Hi!
>
> Example code:
>
> ==
>
> {% for pretty_date, days_events in date_days_events_tuple %}
> ...
>
> ...
> {% for details in days_events %}
> ...
> ...
>
Generally, try to build your application so that it doesn't blindly
depend on the profile existing. The signal example Tom showed you is
good as it means you won't have to check if the UserProfile instance
exists for the user on every turn. However, don't depend on the data
within. Keep it light an
On 26 March 2010 11:09, Daniel Roseman wrote:
> On Mar 25, 7:17 pm, Peter Bengtsson wrote:
>> The old django debug-toolbar used to make it possible to group
>> statements that were the same so you can see if a particular statement
>> was called repeatedly. This does not app
On Jun 16, 11:07 am, "James Matthews" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am trying to import a library that is in a non-standard location ~/opt/lib
> (I am in a shared environment) and i added it to my "LD_LIBRARY_PATH"
> however Django tells me it cannot find it and me a 500 error.
>
> In p
I have TEMPLATE_DEBUG on but if I write::
X{{ somethingthatdoesnotexits }}X
The output is just XX and no error. How can I enable explicit
rendering and raise errors on typos in the templates?
--~--~-~--~~~---~--~~
You received this message because you are subsc
(django version 1.3.1)
To explain my set up would be very hard as it's not just plain Django but
there's a bunch of other third parties involved but we'll have to try.
I'm getting this traceback when running tests::
Traceback (most recent call last):
File
"/Users/peterbe/dev/MOZILLA/PTO/pto/
I have a django project on django 1.6. It's using django-nose and it's
using sqlite3's :memory: trick:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
Before I added `south` to INSTALLED_APPS it would take about ~5 seconds to
ru
;t run anything in runtime because
I have `COMPRESS_OFFLINE = True` on and I run compress before running
tests.
On Tuesday, January 20, 2015 at 12:37:44 PM UTC-8, Peter Bengtsson wrote:
>
> I have a django project on django 1.6. It's using django-nose and it's
> using sqlit
It seems, for some reason settings.COMPRESS_ENABLED gets set to False when
south is installed.
On Tuesday, January 20, 2015 at 12:37:44 PM UTC-8, Peter Bengtsson wrote:
>
> I have a django project on django 1.6. It's using django-nose and it's
> using sqlite3's :memo
I have this code that looks something like this (django 1.6.11):
def test_something(self):
url = someobject.get_url()
User.objects.create_user('a', 'a...@example.com', 'secret')
assert self.client.login(username='a', password='secret')
r = self.client.get(url)
assert r.status_c
esday, 31 March 2015 22:27:32 UTC+2, Peter Bengtsson wrote:
>>
>> I have this code that looks something like this (django 1.6.11):
>>
>> def test_something(self):
>> url = someobject.get_url()
>> User.objects.create_user('a', 'a...@example.com
I've been googling for an explanation but nothing's come up.
See
https://github.com/django/django/blob/master/django/forms/fields.py#L447
If you use a `DateField` in your form, don't you expect it to produce a
`datetime.date` instance?
E.g.
class MyForm:
start = forms.DateField()
def
On Tuesday, March 4, 2014 12:47:03 PM UTC-8, Tom Evans wrote:
>
> On Tue, Mar 4, 2014 at 8:27 PM, Peter Bengtsson
> >
> wrote:
> > I've been googling for an explanation but nothing's come up.
> >
> > See
> > https://github.com/djan
On Tuesday, March 4, 2014 5:19:17 PM UTC-8, Tom Evans wrote:
>
> On Tue, Mar 4, 2014 at 10:45 PM, Peter Bengtsson
> >
> wrote:
> > The link was to django master. So it's in all versions.
> >
>
> Well, that doesn't necessarily follow does it? It c
86 matches
Mail list logo