Re: Heisenbug to do with self.client losing its sessionstore
No :( It's still a mystery. It's really annoying. It resurfaced again about 2 weeks ago and it caused several test failures that I could never reproduce locally. I have some tests that look like this: class TestCase(DjangoTestCase): def setUp(self): super(TestCase, self).setUp() User.objects.create(...) assert self.client.login(...) def test_something(self): response = self.client.get('/some/url/for/signed/in/people') assert response.status_code == 200 But sometimes, for no reason I can understand, that fails because at the point of doing the self.client.get the self.client.session is empty! :( On Friday, June 5, 2015 at 8:10:52 AM UTC-7, mlpi...@qdqmedia.com wrote: > > Hi, I am facing a similar issue and have not found any solution yet. I was > wondering if you had been able to fix this? > > On Tuesday, 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', 'secret') >> assert self.client.login(username='a', password='secret') >> r = self.client.get(url) >> assert r.status_code == 302 # because you're not allowed to view it >> someobject.privacy_setting = 'different' >> r = self.client.get(url) >> assert r.status_code == 200 # now you can view it according the >> business logic >> >> >> This code has been working for many many months but suddenly it started >> to Heisenfail with the last line being 302 != 200. >> It might be related to caching somewhere else because it ONLY ever fails >> (if it fails!) when I run the whole test suite. >> After a lot of painful debugging I concluded that sometimes, that last >> self.client.get(url) causes `request.user == > >` >> >> I.e. for the second request made by that logged in client, it's all of a >> sudden NOT logged in!! Not always. Only sometimes. :( >> >> I put in a debugging line just before that last test like `assert >> self.client.session['_auth_user_id']` and that sometimes fails. Almost as >> if the testclient loses its session store DURING the lifetime of the test. >> Sometimes. >> >> >> Anybody seen anything similar that might be able to explain it or give me >> a clue? >> >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a0207a9f-2928-48a5-80f5-969e2180675e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Heisenbug to do with self.client losing its sessionstore
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_code == 302 # because you're not allowed to view it someobject.privacy_setting = 'different' r = self.client.get(url) assert r.status_code == 200 # now you can view it according the business logic This code has been working for many many months but suddenly it started to Heisenfail with the last line being 302 != 200. It might be related to caching somewhere else because it ONLY ever fails (if it fails!) when I run the whole test suite. After a lot of painful debugging I concluded that sometimes, that last self.client.get(url) causes `request.user == >` I.e. for the second request made by that logged in client, it's all of a sudden NOT logged in!! Not always. Only sometimes. :( I put in a debugging line just before that last test like `assert self.client.session['_auth_user_id']` and that sometimes fails. Almost as if the testclient loses its session store DURING the lifetime of the test. Sometimes. Anybody seen anything similar that might be able to explain it or give me a clue? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87a1ed74-6ce2-49fa-886c-9cb015a90555%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Installing south and using sqlite3's :memory: ruins total test suite time
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 :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 > run the 371 tests. > > So I add `south` to INSTALLED_APPS (and make sure django_nose is mentioned > last) and I also set SOUTH_TESTS_MIGRATE=False (meaning I can put things in > the the 0001_initial.py files and it doesn't get executed). > > Now it takes ~50 seconds to run the whole test suite. That's 10x times > slower! :( > > I ran the tests with nose-timer and it basically seems every test now gets > a lot slower. You can compare > https://gist.github.com/peterbe/34c9b14028d63429491c with > https://gist.github.com/peterbe/9202c20edee964a370d3 > > > Anybody know what's causing South (1.0.2) to make everything so much > slower? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0ea1c01f-d887-427e-a2d4-f3b2cbb97b4c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Installing south and using sqlite3's :memory: ruins total test suite time
Quick update there, I've figured out where the time is spent. Those ~45 seconds is caused by django_compressor calling out to `lessc` to convert .less files to .css. I'm now trying to figure out why having south in INSTALLED_APPS changes whether that gets run or not. It shouldn'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 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 > run the 371 tests. > > So I add `south` to INSTALLED_APPS (and make sure django_nose is mentioned > last) and I also set SOUTH_TESTS_MIGRATE=False (meaning I can put things in > the the 0001_initial.py files and it doesn't get executed). > > Now it takes ~50 seconds to run the whole test suite. That's 10x times > slower! :( > > I ran the tests with nose-timer and it basically seems every test now gets > a lot slower. You can compare > https://gist.github.com/peterbe/34c9b14028d63429491c with > https://gist.github.com/peterbe/9202c20edee964a370d3 > > > Anybody know what's causing South (1.0.2) to make everything so much > slower? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c119985d-b914-4e6d-88c5-de7cf04a080c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Installing south and using sqlite3's :memory: ruins total test suite time
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 run the 371 tests. So I add `south` to INSTALLED_APPS (and make sure django_nose is mentioned last) and I also set SOUTH_TESTS_MIGRATE=False (meaning I can put things in the the 0001_initial.py files and it doesn't get executed). Now it takes ~50 seconds to run the whole test suite. That's 10x times slower! :( I ran the tests with nose-timer and it basically seems every test now gets a lot slower. You can compare https://gist.github.com/peterbe/34c9b14028d63429491c with https://gist.github.com/peterbe/9202c20edee964a370d3 Anybody know what's causing South (1.0.2) to make everything so much slower? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f13473b-5a24-4546-b42e-8d1ab81b864c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Why doesn't a forms.fields.DateField always return a datetime.date instance?
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 could have been > changed recently in trunk, say for 1.6 release. If you were using 1.5 > it could be different. I haven't looked back, since you didn't > actually say what version you are using. > > Trivially, in 1.6 at least, it works precisely as you expect: > > >>> class A(forms.Form): > ... s = forms.DateField() > ... def clean_s(self): > ... print repr(self.cleaned_data['s']) > ... return self.cleaned_data['s'] > ... > >>> A(data={'s':'2012-12-25'}).is_valid() > datetime.date(2012, 12, 25) > True > > Right you are! It's independent of version. My actual code, where this question arose from, isn't using forms.Form as the base class. Instead a custom base class which clearly is causing some problem. I'm using BaseForm from this http://www.peterbe.com/plog/django-baseform Clearly it's affecting it in some bad way. > > Does this form also have a custom clean() method, is that doing > something silly with cleaned_data['start'] after the form field has > pythonized it and before your clean_start() method is called? > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f3831069-5e8b-45bf-8faf-c522310e7d46%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Why doesn't a forms.fields.DateField always return a datetime.date instance?
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/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 clean_start(self): > > if self.cleaned_data['start'] > datetime.date.today(): > > raise ValidationError('too futuristic') > > return self.cleaned_data['start'] > > > > This won't work! You'll get a TypeError if you run that code. > > Why is that? > > > > It'd be easy to fix but because it's so blatant I just suspect I missed > > something obvious. > > What version of django are you using? > > The link was to django master. So it's in all versions. > The code linked indicates quite clea > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/81ccd7ce-d138-47e1-97ee-87742ac5cb42%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Why doesn't a forms.fields.DateField always return a datetime.date instance?
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 clean_start(self): if self.cleaned_data['start'] > datetime.date.today(): raise ValidationError('too futuristic') return self.cleaned_data['start'] This won't work! You'll get a TypeError if you run that code. Why is that? It'd be easy to fix but because it's so blatant I just suspect I missed something obvious. Peter -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5ddd8ee-b72e-46c8-9d3c-c211aa76fa25%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Very strange KeyError on 'PORT' in db/backends/mysql/base.py
(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/vendor/src/django/django/utils/unittest/case.py", line 339, in run testMethod() File "/Users/peterbe/dev/MOZILLA/PTO/pto/apps/users/tests.py", line 310, in test_mozilla_ldap_backend_basic user, created = back.get_or_create_user('peter', ldap_user) File "/Users/peterbe/dev/MOZILLA/PTO/pto/apps/users/auth/backends.py", line 146, in get_or_create_user .filter(email__iexact=ldap_user.attrs.get('mail')[0])): File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/models/query.py", line 107, in _result_iter self._fill_cache() File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/models/query.py", line 772, in _fill_cache self._result_cache.append(self._iter.next()) File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/models/query.py", line 273, in iterator for row in compiler.results_iter(): File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/models/sql/compiler.py", line 680, in results_iter for rows in self.execute_sql(MULTI): File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/models/sql/compiler.py", line 734, in execute_sql cursor = self.connection.cursor() File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/backends/__init__.py", line 252, in cursor cursor = util.CursorWrapper(self._cursor(), self) File "/Users/peterbe/dev/MOZILLA/PTO/pto/vendor/src/django/django/db/backends/mysql/base.py", line 318, in _cursor if settings_dict['PORT']: KeyError: 'PORT' So just above line 318 in db/backends/mysql/base.py I put in this:: if 'PORT' not in settings_dict: # my debugging from pprint import pprint;pprint(settings_dict) # mydebugging if settings_dict['PORT']: kwargs['port'] = int(settings_dict['PORT']) And then when printed out it prints this:: {'ENGINE': 'django.db.backends.mysql', 'HOST': 'localhost', 'NAME': 'test_pto', 'OPTIONS': {'charset': 'utf8', 'init_command': 'SET storage_engine=InnoDB', 'use_unicode': True}, 'PASSWORD': XX, 'TEST_CHARSET': 'utf8', 'TEST_COLLATION': 'utf8_general_ci', 'TEST_MIRROR': None, 'TEST_NAME': None, 'TIME_ZONE': 'America/Los_Angeles', 'USER': 'root'} As you can see it's a copy of settings.DATABASES but with the name having an added prefix of "test_". Except now it's missing 'PORT'. My settings look like this:: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'pto', 'USER': 'root', 'PASSWORD': , 'HOST': '', 'PORT': '', 'OPTIONS': { 'init_command': 'SET storage_engine=InnoDB', 'charset' : 'utf8', 'use_unicode' : True, }, 'TEST_CHARSET': 'utf8', 'TEST_COLLATION': 'utf8_general_ci', }, } Having a blank 'PORT' key shouldn't be a problem. Removing the key doesn't help. However, setting it to '3306' *does* help but that's not getting to the root of the problem. I know it's a very very hard problem to debug but by mentioning it perhaps other people can chip in some experience. It's a long shot. A couple of other things: * It fails on the first and every test * Debugging self._connection['default'] a bit I find that it has 'PORT' for a while (I think whilst setting up fixtures and stuff) and then stops having it. * I'm using github.com/jbalogh/test-utils but that hasn't changed and it used to work perfectly fine a couple of days ago. * Switching test runner to TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner' solves the problem but I didn't need to do this before. * Colleagues have been unable to reproduce this using very similar stacks which could mean it's OS related to threading or something really low-level. Sigh... -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/p21FozseT44J. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Can I run tests without installing indexes?
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 syncdb? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Image Upload question
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 wrote: > I have a form trying to upload an image. In the docs it says that the > form must be bound to save a file. This is an issue for me because I > wan't to save the file with other data such as the User object that > saved it. I can't put a User object in a form so I put the username in > a hidden form field which allows me to find the user in the view and > use it. But, I can't bind the form with data not from POST right? I > need to do request.FILES, in combination with data not coming from > post. I'm obviously confused I would appreciate some guidance here > > Here's the code:http://gist.github.com/594136 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to implement this model
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 = ForeignKey(Premise, null=True) def on_premise(self): return self.related_premise is not None def get_related_premise(self): assert self.on_premise() return self.related_premise On Jun 16, 3:39 pm, Nick wrote: > OK, here's the deal. I'm working up an obituary site. There are 3 > models/tables and at one point I need to connect two in a way that is > different than I have done up to this point. Here is the situation, > any recommendations on how to accomplish this would be great: > > I have an obituary table. In that table there is a field that checks > if a funeral service is on the premises (column name "on_premises" of > the Funeral Home that is entering the information. > > If this BooleanField is checked then it returns the location > information of the funeral home which is stored in a business_profile > table. Not difficult, just check if the boolean returns a value and > then populate the template > > That works out nicely except I have been given an extra criteria for > this project. Some business have both a funeral home and a > crematorium. Many of these situations require that we list the address > of one or the other. Since the "on premises" is a BooleanField there > is no way for someone to state what part of their business is > responsible for the service. > > What I would like to do is make this option a drop down in the > obituary form that basically gives the business the option of choosing > which one of their locations is the one we want attached to this obit. > Once this is chosen then I will pull the value into the templates. > > How do I relate these models? My first thought is to create two > "business type" columns in the business profile table and then relate > the "service_location" column to these columns in a drop down? Is that > even possible? > > How do I retrieve the values from two different fields and then select > from them in another model? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Why does django's default test suite runner set settings.DEBUG = False?
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, interactive=True, failfast=True, **kwargs): self.verbosity = verbosity self.interactive = interactive self.failfast = failfast def setup_test_environment(self, **kwargs): setup_test_environment() settings.DEBUG = False ... What's the benefit? Is it important? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django list_filter
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 > like : > A > -a1 > -a2 > --a21 > --a211 > --a22 > B > -b1 > > and I use the "parent" as list_filter ,but I get a problem , when I > click 'a1' ,it only show the information in a1, > but I want it also show its childrens' information . For example , > when I click a21,It can show the informations in > a21 and a211.Do anyone have any idea? > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django filters
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. The way its works now > that its displays the old objects first and then the most recent ones. Is it > possible to make it other way around ?. > > Let me know. > > --RJ > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Grouped statements in debug_toolbar
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 appear to be possible in the >> latest version; or am I wrong? > > I don't think this has even been possible in the main django-debug- > toolbar project. However I have a fork at > http://github.com/danielroseman/django-debug-toolbar > that does exactly that. Awesome! I'll give it a spin. > -- > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com fun crosstips.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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: About extending User model
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 and separate. Why does the admin need the stuff you can put in UserProfile if you create him via the admin pages? If he really needs it, tell him to register and then you go in an turn his created account (in the admin) to a superuser or whatever you need. On 25 Mar, 18:37, Jim N wrote: > On Mar 11, 1:03 pm, Tom Evans wrote: > > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit > > wrote: > > > I'm using UserProfile to add one field to my users. However, I know > > > that I must explicitly create UserProfile for each new user that > > > registers. So, I make a UserProfile upon registration. Is UserProfile > > > still the best way to extend the user model? > > > What about the admin user, or users that the admin creates? Since they > > > don't go through the registration process, how do I ensure that their > > > UserProfile gets created? > > > Add this to your models.py > > > from django.db.models.signals import post_save > > from django.contrib.auth.models import User > > > def _hook_save_user(instance, sender, **kwargs): > > try: > > instance.get_profile() > > except UserProfile.DoesNotExist: > > UserProfile.objects.get_or_create(user=instance) > > > post_save.connect(_hook_save_user, sender=User) > > On Mar 11, 1:03 pm, Tom Evans wrote: > > > > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit > > wrote: > > > I'm using UserProfile to add one field to my users. However, I know > > > that I must explicitly create UserProfile for each new user that > > > registers. So, I make a UserProfile upon registration. Is UserProfile > > > still the best way to extend the user model? > > > What about the admin user, or users that the admin creates? Since they > > > don't go through the registration process, how do I ensure that their > > > UserProfile gets created? > > > Add this to your models.py > > > from django.db.models.signals import post_save > > from django.contrib.auth.models import User > > > def _hook_save_user(instance, sender, **kwargs): > > try: > > instance.get_profile() > > except UserProfile.DoesNotExist: > > UserProfile.objects.get_or_create(user=instance) > > > post_save.connect(_hook_save_user, sender=User) > > Very interesting, Tom. > > I have inserted this code, substituting my profile model name > (QotdUser) for UserProfile. It does create a row in QotdUser, but the > row is empty of course. > > More importantly, if I create a user via the admin interface (http:// > 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit > any of the fields of my profile model. > > Or if I create the user some other way, would I be able to pass > arguments to the User model to populate the profile? > > Finally, how do I access the profile, is it like > > my_user_profile = User.objects.get(username="jim").get_profile() ? > > Thanks for the help. > > -Jim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Nested for loop: {% cycle ... %}
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 %} > ... > ... > {% endfor %} > ... > > ... > {% endfor %} > > == > > The output: > > == > > .. > .. > ... > > == > > What I really want: > > == > > .. > .. > ... > > == > > This must be a complete noob question. Sorry 'bout that. :D > > Thanks! > Micky -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: auto authenticate
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 backend in settings.AUTHENTICATION_BACKENDS: if user == load_backend(backend).get_user(user.pk): user.backend = backend if hasattr(user, 'backend'): login(request, user) On 25 Mar, 18:27, CrabbyPete wrote: > I am connecting facebook to an app I have running. In order not to > change a load of code I created a dummy account when someone logs in > through facebook. My only problem is I want to authenticate with this > account when they log Is there a way to login in a user using the > encrypted password. I am using pyfacebook and FacebookUser is the > following model > > class FacebookUser(models.Model): > user = models.ForeignKey(User, unique = True) > fb_uid = models.CharField( max_length=100, blank = True, > unique = True) > > def __unicode__(self): > if self.user.username == u'': > return str(self.pk) > return self.user.username > > the fb_uid is the Facebook id I get back. Here is my view when I get > called from facebook > > fb = request.facebook > try: > fid = FacebookUser.objects.get(Q(fb_uid = fb.uid)) > except FacebookUser.DoesNotExist: > return ... > > name = fid.user > pswd = fid.user.password > user = auth.authenticate(username=name, password=pswd) > if user is not None and user.is_active: > auth.login(request, user) > > pswd is an encrypted password. Is there a way for me to authenticate > with it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Grouped statements in debug_toolbar
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 Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Running multiple FCGI processes out of the same directory
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 so that I use the same manage.py file but with different pid files and different port numbers. The objective is running more processes as opposed to running many threads. And most importantly if a fcgi process dies another can take over and this is taken care of by the load balancer. Is this a good idea? Are there any risks with this approach? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Admin interface and filter by value
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 really know what you're doing. Use the User model inside Django and just let that be what it is. All other bits and pieces such as MacAddress is then put in a user profile class. There's good documentation on how to control your user profiles and how that works. On Jan 22, 11:42 am, onorua wrote: > I have two models: > > class User(models.Model): > > LoginName = models.CharField('login', max_length=50) > Email = models.EmailField('e-mail', blank=True) > FirstName = models.CharField(max_length=50) > LastName = models.CharField(max_length=50) > IpAddress = models.IPAddressField(unique=True) > MacAddress = models.CharField(max_length=17) > UserAddress = models.CharField(max_length=250) > Switch = models.ForeignKey('Switch') > Port = models.ForeignKey('Port') > > class Switch(models.Model): > SwitchTypes = ( > ('N', 'Non managed'), > ('M', 'Managed'), > ('3', '3 Layer'), > ) > SwitchSNMP = ( > ('Y', 'Yes'), > ('N', 'No'), > ) > Name = models.CharField( max_length=50) > IpAddress = models.IPAddressField('unique=True) > Location = models.CharField(max_length=250) > Manufacture = models.CharField(max_length=50) > Model = models.CharField(max_length=50) > PortsNumber = models.IntegerField() > Type = models.CharField(max_length=1, choices=SwitchTypes) > SNMP_enable = models.CharField( max_length=1, choices=SwitchSNMP) > SNMP_group = models.CharField(max_length=50, blank=True) > def __unicode__(self): > return ('%s %s' % (self.Name, self.IpAddress)) > > class Port(models.Model): > MediaType = ( > ('C', 'Copper'), > ('F', 'Fiber'), > ) > > Type = models.CharField(max_length=1, choices=MediaType) > MaxSpeed = models.SmallIntegerField(default = 100) > CurSpeed = models.SmallIntegerField(default=100) > Switch = models.ForeignKey('Switch') > PortNum = models.SmallIntegerField() > Description = models.CharField(max_length=250, blank=True) > > def __unicode__(self): > return ('%s ' % (self.PortNum)) > > I would like to have following: > 1. When I create a new user, I choose switch from the list of > available switches, and when I go to the Port, it will automatically > shows only Ports for this particular switch. > 2. When I add a new Switch, and put the port number as 16, they would > be automatically crated with the default values. > > Is it possible to do? Could you please point me out on the elegant > solution. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Setting a user to have particular permission group when registering with django-registration?
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 want more control such that it's only when they use the django- registration view then you can create your own view called register and let it call django-registration's registrer() On Jan 21, 4:32 pm, littlejim84 wrote: > I'm using django-registration and want to set a user to have a > paricular permission group when they sign in. What is the best way to > implement this without messing with the source of the actual app? > > Any information at all would be good. I'm having no luck at all on the > IRC chat group. > James -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Best Practice for developing djangoapp in a repository
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 instead depend on your custom app that subclasses, e.g. myubertagging. It's never a good idea to change external apps but it's a perfectly good idea to extend or override it. You'll obviously have to pay a price when a new version of django- tagging comes out and you need to figure out what that means for your subclassing app. But it's worth it. On Jan 21, 6:04 pm, Julian wrote: > Hello, > > my problem is maybe not very specific but more a problem with an > approach. Let's say I want to work on a djangoapp (in this case django- > tagging, the famous tagging app). I'm not very satisified with the > code and want to simplify it. > > if I clone the repository I have a folder 'django-tagging' wich > contains several files (e.g. the LICENSE.txt, the setup.py) and a > folder with the djangoapp itself called tagging. > > when working on the code i want to test the tagging app with ./ > manage.py test tagging. so atm I see two possibilities: > > 1.) the folder django-tagging is a djangoproject and all the files not > concerning the djangoapp (e.g. the manage.py) are not in the > repository. then I can change the code, test it, submit the changes > and everything is cool except I mess the djangoproject files and the > files of the app. > > 2.) I could install the app with the setup.py and everytime I change > the code I have to reinstall it in order to test it within a > djangoapp. this is another possibility, but makes me not happy. > > 3.) ??? so what's the best practice to solve that problem? extending > sys.path and keeping the folder its own place? > > Regards > Julian -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: newline in GET data
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 line > chars ? > > Thanks > Sumanth -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cache large files
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 as css files. On Jan 22, 7:17 am, Hinnack wrote: > Hi, > > I am using memcached for caching my sites. The documentation says when > not to use it:http://code.google.com/p/memcached/wiki/WhyNotMemcached > > one point is output larger 1 MB > > I have a site producing pdf files only, where size can easily go over > 1 MB. As the docs above mention mogilefs as > an alternative, I wonder if this is the right way to do it, as there > is no batterie for djangos caching system. > > I know that the cach system has support for filesystem cache - has > someone used this for large files? and maybe even > in conjunction with GlusterFS (http://www.gluster.org/), as that seems > to be more complete then mogilefs? > > What about concurrent writes from different hosts to the cache system? > > -- > > Hinnack -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: "Unsupressing" errors when called from templates
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 !-) >> >> I don't know what means > > oops, sorry - it's french for "OT". > >> >> > Did you actually tried with this exact code ? If yes, this contradicts >> > the FineManual(tm) >> >> >> That's true for other exceptions only. E.g. ValueError or >> ZeroDivisionError > > Yeps - I've seen your other posts and the link to the ticket since I > posted this. Sorry if the answer looked a bit patronizing, but more > often than not, posters fail to read the FineManual(tm) - or to find > the relevant section. > It did but I would have written the same in reply if I suspected someone hadn't skimmed the manual. >> There is.http://code.djangoproject.com/ticket/11421 >> >> I've written a patch that solves it already. Now working on tests for >> it. > > Well done. > > > > -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com fun crosstips.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: admin actions bar in django 1.1
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 the bar, however, I can't seem to find the > discrepancy between the two installs. Have any of you experienced > this? 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: "Unsupressing" errors when called from templates
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.Model): > > text = models.TextField() > > def count_words(self): > > raise AttributeError('debugging') > > a NotImplementedError would be more appropriate !-) > I don't know what means but it's just an example. I could have written: class Article(models.Model): ... def count_words(self): return some_complex_calculation(article=self) > > Then, when I render that page I get: > > Info: words > > Did you actually tried with this exact code ? If yes, this contradicts > the FineManual(tm): > """ > If, during the method lookup, a method raises an exception, the > exception will be propagated, unless the exception has an attribute > silent_variable_failure whose value is True. If the exception does > have a silent_variable_failure attribute, the variable will render as > an empty string. > (...) > Note that django.core.exceptions.ObjectDoesNotExist, which is the base > class for all Django database API DoesNotExist exceptions, has > silent_variable_failure = True. So if you're using Django templates > with Django model objects, any DoesNotExist exception will fail > silently. > """http://docs.djangoproject.com/en/dev/ref/templates/api/#rendering-a-c... > That's true for other exceptions only. E.g. ValueError or ZeroDivisionError I can't set silent_variable_failure=True on TemplateSyntaxError. This is only applicable when you write your own exception sub classes. > > When I want is a raised proper error so that I can spot the possible > > bug in my system. How do I do that? > > Not tested, but this might be the answer: > > http://docs.djangoproject.com/en/dev/ref/settings/#debug-propagate-ex... > I don't know what that does. Perhaps it's related to views only, not template rendering. Setting it to True does NOT propagate AttributeErrors in templates rendering. > > If what you look up in the template doesn't exist I can accept that > > Django, currently, prefers to just suppress it > > Actually, there's no "suppression", > cfhttp://docs.djangoproject.com/en/dev/ref/templates/api/#how-invalid-v... > There is. http://code.djangoproject.com/ticket/11421 I've written a patch that solves it already. Now working on tests for it. > HTH --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: "Unsupressing" errors when called from templates
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 > somewhere else. > > On 21 Oct, 14:05, Peter Bengtsson wrote: > > > 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 a raised proper error so that I can spot the possible > > bug in my system. How do I do that? > > > If what you look up in the template doesn't exist I can accept that > > Django, currently, prefers to just suppress it but I'm here talking > > about things that are found but yields an exception upon executing. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: "Unsupressing" errors when called from templates
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: > > # 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 a raised proper error so that I can spot the possible > bug in my system. How do I do that? > > If what you look up in the template doesn't exist I can accept that > Django, currently, prefers to just suppress it but I'm here talking > about things that are found but yields an exception upon executing. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: efficiently deleting content based on how old it 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.now() - timedelta > > (days = 30)).delete() > > Yep, that's prettymuch what I ended up writing. Wow, Django's ORM > expressions are ugly compared to SQLAlchemy ;-) > Then just import sqlalchemy Don't do URL whacking. Just write a simple management command and wire that to your crontab. If the db is a legacy database and things are stored as varchars then I don't see any point in changing the database so you can use proper datetimes. And if it's indexed searching for something like 'April 2009' is going to be uber fast. > > old. As for your complicated references, assuming you don't have > > cascading deletes happening automatically, you may have to do an > > objects.filter(), > > Well, cascading deletes do happen automatically with Django, so no > problem there... > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > -http://www.simplistix.co.uk --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
"Unsupressing" errors when called from templates
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 a raised proper error so that I can spot the possible bug in my system. How do I do that? If what you look up in the template doesn't exist I can accept that Django, currently, prefers to just suppress it but I'm here talking about things that are found but yields an exception upon executing. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: get current URL
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 post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-admin.py the system cannot execute the specified program
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 running it from my command prompt:>>python hello.py > > Is that correct? > > On Sep 13, 10:29 pm, Karen Tracey wrote: > > > On Sun, Sep 13, 2009 at 3:09 PM, about2flip wrote: > > > > I am learning django, and I am having doubts if it is worth it. I am > > > trying to startproject and I keep getting the system cannot execute > > > the specified program error at my command prompt. I would type: > > > > django-admin.py startproject name > > > > and then I get the error. I am using python 2.6, django 1.1 on XP SP2 > > > machine. > > > > Thanks for your help on what to do to fix this issue > > > "Cannot execute the specified program" generally means the system can't find > > some DLL needed for the program. Django doesn't have any DLLs, so I suspect > > your python installation may be the cause of the problem. Can you run any > > python program? For example if you create a hello.py file with contents: > > > print 'hello' > > > Can you run it? > > > Karen --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: filter on entries from a certain user
On 14 Sep, 09:24, Peter Newman wrote: > Ok i am a bit further. The above only works with Google's > authentication. However I want to use Django authentication. Is there > a way to add the current user to the model during creation of the > entity? There must be something 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 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. > > Something like this: > > > class ContactForm(forms.ModelForm): > > class Meta: > > model = Contact > > exclude = ('owner',) > > > On Sep 13, 9:06 am, Peter Newman > > wrote: > > > > Guys - > > > > I have > > > class Contact(db.Model): > > > person = db.ReferenceProperty(Person) > > > contact_date = db.DateTimeProperty(auto_now_add=True) > > > remarks = db.TextProperty() > > > owner = db.UserProperty(auto_current_user_add=True) > > > > and a simple form > > > class ContactForm(forms.ModelForm): > > > class Meta: > > > model = Contact > > > > but when i add a record owner remains None??? what am i doing wrong? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: html template usage
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!{% endblock %} {% block content %} Welcome to my website {% endblock %} Now, in the same directory as home.html you now need to turn your monster template into a Django template so change it to this: {% block title %}{% endblock %} {% block content %}{% endblock %} The rest is easy: Plain and simple reading of the Django docs and tutorial. On Sep 12, 8:19 pm, aftalavera wrote: > Hi there, > > All I need is a sample (if available) or a working example on how to use > an existing HTML template into the Django template system. Am I on the > wrong track integrating both? > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: filter on entries from a certain user
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. Something like this: class ContactForm(forms.ModelForm): class Meta: model = Contact exclude = ('owner',) On Sep 13, 9:06 am, Peter Newman wrote: > Guys - > > I have > class Contact(db.Model): > person = db.ReferenceProperty(Person) > contact_date = db.DateTimeProperty(auto_now_add=True) > remarks = db.TextProperty() > owner = db.UserProperty(auto_current_user_add=True) > > and a simple form > class ContactForm(forms.ModelForm): > class Meta: > model = Contact > > but when i add a record owner remains None??? what am i doing wrong? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Memory limits
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. On Sep 13, 1:14 pm, Pablo Escobar wrote: > Hi > i'm wondering what is memory consumption for django 1.1 + postgre. > Will it be enough to have VPS with 256 MB of RAM as entry level for > recent projects? > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: urls.py
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.static.serve', > {'document_root': '/home/ramanathan/media/'}) > > These are the two lines in my urls.py file.. > > If i givehttp://localhost:8000/90/ it is matched > ashttp://localhost:8000/media/90/ insetad of getting redirected to > activate function in views.py file. > > Please Help me out. > > Regards, > Ramanathan M --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: post_save signal to create the new user profile
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:12 pm, Dmitry Gladkov wrote: > Hi! > > I've got user profile, that uses multi-table inheritance: > > class Employee(User): > address = models.CharField(max_length=50, null=True, blank=True) > phone1 = models.CharField(max_length=15, null=True, blank=True) > phone2 = models.CharField(max_length=15, null=True, blank=True) > skype = models.CharField(max_length=32, null=True, blank=True) > website = models.URLField(null=True, blank=True) > comments = models.TextField(null=True, blank=True) > > When I create a new employee from django admin interface it creates a > new user for it, but how to manage to create a new blank employee > profile after creating a new user from django admin? > > I tried to use post_save signal for it, but have no idea how to create > a new employee when it's inherited from known user. > When i use "instance.employee" it says "Employee matching query does > not exist." > When i try to create new employee using Employee(user=instance).save() > it says that there's no field called "user". > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File Field max size and admin interface
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. On Sep 13, 3:44 pm, drakkan wrote: > Hi, > > I'm using the admin interface with some filefield, I tested with a big > file (200 MB) and it was successfully uploaded, this is ok but I would > like a way to limiting the uploaded size for example to a maximun of > 10 MB, any hints? > > thanks > drakkan --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynaically fields to a formwizard form
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.name) for c in get_all_choices()] Perhaps you'll need to do it in the view. You can create the form instance both before you bind it with something like request.POST or if you do it later. E.g. def my_view(request): form = MyForm() form.fields['country'].choices = get_my_country_choices (request.user) if request.method == "POST": # bind the form form.is_bound = True form.data = request.POST if form.is_valid(): return render(request, 'my_template.html', locals()) cool! On Aug 25, 7:16 am, dingue fever wrote: > Hi, > > Is it possible to dynamically add fields to a formwizard form. I have > been able to add the fields I want but if the form fails validation > the new dynamic fields disappear when the form re-renders. Is it > possible to override this so that I can validate and return the new > fields if the validation fails? > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Many-to-many column
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(): list_.append(entry) list_.extend(get_all_parents(list_, entry) return list_ current = A parents = [] get_all_parents(parents, current) print parents Excuse me if I didn't get it right but it should get you started. On Aug 25, 10:11 am, Sven Richter wrote: > Hi, > > i implemented a many-to-many field in my model like: > class Entries(models.Model): > following_to = models.ManyToManyField('self', blank=True, null=True) > > Now i can get all related Entries in a template with entry.following_to.all. > But i want to go deeper in relationships. > > Lets say i have 4 Entries A, B, C, D. > A is following_to to B and > B is following_to to C and > C is following_to to D. > A.following_to.all gives back B. > > But what i need is to follow until the end of the chain is reached. > I need something like: > A.following_to.give_all_related_entries which then returns: > B, C, D > > Do i have to write my own template tag for that or is it already implemented > in Django? > Or maybe there is a better approach to solve my issue? > > I couldnt find a similar question or answer in the docs. > > Greetings > Sven --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: json serialization error on arrays
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 use efficient array storage. > > Testing with arrays I get.. > > TypeError at /zeros/ > > array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) is not JSON > serializable > > What would you recommend I do to support arrays? > > Thanks in advance, > John --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Test client and form processing
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 the fields from the form instance. On Aug 25, 4:31 pm, Joshua Russo wrote: > I'm working on putting together parsing logic so that I can extract the form > variables from the response content of the test Client. That way I can just > change a few values and throw it back at the server. This is especially > helpful with large dynamic forms that use formsets. > My question is, has this already been done? My Google-fu came up with nada. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Raw HTTP request processing?
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_data > The raw HTTP POST data. This is only useful for advanced > processing. Use POST instead. > > As I am going to be dealing with potentially very large streams in and > out, I need it to access the streams rather than a variable stored in > memory. Any examples of doing this that you know about? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: print PDF on windows
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 unfortunately his method for PDFs only print on the default > printer. I need the server to produce the PDF, save it (works already) > and send it to a specific shared printer on the network. The printer > should be determined from a table that holds 'host' - 'printer' pairs > e.g. ('PC01', '\\PC01\PR01'). The host ('PC01') determined from the > http request allows to choose the right printer ('\\PC01\PR01') from > that table. > > Printing should be executed directly when the user has submitted the > request. Any solution that pops up the document locally in a PDFReader > and where the user has to hit the print button is not viable. > > Kindly Yours > Marc --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Raw HTTP request processing?
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 and form etc? > Isn't it just request.raw_post_data > It is obvious how to do this on output as you create the response > object yourself, but with a request? > > Thanks in advance, > John --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Have I found a bug? Deletion and rolled back transactions
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 wrote: >>> 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() >>> transaction.managed(True) >>> qs = Article.objects.all() >>> for article in qs: >>> if article.title.lower().startswith(request.GET.get >>> ('startswith')): >>> article.delete() >>> break >>> transaction.rollback() >>> return HttpResponse("Rolled back!") >>> >>> # tests.py >>> from django.test import TestCase >>> >>> from news.models import Article >>> >>> class SimpleTest(TestCase): >>> def setUp(self): >>> Article.objects.create(title=u'Abraham') >>> Article.objects.create(title=u'Ben') >>> Article.objects.create(title=u'Ancor') >>> Article.objects.create(title=u'Wat') >>> >>> super(SimpleTest, self).setUp() >>> >>> def test_deletion(self): >>> count_before = Article.objects.count() >>> assert count_before == 4 >>> r = self.client.get('/news/delete-rolledback/', >>> dict(startswith='a')) >>> assert r.content.count("Rolled back") >>> count_after = Article.objects.count() >>> assert count_after == 4, count_after >>> >>> When I run these tests (with postgres or with sqlite) I get this >>> assertion error: >>> >>> Traceback (most recent call last): >>> ... >>> AssertionError: 3 >>> >>> If someone more clued up than me could take a look at this and confirm >>> that it is a Django bug I can start looking into explaining what's >>> wrong and possibilities of a patch. >>> I've found this ticket (http://code.djangoproject.com/ticket/4758) >>> where someone has experienced similar problems when using Oracle. But >>> only for Oracle; he claims the same code *works* with Postgres. >> > >> > > Your tests test transaction behavior so you need to subclass > TransactionTestCase instead of jsut TestCase. > I see. Thanks! > Alex > > -- > "I disapprove of what you say, but I will defend to the death your > right to say it." -- Voltaire > "The people's good is the highest law." -- Cicero > "Code can always be simpler than you think, but never as simple as you > want" -- Me > > > > -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com fun crosstips.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Have I found a bug? Deletion and rolled back transactions
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(max_length=100) > > # urls.py > urlpatterns = patterns('', > (r'^delete-rolledback/$', delete_rolledback), > ) > > # views.py > def delete_rolledback(request): > transaction.enter_transaction_management() > transaction.managed(True) > qs = Article.objects.all() > for article in qs: > if article.title.lower().startswith(request.GET.get > ('startswith')): > article.delete() > break > transaction.rollback() > return HttpResponse("Rolled back!") > > # tests.py > from django.test import TestCase > > from news.models import Article > > class SimpleTest(TestCase): > def setUp(self): > Article.objects.create(title=u'Abraham') > Article.objects.create(title=u'Ben') > Article.objects.create(title=u'Ancor') > Article.objects.create(title=u'Wat') > > super(SimpleTest, self).setUp() > > def test_deletion(self): > count_before = Article.objects.count() > assert count_before == 4 > r = self.client.get('/news/delete-rolledback/', > dict(startswith='a')) > assert r.content.count("Rolled back") > count_after = Article.objects.count() > assert count_after == 4, count_after > > When I run these tests (with postgres or with sqlite) I get this > assertion error: > > Traceback (most recent call last): > ... > AssertionError: 3 > > If someone more clued up than me could take a look at this and confirm > that it is a Django bug I can start looking into explaining what's > wrong and possibilities of a patch. > I've found this ticket (http://code.djangoproject.com/ticket/4758) > where someone has experienced similar problems when using Oracle. But > only for Oracle; he claims the same code *works* with Postgres. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Have I found a bug? Deletion and rolled back transactions
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() transaction.managed(True) qs = Article.objects.all() for article in qs: if article.title.lower().startswith(request.GET.get ('startswith')): article.delete() break transaction.rollback() return HttpResponse("Rolled back!") # tests.py from django.test import TestCase from news.models import Article class SimpleTest(TestCase): def setUp(self): Article.objects.create(title=u'Abraham') Article.objects.create(title=u'Ben') Article.objects.create(title=u'Ancor') Article.objects.create(title=u'Wat') super(SimpleTest, self).setUp() def test_deletion(self): count_before = Article.objects.count() assert count_before == 4 r = self.client.get('/news/delete-rolledback/', dict(startswith='a')) assert r.content.count("Rolled back") count_after = Article.objects.count() assert count_after == 4, count_after When I run these tests (with postgres or with sqlite) I get this assertion error: Traceback (most recent call last): ... AssertionError: 3 If someone more clued up than me could take a look at this and confirm that it is a Django bug I can start looking into explaining what's wrong and possibilities of a patch. I've found this ticket (http://code.djangoproject.com/ticket/4758) where someone has experienced similar problems when using Oracle. But only for Oracle; he claims the same code *works* with Postgres. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin: raw-id: Link to edit page
I see. I don't know how to make a link to the City in the Place edit page next to the City drop-down. You can put special links or things like that in the edit page at the top just above the fieldset. You first create a template called: templates/admin/// change_form.html And then do something like this: {% extends "admin/change_form.html" %} {% block object-tools %} {% if city %}{{ city.name }}{% endif %} {{ block.super }} {% endblock %} And then you need this in your admin.py class PlaceAdmin(admin.ModelAdmin): def change_view(self, request, object_id, extra_context={}): place = Place.objects.get(pk=object_id) if place.city: extra_context['city'] = place.city result = super(PlaceAdmin, self).change_view(request, object_id, extra_context) On 3 Aug, 13:22, Thomas Guettler wrote: > Thank you Peter. > > 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: > > > > > > > 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_display = ('city_special',) > > def city_special(self, obj): > > return '%s' % \ > > (obj.id, obj.name) > > city_special.short_description = u'City' > > city_special.allow_tags = True > > > That should get you started. I don't know if there is a more correct > > way to get the admin edit url for an object. > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to, complex filters in admin
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, selcukcihan wrote: > Hi, is there a ready to go solution within django for providing > complex filters(besides the date filters and others) on models within > the admin? For instance, there is a model with an integer field, i > would like to be able to apply filters of the form "greater than or > equal to" or "between this and that" --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Image handling - Custom image field?
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 >> /dev/null 2>&1 But running this as a separate command you'll make sure than for each run python will reuse memory it has freed. You might also want to write it so that the management command only does a limited about of photos in one batch and instead run the management command often. On 1 Aug, 22:50, TiNo wrote: > Hi, > I am working on an image gallery. I am making use of django-imagekit. My > site is hosted at a VPS, with 80 MBs of memory. I use NginX with fastcgi. > > What I am trying to accomplish is the following: > 1. A logged-in user goes to an /upload page, where information about the ftp > server is listed > 2. The user uploads his pictures through ftp (sometimes more than 100), and > clicks 'done' on the page. > 3. Images get imported, their EXIF data gets added to the database and they > are resized (to about 1024x800) > 4. Original images are moved to an 'originals' folder, and stored for some > time. > > I got everything covered, except from step 3. As I don't have a lot of > memory, I can't afford to load all the images in the main script. The django > fastcgi instances then quickly use about 100MBs together, for quite some > time. > > So I will do this in a separate python script. Then some questions: > - It would be nice to open the uploaded file as an PIL image, resize it, and > save it to the final destination, therefore saving an extra open() call. It > is probably possible to do this in a subclassed ImageField, but I can't > really get my head around these FileFields with the FieldFile classes. So > what method would I have to override to do this? > - What would be the best way to start a separate python script? And is there > any way to communicate between de fastcgi script and the import script? Say > pass that we are at image 25 of 100? > > Thanks, > > TiNo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newbie tutorial part 1 startproject doesn't create folder and appropriate files
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 2 Aug, 22:47, mdsmoker wrote: > I'm using django 1.1, python 2.5, and windows and i'm brand-spanking > new to this. i installed django w/out a problem. python is in my > windows path and if i type import django after running python i don't > get any errors so I'm assuming it is installed correctly. after i run > django-admin.py startproject mysite i don't get any errors and i also > don't get any results :( no new folder or project files were > created. any suggestions? i can't believe i can't get through the > very first step in the tutorial! --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to modified filefiled after created it
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 == 'status': self.name = v.lower() super(Foo, self).__setattr__(k, v) f = Foo() f.status = 'APPROVE' print f.status # will print 'APPROVE' print f.name # will print 'approve' On 3 Aug, 08:28, Shuge Lee wrote: > Please take a lookhttp://dpaste.com/74606/ > > or here > > # in models.py > > UNAPPROVE = 0 > ACCEPT = 1 > REJECT = 2 > > unapprove_path = os.path.join(MEDIA_ROOT, 'unapprove') > accept_path = os.path.join(MEDIA_ROOT, 'accept') > reject_path = os.path.join(MEDIA_ROOT, 'reject') > > def get_filepath(instance, filename): > i = instance > > suffix = os.path.splitext(filename)[-1] > newfile = osp.join(i.category, i.name + suffix) > > if i.status == UNAPPROVE: > path = os.path.join(unapprove_path, newfile) > elif i.status == ACCEPT: > path = os.path.join(accept_path, newfile) > elif i.status == REJECT: > path = os.path.join(reject_path, newfile) > return path > > class Category(models.Model): > name = models.CharField(max_length=32, unique=True, null=True) > > def __unicode__(self): > return self.name > > class Meta: > verbose_name_plural = 'Categories' > > def save(self): > self.name = self.name.replace(' ', '-') > super(Category, self).save() > > class Seed(models.Model): > name = models.CharField(max_length=128) > > files = models.FileField(upload_to=get_filepath, blank=True, > null=True) > > category = models.ForeignKey(Category) > status = models.IntegerField(max_length=1, > choices=SEED_STATUS_CHOICES, default=UNAPPROVE) > > def __unicode__(self): > return self.name > > def save(self, force_insert=False, force_update=False): > self.name = self.name.replace(' ', '-') > super(Seed, self).save() > > However, how to make `files` field be modified automatically while > `status` field changed ? > > """ > > > For example, I add new record > > from django.core.files import File > myfile = File(open('/tmp/old.7z')) > t.Seed(name='TCPL', category=Category(pk=1), status=UNAPPROVE) > t.files.save(name=t.name, content=myfile) > t.save() > > t.status = ACCEPT > # I want t.files changed automatically here > # How to do it ? > t.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin: raw-id: Link to edit page
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_display = ('city_special',) def city_special(self, obj): return '%s' % \ (obj.id, obj.name) city_special.short_description = u'City' city_special.allow_tags = True That should get you started. I don't know if there is a more correct way to get the admin edit url for an object. > Regards, > Thomas Güttler > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to rerun tests on file changes
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 know that py.test has this but I don't know how to use py.test with 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin list_filter and using a method instead
I looked into this deeper. You can't have a filter widget in the admin of methods rather than DB fields. That's bad I thought, but let's just pretend its there and hardcode the links. So I tried adding ?man=1 to the URL /admin/myapp/mymodel/?man=1 But it doesn't like that and redirects to /admin/myapp/mymodel/?e=1 It does that because in contrib/admin/views/main.py:190 it does this:: # Apply lookup parameters from the query string. try: qs = qs.filter(**lookup_params) # Naked except! Because we don't have any other way of validating "params". # They might be invalid if the keyword arguments are incorrect, or if the # values are not in the correct type, so we might get FieldError, ValueError, # ValicationError, or ? from a custom field that raises yet something else # when handed impossible data. except: raise IncorrectLookupParameters Basically, I was able to override MyModel.objects and write my own custom filter() and exclude() which makes it possible to filter and exclude on non-DB fields. But this qs.filter() is a the queryset that MyModel.objects "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: > > class MyModel: > gender = models.CharField() > age = models.IntegerField() > > �...@property > def man(self): > return self.gender == 'male' and self.age > 18 > > objects = SpecialManager() > > The special manager I use makes it possible to do this:>>> > MyModel.objects.filter(man=True) > > I achived that by wrapping filter() and exclude(). No big deal. > The admin is registered like this: > > class MyModelAdmin(admin.ModelAdmin): > list_display = ('__unicode__', 'user', 'man') > list_filter = ('man', ) # thise causes the ImproperlyConfigured > error! > > def man(self, object_): > return object_.man > man.short_description = 'Man?' > man.allow_tags = False > > admin.site.register(MyModel, MyModelAdmin) > > Why can't I use methods instead of fields in list_filter? > Is there a solution to this problem? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin list_filter and using a method instead
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 pseudo code should explain my situation: > > class MyModel: > gender = models.CharField() > age = models.IntegerField() > > �...@property > def man(self): > return self.gender == 'male' and self.age > 18 > > objects = SpecialManager() > > The special manager I use makes it possible to do this:>>> > MyModel.objects.filter(man=True) > > I achived that by wrapping filter() and exclude(). No big deal. > The admin is registered like this: > > class MyModelAdmin(admin.ModelAdmin): > list_display = ('__unicode__', 'user', 'man') > list_filter = ('man', ) # thise causes the ImproperlyConfigured > error! > > def man(self, object_): > return object_.man > man.short_description = 'Man?' > man.allow_tags = False > > admin.site.register(MyModel, MyModelAdmin) > > Why can't I use methods instead of fields in list_filter? > Is there a solution to this problem? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Admin list_filter and using a method instead
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 self.age > 18 objects = SpecialManager() The special manager I use makes it possible to do this: >>> MyModel.objects.filter(man=True) I achived that by wrapping filter() and exclude(). No big deal. The admin is registered like this: class MyModelAdmin(admin.ModelAdmin): list_display = ('__unicode__', 'user', 'man') list_filter = ('man', ) # thise causes the ImproperlyConfigured error! def man(self, object_): return object_.man man.short_description = 'Man?' man.allow_tags = False admin.site.register(MyModel, MyModelAdmin) Why can't I use methods instead of fields in list_filter? Is there a solution to this problem? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Invalidate a cache_page view
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 '/etc/init.d/memcached restart' but that not very practical; especially since it's not automated. Granted, the HTTP Expires settings have been sent to obeying browsers won't reload unless each client explicitly press the Reload button. Is there a way to, using signals, invalidate a cache_page cache? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Manual transactions in command
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.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() > MyModel.objects.create(name=u'FOO') > transaction.rollback() > > When I run that command it does NOT roll back the transaction and > after running it I get an entry of FOO in my postgresql database. > > I couldn't find any documentation for using django.db.transcation in > non-views so I guessed this was the way to run it. > (Using django trunk) --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Manual transactions in command
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() MyModel.objects.create(name=u'FOO') transaction.rollback() When I run that command it does NOT roll back the transaction and after running it I get an entry of FOO in my postgresql database. I couldn't find any documentation for using django.db.transcation in non-views so I guessed this was the way to run it. (Using django trunk) --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Searching a list of Q
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 ugly and feels "clunky": qset = None for each in [u"Foo", u"Bar"]: if qset is None: qset = Q(author__iexact=each) else: qset = qset | Q(author__iexact=each) --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
locmem or memcache
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 worry about some RAM bloat. --~--~-~--~~~---~--~~ 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: Ordering bookeditions by their rating
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(title=u'Title2', binding=u'') >>> e3 = Edition.objects.create(title=u'Title3', binding=u'') >>> me = User.objects.all()[0] >>> __ = Rating.objects.create(user=me, edition=e1, rating=3) >>> __ = Rating.objects.create(user=me, edition=e1, rating=4) >>> __ = Rating.objects.create(user=me, edition=e1, rating=2) >>> __ = Rating.objects.create(user=me, edition=e2, rating=5) >>> __ = Rating.objects.create(user=me, edition=e2, rating=6) >>> __ = Rating.objects.create(user=me, edition=e2, rating=5) >>> __ = Rating.objects.create(user=me, edition=e3, rating=1) >>> __ = Rating.objects.create(user=me, edition=e3, rating=2) >>> __ = Rating.objects.create(user=me, edition=e3, rating=1) >>> __ = Rating.objects.create(user=me, edition=e3, rating=3) >>> So at this point Edition 1 has 3 ratings of 3,4 and 2 (average = 3) Edition 2 ratings 5, 6 and 5 (average = 5.33) Edition 3 ratings 1, 2, 1, 3 (average = 1.75) So the highest average is Edition 2. Now we'll do the complex select. >>> qs = Rating.objects.all().order_by('-avg') >>> qs = qs.extra(select={'s':'sum(rating)', ... 'c':'count(rating)', ... 'avg':'sum(rating)::float/count(rating)'}) >>> qs = qs.values('edition_id','s','c','avg') >>> qs.query.group_by = ['edition_id'] >>> print qs.query.as_sql() (u'SELECT (sum(rating)) AS "s", (sum(rating)::float/count(rating)) AS "avg", (count(rating)) AS "c", "collection_rating"."edition_id" FROM "collection_rating" GROUP BY edition_id ORDER BY "avg" DESC', ()) >>> for e in qs: ... print e ... {'s': 16L, 'avg': 5.3304, 'edition_id': 2, 'c': 3L} {'s': 9L, 'avg': 3.0, 'edition_id': 1, 'c': 3L} {'s': 7L, 'avg': 1.75, 'edition_id': 3, 'c': 4L} >>> edition_ids = [x['edition_id'] for x in qs] >>> edition_ids [2, 1, 3] That should get you going. Now you have to do something with this ordered list of edition_ids. You can use this for a filter on a more elaborate QuerySet. Something like this: cool_editions = Editions.objects.filter(id__in=edition_ids).exclude (title__icontains='Fudge').order_by('-binding') I hope that helps! On Nov 28, 10:07 am, coan <[EMAIL PROTECTED]> wrote: > I have book editions in my database. Users can rate editions. If they > want, they can also add them to their book collection. > Here is a simplified overview of the models: > > class Edition(models.Model): > title = models.models.CharField(max_length=255) > binding = models.models.CharField(max_length=30) > > class Bookcollection(models.Model): > user = models.ForeignKey(User) > edition = models.ForeignKey(Edition) > > class Rating(models.Model): > user = models.ForeignKey(User) > edition = models.ForeignKey(Edition) > rating = models.PositiveIntegerField() > > I can fetch all the books in a users bookcollection with editions = > user.edition_set.all() > What do I do if I want to order a users bookcollection by the rating > he or she gave it? --~--~-~--~~~---~--~~ 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: ImageField upload_to not workin
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 model and > assign instance.archivo to a file then instance.archivo.path does not > contain my upload_to parameter: > > Ie: > > my media root is :"/home/media" > my uploadto is "imageneslugar" > my file is "image.jpg" > > I do: > instance.archivo = "image.jpg" Is this pseudo code or does that actually work? I do this: instance.achivo.save('image.jpg', request.FILES['photo']) > > then: > instance.archivo.path is: > /home/media/image.jpg > instead of > /home/media/imageneslugar/image.jpg > > what am I missing? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Turning key=value1&key=value2&key=value3 into a list
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-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: www.djangosnippets.org is down now?
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 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: Test client: how to tell if user is logged in?
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', password='s') client.get('/view/that/uses/request.user/') On Aug 26, 7:41 pm, Aaron Maxwell <[EMAIL PROTECTED]> wrote: > Hi all, > > Using django 1.0beta'stestclient, is there some reliable way to tell if > atestuseris logged in? > > It would be nice to do this within thetestcase code. However, even within a > view, using request.user.is_authenticated does not seem to work properly. > > Thanks, > Aaron > > -- > Aaron Maxwellhttp://redsymbol.net --~--~-~--~~~---~--~~ 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: Forms generated from models missing primary key
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.forms.widgets import HiddenInput >>> form.fields['id'].widget = HiddenInput() > the generated form doesn`t have a hidden field for the primary key. > Why? What`s the best way to add it? --~--~-~--~~~---~--~~ 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: Accessor for field 'user' clashes with related field 'User.*'
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') to_user = models.ForeignKey(User, null=True, related_name='to') On Oct 22, 11:09 am, lcordier <[EMAIL PROTECTED]> wrote: > I have recently changed the layout of my code. Putting all my apps > into an apps sub-directory to make things a bit cleaner. Basically the > same layout > ashttp://code.djangoproject.com/browser/djangoproject.com/django_websit... > > To run my tests I have to go into the apps sub-directory and run it > like so: > ../manage.py test app > > The problem, now all foreign key's result in: > apps/profiles.userprofile: Accessor for field 'user' clashes with > related field 'User.lala_set'. Add a related_name argument to the > definition for 'user'. > apps/profiles.userprofile: Reverse query name for field 'user' clashes > with related field 'User.lala_set'. Add a related_name argument to the > definition for 'user'. > > No matter what 'related_name' I choose, I mean no clashes with other > tables. > My questions: > > 1. How does test work for django_website? > 2. Anyone else with a non-standard apps layout, with a solution to > this problem? > > Regards, Louis. --~--~-~--~~~---~--~~ 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: second post:Please answer!How to compare from two models in the same function (view)?
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(request): > form = ItemForm() > if request.method=="POST": > form = ItemForm(request.POST, request.FILES) > if form.is_valid(): > if item.price >= old.price and item.pub_date <= > old.pub_date > item = form.save(commit=False) > item.seller = request.user > item.save() > form = ItemForm() > else: > pass > return render_to_response( > "add_item.html", > {"form": form},context_instance=RequestContext(request)) But that is not comparing two models. One of them is a form instance the other ("old") is something else. If you want to compare two models you have to add a __eq__ method to your view class. I guess the same applies if you want to compare two form instances. --~--~-~--~~~---~--~~ 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: ViewDoesNotExist: Even though it does
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 fish problems and errors that are otherwise "hidden" by the magic of wiring when you run Django. Has definitely helped me in the past. On Oct 22, 8:09 am, JonathanB <[EMAIL PROTECTED]> wrote: > Getting a very erratic Exception: > > ViewDoesNotExist: Could not import supplier.views. Error was: cannot > import name Buyer > > What is stage is Buyer (model Class) does exist and the exception is > only thrown once in a while. Could it be that there are too many > ForeignKey relationships. i.e. the Buyer model is used in 3 other > models. --~--~-~--~~~---~--~~ 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: Django Suitability
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 strongly in > favor of using Django for the project and one of the principles is mostly > convinced that will be fine. The other wants a third-party (who currently > develop applications with Servoy) to check into Django/Python and evaluate > it for its suitability for this project. The requirements for the project > are these: > > 1. Rapid development > 2. Stability > 3. Ease of use > 4. Customer access including order entry (currently orders can only be > entered by staff) > 5. Remote access via smart phone > Those requirements would fit any decent web framework except the Java ones :) > My questions are these: > > 1. Is there anyone out there who has used Django and Servoy? > 2. Has anyone done an order entry system (not pinax) or accounting system (I > know of the projects on google code) or interfaced with legacy systems with > Django? Building one at the moment. Nothing to share though since there's nothing specific about it. It just a web app. > 3. There seems to be a concern that Django isn't used by "big names". Are > there big names using Django (other than the newspapers and google)? I have > looked through django sites quite a bit and found a few universities but not > a lot else. Google banked on Django when they built the Google App Engine. > 4. I welcome any other comments, thoughts, opinions, or references as to the > suitability of Django for this project. > Key is PYTHON. Django is very modular and loosely couple and you get immediate access to the world of Python in your models and views and then only the sky is the limit. If there's a Python module for ODBC, Access, etc. then YES it can be used in Django. > I apologize if any/all of this is redundant. I am a big fan of Django, so > thanks to all the developers and community! > > Matthew --~--~-~--~~~---~--~~ 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: www.djangosnippets.org is down now?
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 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: Split a form up in the template/view?
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(): > form.save() > return HttpResponseRedirect('/add_publisher/thanks/') > else: > form = PublisherForm() > return render_to_response('books/add_publisher.html', {'form': > form}) > > If say my model had 10 attributes, and I wanted to split it up into 5 > different blocks (i.e. put pairs of elements in their own div block > and whatnot), is there any easy way to do this? I know if you pass > lists in, you can do something along the lines of: > {% for item in form|slice:":2" %} to get the first two elements, for > example, but you apparently cannot do this when you pass a form object > to the template. Is there an easy way to do this without writing a lot > of code in the template/view? Easy. Turn the fields in the a list and then slice works. But you have to do that in the view as far as a I know. So fields = list(my_form) return render_to_response(... Then: {% for field in fields|slice:":5" %} {{ field }} {% endfor %} --~--~-~--~~~---~--~~ 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: actual django stack
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 of you test different solution and can share some output here. > > Here are the ones I see actually > > Apache mod_python > Apache in fastcgi mode > Lighttpd in fastcgi mode > Nginx in fastcgi mode > I've noticed a small performance boost from using Nginx + fcgi compared to Apache + mod_python and I hear that Nginx is also a better performer on the static content but haven't personally experienced that but the blogosphere will probably agree that Nginx is faster. The benefit to us with Apache is that we have more knowledge about it within the team but this only matters when you do more complicated stuff such as advanced authentication stuff or additional security hardening. This will probably be the case for many teams since Nginx is so new. When I last evaluated whether to go for Nginx or Lighttpd I remember seeing a lot of concern for Lighttpd's stability. The blogosphere talked about seg faults and slightly higer footprint than Nginx. > I'm not talking about load balancer, memcached and database here, just > the application. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with filtering on DateTimeField
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,9,4)).count() 0 This is unexpected. Clearly there is one object in there on the same day, but obviously at a different hour. I've also tried date__exact= and date__startswith= but no luck with either. I know it's possible to do things like date__year=, date__month=, date__day= but that feels a bit excessive. At the moment I've solved my problem by doing a __range but I really want to know why it doesn't work. Peter --~--~-~--~~~---~--~~ 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: Discover tests in forms.py
> 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' import classes.forms def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): d = locals() d.pop('test_labels') extra_tests.append(build_suite(classes.forms)) return orig_run_tests(test_labels, **d) That works great and I now need to make it non-hardcoded. I like how it doesn't repeat the code from simple.py much which is key to me for new upgrades of django itself. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Discover tests in forms.py
>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 classes. How do I get the testrunner to discover them? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
More advanced test runner available?
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 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 -~--~~~~--~~--~--~---
Trapping template errors
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 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: library import issue.
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 python i can import the library but not in Django. I compiled this > library using Swig. > > Details: > > Error was: libhdate.so.1: cannot open shared object file: No such file or > directory > > but in python... > [machine]$ python -c "from hdate import Hdate" > [machine]$ > Clearly it's a different sys.path in the two pythons. Assert yourself first that you're using the exact same python binary for django and for python on the command line. Try this: $ python >>> import hdate >>> import sys >>> from pprint import pprint >>> pprint(sys.path) Then try it from the django shell $ python manage.py shell >>> import hdate ... ImportError ... >>> import sys >>> from pprint import pprint >>> pprint(sys.path) Then compare and find out what's going on. > Any help? > > James > > --http://search.goldwatches.com/?Search=Movado+Watcheshttp://www.jewelerslounge.comhttp://www.goldwatches.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---