Re: rendering to template help
On May 27, 3:10 pm, Pirate Pete wrote: > hello again, > > i am trying to get a single entry from my db and then annotate the > count and rating to it like we established above > > however it doesn't seem to be returning anything: > videos = > Video.objects.get(id=vid_id).annotate(rating_count=Count('rating'), > rating_avg=Avg('rating__rating')) The trouble is that .get() directly returns an instance, not a queryset - so you can't call annotate() on it. It should work if you move the .get() clause to the end. > i even tried a filter: > > videos = > Video.objects.all().filter(id=vid_id).annotate(rating_count=Count('rating') , > rating_avg=Avg('rating__rating')) > > this is really puzzling me as to why it is not working. Any ideas? This should work, although remember that it will return a single-item queryset, rather than a single instance as above - so you'll still need to iterate through, or slice it (via videos[0]). > Also i seem to be getting an error with my |drawstars which works fine > on other pages that dont require this individual selection. > > I don't quite understand this error: > > "Caught an exception while rendering: a float is required" > > thanks in advance That's probably because you're passing the queryset, rather than individual instance, as I note above. You should be seeing error tracebacks, especially in the first example you show above - you should find they are helpful in debugging this sort of thing. -- 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.
problems with authentication of test client
Hi, I am trying to test my pages that need authentication. But, I am not able to test views that need authentication. I have tried following threads about logging in test client in this group and django documentation, but still cant figure out. This my view I am trying to test: def cauction(request) if not request.user.is_authenticated(): print "redirecting" # printing this to check which if branch is executing print request.user return HttpResponseRedirect('/login/?next=%s' % request.path) else: print "authenticated_branch" # printing this to check which if branch is executing errors = [] if not request.method == 'POST': form = createAuction() return render_to_response('createauction.html', {'form' : form} ) else: form = createAuction(request.POST) if form.is_valid(): cd = form.cleaned_data uname = request.user.username a_title = cd['title'] a_desc = cd['description'] a_minprice = cd['min_price'] a_end_date = cd['end_date'] a_start_date = datetime.datetime.now() if not a_end_date > a_start_date: e = _('End date should be greater than start date.') errors.append(e) else: dt = a_end_date - a_start_date day = dt.days total_secs=dt.seconds secs = total_secs % 60 total_mins = total_secs / 60 mins = total_mins % 60 hours = total_mins / 60 th = hours + (day * 24) if th > 72 or th == 72: uname = request.user.username form = confAuction() return render_to_response('wizardTest.html', {'form' : form, 'a_title' : a_title, 'a_desc' : a_desc,'a_start-date' : a_start_date, 'a_end_date' : a_end_date, 'a_minprice' : a_minprice, 'uname' : uname}) else: e = _('Auction duration should be at least 72 hours') errors.append(e) else: e = _('Enter Valid data') errors.append(e) return render_to_response('createauction.html', {'form' : form, 'errors' : errors}) This view is called by this pattern in urls.py urlpatterns = patterns('',('^$', yaas_homepage) , (r'^createauction/$', cauction), ...) This is my tests.py import unittest from django.test.client import Client from django.test import Client, TestCase from django.contrib.auth import authenticate from django.contrib.auth.models import * from django.core import mail import datetime import time class SimpleTest(TestCase): fixtures = ['f1.json'] def setUp(self): # Every test needs a client self.client = Client() def test_create(self): response = self.client.get('/createauction/') # Check that it takes to login page if not logged n self.failUnlessEqual(response.status_code, 302) self.assertRedirects(response, '/login/?next=/createauction/') # i have created a user here again as some threads suggested that I should make a user here. user = User.objects.create_user(username = 'myadmin2', email ='du...@dummy.com', password = 'testing2') uid = user.id user.is_staff = True user.save() print "trying to login..." login = self.client.login(username='myadmin2', password='testing2') self.failUnless(login, True) self.assertEqual( login, True) # this test does not fail, means user has logged in succefully and login is True enddate = datetime.datetime(2010, 06, 04, 3, 45, 50) post_data = { 'title' : 'Title1', 'desc' : 'description', 'start-date' : datetime.datetime.now() , 'end_date' : enddate, 'owner' : user.id, 'price' : 60, 'highbid' : 60, 'banned' : False, 'closed' : True, } r = c.post('/createauction/', post_data) self.failUnlessEqual(r.status_code, 200) # this test fails, as status_code returned is 302 These tests are run successully, meaning the user is redirected to login page, implying that client never enters the else branch for authenticated user in the 'cauction' view. self.failUnlessEqual(r.status_code, 302) self.assertRedirects(response, '/login/?next=/createauction/') I have put in more than a day in this problem, trying to figure out where I am going wrong. I have tried to explain clearly here. Any one has any idea? Thanks, irum -- 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 thi
Installation problem (version 1.2.1)
I have just upgraded my version of Ubuntu, which then also installed Python 2.6. I thought this was a good opportunity to upgrade to Django 1.2. I removed all traces of Django 1.1.1 that I could find, along with extra plugins/modules/apps etc, and ran the install for Django 1.2.1, checking that I was specifying "python2.6" when doing so. However when I try and start a new project (django-admin.py startproject test), I get: Traceback (most recent call last): File "/usr/local/bin/django-admin.py", line 2, in from django.core import management File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 11, in AttributeError: 'module' object has no attribute 'get_version' If I start a Python session, I can do: >>> import django >>> dir(django) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] which seems incomplete? What (probably obvious) step or action have I missed or messed up? Thanks Derek -- 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: Installation problem (version 1.2.1)
On May 28, 9:56 am, Derek wrote: > I have just upgraded my version of Ubuntu, which then also installed > Python 2.6. I thought this was a good opportunity to upgrade to > Django 1.2. I removed all traces of Django 1.1.1 that I could find, > along with extra plugins/modules/apps etc, and ran the install for > Django 1.2.1, checking that I was specifying "python2.6" when doing > so. > > However when I try and start a new project (django-admin.py > startproject test), I get: > > Traceback (most recent call last): > File "/usr/local/bin/django-admin.py", line 2, in > from django.core import management > File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", > line 11, in > AttributeError: 'module' object has no attribute 'get_version' > > If I start a Python session, I can do: > > >>> import django > >>> dir(django) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] > > which seems incomplete? > > What (probably obvious) step or action have I missed or messed up? > > Thanks > Derek Sounds like you have an old 'django' directory somewhere on your pythonpath that is empty apart from an __init__.py. In your shell, do: >>> import django >>> django.__path__ to see where it is, and delete it. -- 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.
Re: problems with authentication of test client
On May 28, 9:23 am, irum wrote: > import unittest > from django.test.client import Client > from django.test import Client, TestCase > from django.contrib.auth import authenticate > from django.contrib.auth.models import * > from django.core import mail > import datetime > import time > > class SimpleTest(TestCase): > fixtures = ['f1.json'] > > def setUp(self): # Every test needs a client > self.client = Client() > > def test_create(self): > > response = self.client.get('/createauction/') > # Check that it takes to login page if not logged n > self.failUnlessEqual(response.status_code, 302) > self.assertRedirects(response, '/login/?next=/createauction/') > > # i have created a user here again as some threads suggested that I > should make a user here. > user = User.objects.create_user(username = 'myadmin2', email > ='du...@dummy.com', password = 'testing2') > uid = user.id > user.is_staff = True > user.save() > > print "trying to login..." > > login = self.client.login(username='myadmin2', > password='testing2') > self.failUnless(login, True) > self.assertEqual( login, True) # this test does not fail, > means user has logged in succefully and login is True > > enddate = datetime.datetime(2010, 06, 04, 3, 45, 50) > > post_data = { > 'title' : 'Title1', > 'desc' : 'description', > 'start-date' : datetime.datetime.now() , > 'end_date' : enddate, > 'owner' : user.id, > 'price' : 60, > 'highbid' : 60, > 'banned' : False, > 'closed' : True, > > } > > r = c.post('/createauction/', post_data) > self.failUnlessEqual(r.status_code, 200) # this test fails, as > status_code returned is 302 > > These tests are run successully, meaning the user is redirected to > login page, implying that client never enters the else branch for > authenticated user in the 'cauction' view. > self.failUnlessEqual(r.status_code, 302) > self.assertRedirects(response, '/login/?next=/createauction/') > > I have put in more than a day in this problem, trying to figure out > where I am going wrong. I have tried to explain clearly here. Any one > has any idea? > > Thanks, > irum What is `c` in the second-last line of the test? Are you perhaps instantiating a separate test client somewhere? Show the actual code you're running. Also note you don't need to define self.client in setUp(), as TestCase does that already: http://docs.djangoproject.com/en/1.2/topics/testing/#default-test-client -- 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.
Re: password reset getting error - 'function' object is not iterable
At a first glance it looks like a problem with your urls. Could you show us your custom template and url definitions from urls.py? Nuno On Thu, May 27, 2010 at 7:10 PM, Pankaj Singh < singh.pankaj.iitkg...@gmail.com> wrote: > > > > > Exception Value: > > 'function' object is not iterable > > > > > > > > -- 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.
Annotating a queryset without aggregation
Hi all I want to annotate a qs with a computed field from one of its current fields, and then filter on the annotated field. I cannot work out how I'm supposed to do this in the ORM (or even if I can). Basically, I have a model with a username field, that in this case contains an email address. I want to extract the domain of that email address, and then filter the queryset based upon the value of the domain. So, in code: domains = UsageLogEntry.objects \ .filter(action=ACTION_FAILED_REGISTRATION, sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ .annotate(domain=...) \ .exclude(domain='').values_list('domain', flat=True) Im clueless about what to put in annotate(). In 1.0.x, I used a horrific hack with extra(), that has stopped working with 1.2: domains = UsageLogEntry.objects \ .filter(action=ACTION_FAILED_REGISTRATION, sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ .extra( select={ 'domain': 'SUBSTRING(username, LOCATE("@", username)+1)' }, # XXX hacks ahoy - this makes the where clause look like #WHERE ... AND 1 HAVING `domain` != '' where=[ "1 HAVING `domain` != ''", ], ) \ .order_by('domain') \ .values_list('domain', flat=True) This is because (I think) in 1.0.x, the where clause was bare, and in 1.2 it is enclosed by braces, which makes my hacky insertion of a having clause illegal syntax. Thanks for any pointers Tom -- 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: problems with authentication of test client
'c' is written here by mistake, I was trying different things by and commented out the wrong statement while pasting. It was, r = self.client.post('/createauction/', post_data) Also, could the problem be with my Python version 2.6.5 and Django 1.1.1 as stated in this thread: http://groups.google.com/group/django-users/browse_thread/thread/617457f5d62366ae/e5d1436ac93aeb61?lnk=gst&q=baffled# I have also tried after updating my django-trunk but the problem persisits. Should I downgrade to Python 2.6.4 to fix this? Irum On May 28, 12:13 pm, Daniel Roseman wrote: > On May 28, 9:23 am, irum wrote: > > > > > > > > > import unittest > > from django.test.client import Client > > from django.test import Client, TestCase > > from django.contrib.auth import authenticate > > from django.contrib.auth.models import * > > from django.core import mail > > import datetime > > import time > > > class SimpleTest(TestCase): > > fixtures = ['f1.json'] > > > def setUp(self): # Every test needs a client > > self.client = Client() > > > def test_create(self): > > > response = self.client.get('/createauction/') > > # Check that it takes to login page if not logged n > > self.failUnlessEqual(response.status_code, 302) > > self.assertRedirects(response, '/login/?next=/createauction/') > > > # i have created a user here again as some threads suggested that I > > should make a user here. > > user = User.objects.create_user(username = 'myadmin2', email > > ='du...@dummy.com', password = 'testing2') > > uid = user.id > > user.is_staff = True > > user.save() > > > print "trying to login..." > > > login = self.client.login(username='myadmin2', > > password='testing2') > > self.failUnless(login, True) > > self.assertEqual( login, True) # this test does not fail, > > means user has logged in succefully and login is True > > > enddate = datetime.datetime(2010, 06, 04, 3, 45, 50) > > > post_data = { > > 'title' : 'Title1', > > 'desc' : 'description', > > 'start-date' : datetime.datetime.now() , > > 'end_date' : enddate, > > 'owner' : user.id, > > 'price' : 60, > > 'highbid' : 60, > > 'banned' : False, > > 'closed' : True, > > > } > > > r = c.post('/createauction/', post_data) > > self.failUnlessEqual(r.status_code, 200) # this test fails, as > > status_code returned is 302 > > > These tests are run successully, meaning the user is redirected to > > login page, implying that client never enters the else branch for > > authenticated user in the 'cauction' view. > > self.failUnlessEqual(r.status_code, 302) > > self.assertRedirects(response, '/login/?next=/createauction/') > > > I have put in more than a day in this problem, trying to figure out > > where I am going wrong. I have tried to explain clearly here. Any one > > has any idea? > > > Thanks, > > irum > > What is `c` in the second-last line of the test? Are you perhaps > instantiating a separate test client somewhere? Show the actual code > you're running. > > Also note you don't need to define self.client in setUp(), as TestCase > does that > already:http://docs.djangoproject.com/en/1.2/topics/testing/#default-test-client > -- > 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.
Re: Annotating a queryset without aggregation
Hi Tom, Whilst Django annotation is great, it is rather simplistic in nature and can only do very basic Count, Sum, Avg, etc. which do not allow any filtering (i.e. a WHERE clause in the SQL). Unless there are major differences in 1.2 (which I haven't seen) then you won't be able to do what you want I'm afraid. Euan On May 28, 10:26 am, Tom Evans wrote: > Hi all > > I want to annotate a qs with a computed field from one of its current > fields, and then filter on the annotated field. I cannot work out how > I'm supposed to do this in the ORM (or even if I can). > > Basically, I have a model with a username field, that in this case > contains an email address. I want to extract the domain of that email > address, and then filter the queryset based upon the value of the > domain. > > So, in code: > > domains = UsageLogEntry.objects \ > .filter(action=ACTION_FAILED_REGISTRATION, > sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ > .annotate(domain=...) \ > .exclude(domain='').values_list('domain', flat=True) > > Im clueless about what to put in annotate(). > > In 1.0.x, I used a horrific hack with extra(), that has stopped > working with 1.2: > > domains = UsageLogEntry.objects \ > .filter(action=ACTION_FAILED_REGISTRATION, > sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ > .extra( > select={ 'domain': 'SUBSTRING(username, LOCATE("@", username)+1)' }, > # XXX hacks ahoy - this makes the where clause look like > # WHERE ... AND 1 HAVING `domain` != '' > where=[ "1 HAVING `domain` != ''", ], > ) \ > .order_by('domain') \ > .values_list('domain', flat=True) > > This is because (I think) in 1.0.x, the where clause was bare, and in > 1.2 it is enclosed by braces, which makes my hacky insertion of a > having clause illegal syntax. > > Thanks for any pointers > > Tom -- 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 approach to solve statistical problem
Darren, This seems like quite a complex problem and I'm not sure whether the Django ORM would be up to it. I've had a lot of trouble when using multiple annotations on Querysets when JOINs are involved as Django does the wrong thing. Have you considered using a schemaless DB like MongoDB for your data storage rather than a relational model? Your data does look quite relational though, but you might find some of the map/reduce functionality good. Euan On May 28, 5:50 am, darren wrote: > Needing to get this done, I went with SQL. The sql seems rather > inefficient. But, my data set will be rather small. I posted what I > went with on Pastebin: http://pastebin.com/VmiYNXan(good for 24 > hrs). > > I don't have much data loaded (just one tournament). But, you can see > the resulting table of data here: rankintornadoes.com. > > I would still like to know if this would be the recommended Django > way. Any advice would be welcome. > > Darren > > On Thu, May 27, 2010 at 2:19 PM, darren wrote: > > I'm looking for ideas on the best way to approach this problem. > > Should I write raw SQL, stay with the ORM or even mix Javascript with > > either ORM or SQL? > > > I want to keep up with player stats for a baseball team. I've been > > reading up on aggregates and annotations. And, I'm getting somewhere > > with it. But, not quite all the way yet. I also wrote some SQL that > > accomplishes most everything I need all at once. I think I could run > > with it, too. > > > To calculate things like "on base percentage" or "batting average", I > > need to mix math both vertically and horizontally in the table. One > > way I thought about handling this is to build an HTML table of data > > using a queryset based on this example in the Django documentation: > > > Book.objects.aggregate(Avg('price'), Max('price'), Min('price')) > > > except, I would need something that summed 3 or 4 different columns. > > > At that point, I could use javascript to Sum() the total of each and > > calculate averages. So, a table would be built like: > > > A B C D E > > F > > G H > > Player Name | Hits | Strike Outs | Walks | Fouled Out | > > Javascript Calcuated Total at Bats | Javascript Calc. Batting AVG | > > Javasctipt On Base % > > Player 1 3 2 5 2 > > A+B+C+D+E > > B/F (B+D)/F > > Player 2 4 2 5 1 > > A+B+C+D+E > > B/F (B+D)/F > > > My models contain 3 tables that join people, tournaments and an "at > > bat". The "AtBat" class is where the statistical data will be > > recorded. The model looks like this. So, I'm saving one result per > > record: > > > 101 class AtBat(models.Model): > > 102 atbat_id = models.AutoField(primary_key=True) > > 103 player = models.ForeignKey(Person, to_field='f_name', > > verbose_name='Player', limit_choices_to={'relationship' : 'Player' }) > > 104 game = models.ForeignKey(Score, to_field='scores_id', > > verbose_name='Game') > > 105 result = models.CharField('Result', choices=(('H', 'Hit'), > > ('BB', 'Walk'), ('K', 'Strike Out'), ('FO', 'Ground or Fly Out'), > > ('Sacrifice', 'Sacrafice')), max_length=10) > > > One of my goals would be to allow users to select certain players, > > date ranges or games to filter the results. I'm not sure how that > > might impact the solution. > > > Any suggestions? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Annotating a queryset without aggregation
Django 1.2 is more than happy to filter on aggregates and annotations, see: http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#aggregations-and-other-queryset-clauses My problem is that I can't see how to specify this additional computed field as an annotation, and can only coerce it in with extra(), which doesn't allow filtering, and no way to manually insert a HAVING clause. With this particular data set, I found a simpler way to exclude the tuples I wasn't interested in (filtering on the field that my annotation is based upon), but I would still be interested if there is a way to do this. Cheers Tom On Fri, May 28, 2010 at 11:29 AM, Euan Goddard wrote: > Hi Tom, > > Whilst Django annotation is great, it is rather simplistic in nature > and can only do very basic Count, Sum, Avg, etc. which do not allow > any filtering (i.e. a WHERE clause in the SQL). > > Unless there are major differences in 1.2 (which I haven't seen) then > you won't be able to do what you want I'm afraid. > > Euan > > On May 28, 10:26 am, Tom Evans wrote: >> Hi all >> >> I want to annotate a qs with a computed field from one of its current >> fields, and then filter on the annotated field. I cannot work out how >> I'm supposed to do this in the ORM (or even if I can). >> >> Basically, I have a model with a username field, that in this case >> contains an email address. I want to extract the domain of that email >> address, and then filter the queryset based upon the value of the >> domain. >> >> So, in code: >> >> domains = UsageLogEntry.objects \ >> .filter(action=ACTION_FAILED_REGISTRATION, >> sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ >> .annotate(domain=...) \ >> .exclude(domain='').values_list('domain', flat=True) >> >> Im clueless about what to put in annotate(). >> >> In 1.0.x, I used a horrific hack with extra(), that has stopped >> working with 1.2: >> >> domains = UsageLogEntry.objects \ >> .filter(action=ACTION_FAILED_REGISTRATION, >> sub_action=SUB_ACTION_DOMAIN_DISALLOWED) \ >> .extra( >> select={ 'domain': 'SUBSTRING(username, LOCATE("@", username)+1)' >> }, >> # XXX hacks ahoy - this makes the where clause look like >> # WHERE ... AND 1 HAVING `domain` != '' >> where=[ "1 HAVING `domain` != ''", ], >> ) \ >> .order_by('domain') \ >> .values_list('domain', flat=True) >> >> This is because (I think) in 1.0.x, the where clause was bare, and in >> 1.2 it is enclosed by braces, which makes my hacky insertion of a >> having clause illegal syntax. >> >> Thanks for any pointers >> >> Tom > > -- > 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. > > -- 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: db problems after upgrading
Hi, darren wrote: > I upgraded django version from (not exactly sure) about 1.0 to 1.2. > After doing so, if I run manage.py syncdb, I get messages saying I > need to add unique constraints. I added "unique=True" to the columns > in the model that were indicated. However, I continue to get the > messages. That didn't turn out to be what I wanted anyway because I > couldn't add additional records due to those constraints. Are the fields that it requires unique for, foreign keys? Or do they have db_index set? This may very well be caused by: http://code.djangoproject.com/ticket/11702 If this doesn't help, it would be helpful to see your models.py. cheers, Erik -- 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: Looking for a good CRUD example
Try... http://alpha.djangogenerator.com It will generate a substantial amount of boilerplate code for you. Including templates and various views for listing, editing and viewing models, and admin access with admin documentation setup too. It is helping me greatly with folder layout and basic functionality. HTH, Richard Shebora On Fri, May 28, 2010 at 1:09 AM, Lee Hinde wrote: > Hi; > I've appreciated the sample apps out there as great learning tools. > I'm having problems saving existing records (new ones get created instead?) > and with validation. But rather than pepper the group with my ?s, I'd like > to do some more code reviews. > So, I'm wondering if you can recommend one of the many django-apps out there > as a good CRUD sample. (Admin is great, but it's too abstract for this > newbie.) > > Thanks.. > - Lee > > -- > 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. > -- 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: admin: add save -> error
On Fri, May 28, 2010 at 2:33 AM, Philipp wrote: > Thanks a lot Karen, I did google and found some more info here: > > http://trac.turbogears.org/ticket/2133#comment:11 > > just as a note, this is an issue on Django Developer Kit 1.2.1 > > FYI this has now been fixed in Django trunk: http://code.djangoproject.com/changeset/13310 Karen -- http://tracey.org/kmt/ -- 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: problems with authentication of test client
On Fri, May 28, 2010 at 5:42 AM, irum wrote: > I have also tried after updating my django-trunk but the problem > persisits. Should I downgrade to Python 2.6.4 to fix this? > The problem you reference has been fixed in 1.2.x (and also 1.1.2), so if updating to current Django code did not fix the problem then I would not expect downgrading Python to help either. It sounds like you are running into something else. I would start by trying a simplified view and test that focuses only on checking that the test client login is working, nothing else. If that works then you can proceed to add stuff and figure out what causes the test to eventually break. If the very simple test/view continues to fail then perhaps when you post the specifics of the code someone else will be able to recreate and help debug or spot where the problem is. Karen -- http://tracey.org/kmt/ -- 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.
Fetch DoesNotExist from get_object_for_this_type
Hello, how to fetch the DoesNotExist exception generated by get_object_for_this_type? Being generic i can't use the actual model. I tried something like that, but i doesn't seem to work, the original exception is still raised. from django.contrib.contenttypes.models import ContentType from django.http import Http404 from django.shortcuts import get_object_or_404 ctype = get_object_or_404(ContentType, app_label=obj_app, model=obj_model) try: obj = ctype.get_object_for_this_type(id=obj_id) except ctype.DoesNotExist: raise Http404 Best Regards, Dirk Eschler -- Dirk Eschler -- 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: Fetch DoesNotExist from get_object_for_this_type
On May 28, 1:33 pm, Dirk Eschler wrote: > Hello, > > how to fetch the DoesNotExist exception generated by get_object_for_this_type? > Being generic i can't use the actual model. > > I tried something like that, but i doesn't seem to work, the original > exception is still raised. > > from django.contrib.contenttypes.models import ContentType > from django.http import Http404 > from django.shortcuts import get_object_or_404 > > ctype = get_object_or_404(ContentType, > app_label=obj_app, > model=obj_model) > try: > obj = ctype.get_object_for_this_type(id=obj_id) > except ctype.DoesNotExist: > raise Http404 > > Best Regards, > Dirk Eschler > The DoesNotExist exceptions for each model are subclasses of django.core.exceptions.ObjectDoesNotExist - you can catch that instead. -- 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.
Re: Fetch DoesNotExist from get_object_for_this_type
Am Freitag 28 Mai 2010, 14:43:21 schrieb Daniel Roseman: > On May 28, 1:33 pm, Dirk Eschler wrote: > > how to fetch the DoesNotExist exception generated by > > get_object_for_this_type? Being generic i can't use the actual model. [...] > The DoesNotExist exceptions for each model are subclasses of > django.core.exceptions.ObjectDoesNotExist - you can catch that > instead. Hello Daniel, good point. Thanks alot. Best Regards, Dirk Eschler -- Dirk Eschler -- 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: Installation problem (version 1.2.1)
I think Daniel might mean you can also use the __file__ attribute, as in: >>> import django >>> django.__file__ Hope that helps, Alex On May 28, 4:07 am, Daniel Roseman wrote: > On May 28, 9:56 am, Derek wrote: > > > > > I have just upgraded my version of Ubuntu, which then also installed > > Python 2.6. I thought this was a good opportunity to upgrade to > > Django 1.2. I removed all traces of Django 1.1.1 that I could find, > > along with extra plugins/modules/apps etc, and ran the install for > > Django 1.2.1, checking that I was specifying "python2.6" when doing > > so. > > > However when I try and start a new project (django-admin.py > > startproject test), I get: > > > Traceback (most recent call last): > > File "/usr/local/bin/django-admin.py", line 2, in > > from django.core import management > > File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", > > line 11, in > > AttributeError: 'module' object has no attribute 'get_version' > > > If I start a Python session, I can do: > > > >>> import django > > >>> dir(django) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > '__path__'] > > > which seems incomplete? > > > What (probably obvious) step or action have I missed or messed up? > > > Thanks > > Derek > > Sounds like you have an old 'django' directory somewhere on your > pythonpath that is empty apart from an __init__.py. > > In your shell, do: > > >>> import django > >>> django.__path__ > > to see where it is, and delete it. > -- > 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.
piston and related models
Hi! I don't know how to make django-piston save my related objects. This is my handler file: from piston.handler import BaseHandler, AnonymousBaseHandler from piston.utils import rc, require_mime, require_extended from test.networking.models import NetworkingProfile class NetworkingProfileHandler(BaseHandler): model = NetworkingProfile def create(self, request): attrs = self.flatten_dict(request.POST) if (self.exists(**attrs)): return rc.DUPLICATE_ENTRY else: if ('languages' in attrs): languages = list() for code in attrs['languages'].split(','): languages.append(Language().get_language(code)) attrs['languages'] = languages networking_profile = NetworkingProfile(user=request.user, **attrs) networking_profile.save() return networking_profile And this, my related models: class NetworkingProfile(models.Model): user = models.ForeignKey(User, unique=False) searching = models.TextField(blank=False, help_text='Little description about what are you searching for.') languages = models.ManyToManyField(Language) place = models.CharField(max_length=64, blank=True, help_text='A place where you will be in the future.') availability = models.DateTimeField(default=datetime.now, blank=True, help_text='Temporal availability.') class Language(models.Model): code = models.CharField(max_length=12, primary_key=True, help_text='Example: en, es...') name = models.CharField(max_length=64, help_text='The real name.') def __unicode__(self): return u'%s' % (self.name) def get_language(self, code): return Language.objects.get(code=code) If I test with: curl -u user:password http://127.0.0.1/api/np/ -F "searching=example" it works perfectly, but If I write: curl -u user:password http://127.0.0.1/np/ -F "searching=example" -F "languages=it,gl" it fails with error: Piston/0.2.3rc1 (Django 1.2) crash report: Method signature does not match. Resource does not expect any parameters. Exception was: 'languages' is an invalid keyword argument for this function I've test lot of ways to do that, but I can't know how to do it work. Thanks for your help. Regards, Álex González -- Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt and/or .pptx http://mirblu.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-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.
load model anywhere
hi, sou do brasil, como faço para o Django carregar os Models de qualquer arquivo? exemplo: carregar do arquivo usuario.py e não do models.py alguém pode me ajudar?? (eu lei ingles, mas não sei escrever alguem aí lê portugues?) obrigado! -- 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 approach to solve statistical problem
That sounds interesting. As I am new to Django, I never really gave putting the logic in the model, although I did happen to read a little about model methods yesterday. Would you mind making some of your code available? I'd be interested in seeing your approach. Darren On Fri, May 28, 2010 at 12:08 AM, Kenneth Gonsalves wrote: > On Friday 28 May 2010 10:20:55 darren wrote: >> Needing to get this done, I went with SQL. The sql seems rather >> inefficient. But, my data set will be rather small. I posted what I >> went with on Pastebin: http://pastebin.com/VmiYNXan (good for 24 >> hrs). >> >> I don't have much data loaded (just one tournament). But, you can see >> the resulting table of data here: rankintornadoes.com. >> >> I would still like to know if this would be the recommended Django >> way. Any advice would be welcome. >> > > > interesting - although not directly relevant to what you are asking, I am > doing something similar with golf tournaments, and finally found the best > approach was to put most of the scoring and statistics in the models > themselves. That was painful to do, but now I can generate practically > anything I want from the templates themselves. Like a player model knows it's > statistics ... I mostly use pure python for the calculations and periodically > pickle and save the results for faster access. (please ignore this if it > sounds like irrelevant rambling) > -- > Regards > Kenneth Gonsalves > Senior Associate > NRC-FOSS at AU-KBC > > -- > 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. > > -- 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 approach to solve statistical problem
I'm benefiting a great deal from all other aspects of Django. So, I'm not concerned about having to use SQL to get the job done. However, I really want to do it the way the Django developers intended it to be done, which may be to use raw SQL. The only thing I don't like about addressing the sql results in my templates is that I have to address them by index value, rather than by name. For example, instead of person.f_name, I have to do person.0. Am I missing a concept here? As for the MongoDB, I've never attempted using it. At this point, I really don't need another project with a learning curve. And, I'm comfortable with SQL. Finally, the link to my stats should have been http://rankintornadoes.com/stats Darren On Fri, May 28, 2010 at 5:35 AM, Euan Goddard wrote: > Darren, > > This seems like quite a complex problem and I'm not sure whether the > Django ORM would be up to it. I've had a lot of trouble when using > multiple annotations on Querysets when JOINs are involved as Django > does the wrong thing. > > Have you considered using a schemaless DB like MongoDB for your data > storage rather than a relational model? Your data does look quite > relational though, but you might find some of the map/reduce > functionality good. > > Euan > > On May 28, 5:50 am, darren wrote: >> Needing to get this done, I went with SQL. The sql seems rather >> inefficient. But, my data set will be rather small. I posted what I >> went with on Pastebin: http://pastebin.com/VmiYNXan(good for 24 >> hrs). >> >> I don't have much data loaded (just one tournament). But, you can see >> the resulting table of data here: rankintornadoes.com. >> >> I would still like to know if this would be the recommended Django >> way. Any advice would be welcome. >> >> Darren >> >> On Thu, May 27, 2010 at 2:19 PM, darren wrote: >> > I'm looking for ideas on the best way to approach this problem. >> > Should I write raw SQL, stay with the ORM or even mix Javascript with >> > either ORM or SQL? >> >> > I want to keep up with player stats for a baseball team. I've been >> > reading up on aggregates and annotations. And, I'm getting somewhere >> > with it. But, not quite all the way yet. I also wrote some SQL that >> > accomplishes most everything I need all at once. I think I could run >> > with it, too. >> >> > To calculate things like "on base percentage" or "batting average", I >> > need to mix math both vertically and horizontally in the table. One >> > way I thought about handling this is to build an HTML table of data >> > using a queryset based on this example in the Django documentation: >> >> > Book.objects.aggregate(Avg('price'), Max('price'), Min('price')) >> >> > except, I would need something that summed 3 or 4 different columns. >> >> > At that point, I could use javascript to Sum() the total of each and >> > calculate averages. So, a table would be built like: >> >> > A B C D E >> > F >> > G H >> > Player Name | Hits | Strike Outs | Walks | Fouled Out | >> > Javascript Calcuated Total at Bats | Javascript Calc. Batting AVG | >> > Javasctipt On Base % >> > Player 1 3 2 5 2 >> > A+B+C+D+E >> > B/F (B+D)/F >> > Player 2 4 2 5 1 >> > A+B+C+D+E >> > B/F (B+D)/F >> >> > My models contain 3 tables that join people, tournaments and an "at >> > bat". The "AtBat" class is where the statistical data will be >> > recorded. The model looks like this. So, I'm saving one result per >> > record: >> >> > 101 class AtBat(models.Model): >> > 102 atbat_id = models.AutoField(primary_key=True) >> > 103 player = models.ForeignKey(Person, to_field='f_name', >> > verbose_name='Player', limit_choices_to={'relationship' : 'Player' }) >> > 104 game = models.ForeignKey(Score, to_field='scores_id', >> > verbose_name='Game') >> > 105 result = models.CharField('Result', choices=(('H', 'Hit'), >> > ('BB', 'Walk'), ('K', 'Strike Out'), ('FO', 'Ground or Fly Out'), >> > ('Sacrifice', 'Sacrafice')), max_length=10) >> >> > One of my goals would be to allow users to select certain players, >> > date ranges or games to filter the results. I'm not sure how that >> > might impact the solution. >> >> > Any suggestions? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-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. > > -- You received this message because you are subscribed to the Google Groups "Django users" g
Re: Creating a custom view in Django admin,
Thank you chr, I've never experimented with managers, but it's quite useful. I guess a custom manager is also the only way to have a foreignkey to a user in a specific group. But although I'm a bit further, I still don't know the answer to my million-dollar question. Is it possible to have an intermediary step before actually saving the object. In which I have a custom view? What I actually want is a multiple step saving process. Is that possible without ugly hacks? Thanks in advance. Grtz, Dexter On Thu, May 27, 2010 at 8:54 PM, chr wrote: > On May 26, 7:02 pm, Dexter wrote: > > Another thing: > > > > At the event model, it is unnecessary to display all the events in the > > admin. How can I make sure only the events coming (ie > > date__gte=datetime.now()) are displayed in the admin? > > i think a proxy model[1] might work where you set the default manager > to only filter for all objects greater than now(). then, instead of > (or in addition to) the actual event model you register the proxymodel > with the admin. > > [1] > http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-model-managers > > -- > 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. > > -- 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.
android app for the documentation site
Hi All, I thought some of you with android phones might be interested, I knocked up a quick app to make browsing the doc site a bit easier for me. It's in the marketplace for download. It's got some quick links to topics I tend to lookup a lot. I was thinking of adding in custom bookmarks and snippets. http://jaymz.eu/2010/05/django-reference-in-android-market-now/ Any suggestions are welcome, Cheers, jaymz -- 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: android app for the documentation site
On 2010-05-28, at 17:31 , jaymzcd wrote: > > Hi All, > > I thought some of you with android phones might be interested, I > knocked up a quick app to make browsing the doc site a bit easier for > me. It's in the marketplace for download. It's got some quick links to > topics I tend to lookup a lot. I was thinking of adding in custom > bookmarks and snippets. > > http://jaymz.eu/2010/05/django-reference-in-android-market-now/ > > Any suggestions are welcome, Create a Sphinx Django template for mobile content instead, that way it's also compatible with Pre, Nokias and other iPhones and it can be pushed to Django's very own website? -- 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.
makeing a foreign key optional
Hey, i want to have an optional foreign key in my model. I tried sth like this: person= models.ForeignKey('Person', related_name="kontakt",blank=True,null=True) If I try to add a new object in the admin interface it is always complaining that i have no value selected in the person field. What am I doing wrong here? Thx Sebastian -- 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: makeing a foreign key optional
Had you already run syncdb when you made the field optional? If so, you need to use a migration tool -- syncdb doesn't change existing tables, only creates new ones. Shawn -- 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: Newbie having problems with django project tutorial setup - errors with psycopg2
If you're in a terrible rush, you could switch to sqlite3 during development until you're ready to go to production. It sounds like either psycopg2 didn't install properly, or your Django instance is running under a different version or installation of Python than the one where you installed the psycopg2 module. What happens if you go to the command line and run the Python interactive interpreter and type "import psycopg2"? Shawn -- 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: Newbie having problems with django project tutorial setup - errors with psycopg2
When I do import from Python, it can't find it either. I need Postgresql for a job. I saw a post somewhere else that says maybe my Python path is not complete, so I will look at that when I get home. Thanks for the reply! Cyndi www.mysticbostons.com On Fri, May 28, 2010 at 12:22 PM, Shawn Milochik wrote: > If you're in a terrible rush, you could switch to sqlite3 during > development until you're ready to go to production. > > It sounds like either psycopg2 didn't install properly, or your Django > instance is running under a different version or installation of Python than > the one where you installed the psycopg2 module. > > What happens if you go to the command line and run the Python interactive > interpreter and type "import psycopg2"? > > Shawn > > > -- > 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. > > -- 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.
Admin: issues in saving an object in popup
In the Admin application I can create related objects 'on the fly' in a popup (e.g. when changing a User I can create Groups by pressing the green 'plus' next to the Group list): this is done adding '_popup=1' to the url used in the popup (e.g. "/admin/auth/group/add/?_popup=1"). The 'Save' button in this popup updates the main page and closes the popup. I tried to do the same for inspecting a related object (e.g. inspect a Group while changing a User), so I opened a popup on "/admin/auth/ group/1/?_popup=1" and the form was correctly displayed with no header. The problem is that after pressing the 'Save' button the popup isn't closed but it is redirected to the object list (I think that a correct behaviour is to update the Group in the User Group list and close the window). Is this a bug? Is there any other solution? Thank you -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: makeing a foreign key optional
Hey Shawn, I have deleted the whole DB just to be sure. It must be sth else. I'm using the grapelli admin interface. An SQL insert query with NULL as foreign key is working. So it must be sth abouth the django validation stuff. thx, Sebastian On 28 Mai, 18:18, Shawn Milochik wrote: > Had you already run syncdb when you made the field optional? If so, you need > to use a migration tool -- syncdb doesn't change existing tables, only > creates new ones. > > Shawn -- 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: makeing a foreign key optional
Hey Shawn, I have deleted the whole DB just to be sure. It must be sth else. I'm using the grapelli admin interface. An SQL insert query with NULL as foreign key is working. So it must be sth abouth the django validation stuff. thx, Sebastian On 28 Mai, 18:18, Shawn Milochik wrote: > Had you already run syncdb when you made the field optional? If so, you need > to use a migration tool -- syncdb doesn't change existing tables, only > creates new ones. > > Shawn -- 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.
Create Dynamic data with mongokit
I need to create a project that creates dynamic forms, which I keep in a relational database structure and use the form MongoDB to persist the data, keeping in different collections each form. Am I creating this dynamic class that way [1], but I'm having some trouble returning the seguitne error [2] (ipython traceback): can anyone help me with this? [1]http://paste.pocoo.org/show/219363/ [2]http://paste.pocoo.org/show/219367/ -- Marcos Daniel Petry http://mdpetry.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-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.
BaseGenericInlineFormSet failing on Save As New in admin
I'm using an InlineAdmin that is a generic relation, similar to django tagging, with one of my model admins. The problem is on a save as new, if the original object has tags, then the initial form count, gotten from the management form, isn't zero, even though the new object will have zero tags, causing an error when the formset searches for those initial tags. Now the BaseInlineFormSet takes care of this by returning zero for initial form count if save as new is set as True. Is there a reason why BaseGenericInlineFormSet doesn't do the same thing? Hopefully I explained this well enough. Perhaps I'm missing something, but I think the BaseGenericInlineFormSet should do the same as the BaseInlineFormSet. I am currently using django 1.1, but looking at the code for 1.2, it seems to still so the same thing. Thanks in advance if you know what I'm 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-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: Content Types and Filtering Generic Relationships
Still hoping someone has some insight here. I've been plugging away at it and am still not finding an answer I can live with as an engineer. Currently I'm cheating a bit to filter down by only published objects in my view like so tag = get_object_or_404(Tag, slug=slug) contentitems = tag.taggeditem_set.all() contentlist = [item for item in contentitems if item.content_object.status == 'P'] Obviously this seems a bit sloppy and I'm probably better off putting this in a custom related manager that catches errors if I'm trying to filter on fields that a model doesn't have (which could happen in generic models). It doesn't do well at ordering obviously. I'm still struggling with this though and am not sure generic tagging is the way I should be going with this. Still appreciate any insight out there. On May 24, 10:05 am, Streamweaver wrote: > I'm trying to implement tagging using Content Types and Generic > Relationships. What I want to is query any tagged item with a > status of Published. > > All my tagged models are implementing an Abstract Model class with a > status field so they share the 'Published' and 'Unpublished' types. > > Here are some cut down version of the models I'm using for an > example. Right now I only have Posts related to Tags but I plan on > adding flat pages and such. What I want to be able to have pages for > tags return all content with a status of Published but I don't seem to > be able to find a way to do this. I can find content and tags just > fine but when I have to filter it further I'm stumbling and would > appreciate any insight or pointers to example code. I've seen some > examples of custom managers online but the folks there are writing > naked SQL in the managers and I'd like to avoid going that route if I > can > > class Tag(models.Model): > > text = models.CharField(max_length=30, unique=True) > slug = models.SlugField(max_length=30, unique=True, null=True, > blank=True) > > class TaggedItem(models.Model): > > tag = models.ForeignKey(Tag) > > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey('content_type', > 'object_id') > > class Post(models.Model): > > title = models.CharField(max_length=75) > ... > status = models.CharField(max_length=1, choices=POST_STATUS) > > topics = generic.GenericRelation(TopicCatalog) > tags = generic.GenericRelation(TagCatalog) > > -- > 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: Content Types and Filtering Generic Relationships
Have you checked out http://code.google.com/p/django-tagging/ ? On May 28, 12:54 pm, Streamweaver wrote: > Still hoping someone has some insight here. I've been plugging away > at it and am still not finding an answer I can live with as an > engineer. > > Currently I'm cheating a bit to filter down by only published objects > in my view like so > > tag = get_object_or_404(Tag, slug=slug) > > contentitems = tag.taggeditem_set.all() > > contentlist = [item for item in contentitems if > item.content_object.status == 'P'] > > Obviously this seems a bit sloppy and I'm probably better off putting > this in a custom related manager that catches errors if I'm trying to > filter on fields that a model doesn't have (which could happen in > generic models). > > It doesn't do well at ordering obviously. > > I'm still struggling with this though and am not sure generic tagging > is the way I should be going with this. Still appreciate any insight > out there. > > On May 24, 10:05 am, Streamweaver wrote: > > > > > I'm trying to implement tagging using Content Types and Generic > > Relationships. What I want to is query any tagged item with a > > status of Published. > > > All my tagged models are implementing an Abstract Model class with a > > status field so they share the 'Published' and 'Unpublished' types. > > > Here are some cut down version of the models I'm using for an > > example. Right now I only have Posts related to Tags but I plan on > > adding flat pages and such. What I want to be able to have pages for > > tags return all content with a status of Published but I don't seem to > > be able to find a way to do this. I can find content and tags just > > fine but when I have to filter it further I'm stumbling and would > > appreciate any insight or pointers to example code. I've seen some > > examples of custom managers online but the folks there are writing > > naked SQL in the managers and I'd like to avoid going that route if I > > can > > > class Tag(models.Model): > > > text = models.CharField(max_length=30, unique=True) > > slug = models.SlugField(max_length=30, unique=True, null=True, > > blank=True) > > > class TaggedItem(models.Model): > > > tag = models.ForeignKey(Tag) > > > content_type = models.ForeignKey(ContentType) > > object_id = models.PositiveIntegerField() > > content_object = generic.GenericForeignKey('content_type', > > 'object_id') > > > class Post(models.Model): > > > title = models.CharField(max_length=75) > > ... > > status = models.CharField(max_length=1, choices=POST_STATUS) > > > topics = generic.GenericRelation(TopicCatalog) > > tags = generic.GenericRelation(TagCatalog) > > > -- > > 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.
delete file or image after deleting model item
There are ImageField and FileField in a model. When model item removed, image and file stay. Is it normal behavior? Is there a way to remove image and file automatically? -- 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: runtests.py fails with ImportError: No module named messages
That seems reasonable. So if I want to run tests on local django workspace and have older django installed (in daily work I use 1.1.1) I need to simply have this django workspace added to PYTHONPATH? Won't this mess with my default django installation? On May 27, 2010 4:03 PM, "Karen Tracey" wrote: 2010/5/27 Filip Gruszczyński > > I am trying to run tests on the trunk (rev 13307) and when I do, I get: > > grusz...@gruszczy-la... Every time I have seen this, the problem has been that I'm using a settings file generated with 1.2-level code but I've got my PYTHONPATH pointing to a 1.1.something (or earlier) version of Django. Karen -- http://tracey.org/kmt/ -- 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. -- 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: contrib.auth test failures persist to 1.2
Yes, it seems the fault is on my side (not directly, not my code :-)). Thanks a lot. On May 19, 2010 3:54 PM, "Karen Tracey" wrote: 2010/5/19 Filip Gruszczyński > > I have just installed Django 1.2 hoping, that my test suites will > finally work flawlessly and... If you create a new Django project & app, include admin and auth in INSTALLED_APPS, and run the tests, they pass. I'm aware of some issues with built-in auth and/or admin tests failing depending on specific project settings, see for example: http://code.djangoproject.com/ticket/11077. That ticket references discussions on django-dev covering the broader (still open) issue of integration testing versus application testing. It's possible that broader issue is what you are running into here. However, so far as I can tell I have never seen a report of these auth remote_user tests failing before. I can find no mention of such failures in trac nor in my mail archive of django-users. So I have no idea if this is an integration/application test issue or something else. The first things to figure out would be what's different about your project compared to a newly-created one that is leading to these tests failing. You have not given any specifics about your project so I'm not really sure what might be causing these failures. Karen -- http://tracey.org/kmt/ -- 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. -- 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.
Trouble with comment moderation
I have a very simple blog app and am trying to enable moderation on the entries. I'm following the docs, but nothing seems to be happening: The code: http://dpaste.com/200509/ Which would lead me to entries > 14 days old would be closed for commenting. Not so. And no matter what I do, all comments are marked as public. -- 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: mod_wsgi can't find app to import..but I added path to wsgi file?!
On May 27, 6:56 pm, Graham Dumpleton wrote: > You also need to add '/home/seb/MAIN/seoconquer'. Read: > > http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html I tried both versions of the wsgi script on your blog. And I still get this same error. ImportError: No module named mvc I think the problem is this line in settings.py where it can't find seoconquer.mvc to load. I printed the vars on your blog from withing my settings.py if that helps... __name__ =seoconquer.settings __file__ =/home/seb/MAIN/seoconquer/settings.py os.getcwd() =/home/www os.curdir =. sys.path =['/home/seb/MAIN', '/home/seb/MAIN/seoconquer',...etc.] sys.modules.keys() =['django.utils.text', 'decimal', 'django.core.django',...etc.] sys.modules.has_key('seoconquer') =True Notice that both necessary paths are in sys.path?!?!!? cs -- 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.
How do you handle broken tests from plug-ins?
I'm using Django-registration and Django-invitation. They both work on my website, but they both come with tests that fail. I don't think the tests are failing because the plug-ins don't work. I think they're failing due to different testing environments. Django- registration in particular gives me 10 errors due to linking to other pages in my base template that I know for certain works. How would you handle this? Delete the tests and write my own? Just delete the tests? Modify the tests to make them work? Something else? -- 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: BaseGenericInlineFormSet failing on Save As New in admin
Added this for my GenericInlineFormSet and things seem to work correctly now: class MyGenericInlineFormSet(BaseGenericInlineFormSet): def __init__(self,*args,**kwargs): self.save_as_new = kwargs.get('save_as_new',False) super(MyGenericInlineFormSet,self).__init__(*args,**kwargs) def initial_form_count(self): if self.save_as_new: return 0 return super(MyGenericInlineFormSet, self).initial_form_count() def total_form_count(self): if self.save_as_new: return super(MyGenericInlineFormSet, self).initial_form_count() return super(MyGenericInlineFormSet, self).total_form_count() def _construct_form(self, i, **kwargs): form = super(MyGenericInlineFormSet, self)._construct_form(i, **kwargs) if self.save_as_new: # Remove the primary key from the form's data, we are only # creating new instances form.data[form.add_prefix(self._pk_field.name)] = None # Remove the object id from the form's data form.data[form.add_prefix(self.ct_fk_field_name)] = None return form On May 28, 12:36 pm, Stephen Sundell wrote: > I'm using an InlineAdmin that is a generic relation, similar to django > tagging, with one of my model admins. The problem is on a save as > new, if the original object has tags, then the initial form count, > gotten from the management form, isn't zero, even though the new > object will have zero tags, causing an error when the formset searches > for those initial tags. Now the BaseInlineFormSet takes care of this > by returning zero for initial form count if save as new is set as > True. Is there a reason why BaseGenericInlineFormSet doesn't do the > same thing? > > Hopefully I explained this well enough. > > Perhaps I'm missing something, but I think the > BaseGenericInlineFormSet should do the same as the BaseInlineFormSet. > I am currently using django 1.1, but looking at the code for 1.2, it > seems to still so the same thing. > > Thanks in advance if you know what I'm 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-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: mod_wsgi can't find app to import..but I added path to wsgi file?!
In '/home/seb/MAIN/seoconquer', can you do: ls -las ls -las mvc and post the output. If you are concerned about revealing details send it to my email direct. Graham On May 29, 7:19 am, Chris Seberino wrote: > On May 27, 6:56 pm, Graham Dumpleton > wrote: > > > You also need to add '/home/seb/MAIN/seoconquer'. Read: > > > http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html > > I tried both versions of the wsgi script on your blog. And I still get > this same error. > > ImportError: No module named mvc > > I think the problem is this line in settings.py where it can't find > seoconquer.mvc to load. > > I printed the vars on your blog from withing my settings.py if that > helps... > > __name__ =seoconquer.settings > __file__ =/home/seb/MAIN/seoconquer/settings.py > os.getcwd() =/home/www > os.curdir =. > sys.path =['/home/seb/MAIN', '/home/seb/MAIN/seoconquer',...etc.] > sys.modules.keys() =['django.utils.text', 'decimal', > 'django.core.django',...etc.] > sys.modules.has_key('seoconquer') =True > > Notice that both necessary paths are in sys.path?!?!!? > > cs -- 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.
Getting brackets at the end of your Keys?
I'm having to, in Javascript, create a dictionary ( my_dict = {} ), then put in some Arrays. my_dict["stringkey"] = Array("hey","hey1") my_dict["stringkey1"] = Array("more","stuff") In the views function: for key in request.POST: prop_rec = request.POST.getlist(key) The Python var, "prop_rec" has the array contents that I'm expecting. However, I also need to use "key". But when I'm sending over stuff from javascript like above, the key has a "[]" tacked on the end of it, like "stringkey[]" If I code the normal in js: my_dict["stringkey"] = "1", then if I do a print key in the views function, I don't get the brackets at the end -- 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.
Having to rstrip the " [] " from the end of your Key when posted?
I'm having to, in Javascript, create a dictionary ( my_dict = {} ), then put in some Arrays. my_dict["stringkey"] = Array("hey","hey1") my_dict["stringkey1"] = Array("more","stuff") In the views function: for key in request.POST: prop_rec = request.POST.getlist(key) The Python var, "prop_rec" has the array contents that I'm expecting. However, I also need to use "key". But when I'm sending over stuff from javascript like above, the key has a "[]" tacked on the end of it, like "stringkey[]" If I code the normal in js: my_dict["stringkey"] = "1", then if I do a print key in the views function, I don't get the brackets at the end So just wondering if that's normal. -- 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.
ManyToMany + through model disappear from Admin interface
Hello, I have this simple code, which dives me crazy already :( class ActiveInformer(models.Model): informer = models.ForeignKey('Informer', related_name='act_informers') user = models.ForeignKey(User, related_name='informers') class Informer(models.Model): informer_types = (('P', 'Poll'), ('I', 'Info'), ) Name = models.CharField(max_length=50) Type = models.CharField(default = 'I', max_length=1", choices = informer_types) Active = models.BooleanField(default=False,') ActiveFor = models.ManyToManyField(User, through=ActiveInformer) class User(models.Model): ... The issue is, when I avoid "through=ActiveInformer" parameter, I can see list of Users on Admin interface (when Django create it's own table for ManyToMany relation). As soon as I add "throught=", related Users disappear from list of shown Informer parameters on Admin interface. How to overcome this? What I'm 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-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.
Thread safety with Form Wizard
Hi guys, I'm a relative newbie at using Django in an actual production setting. I'm having trouble using the form wizard at the moment, and I noticed that there is one instance of the Wizard class, instantiated in urls.py. Is there anything I should worry about as far as thread safety is concerned (i.e. should I not store any context-specific data in "self")? -- 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.
common object
hi I'm new in this group and I'm newbie with django. I have this problem: I need to have a socket reference accessible from all views in the application. The concept is similar to the session concept, but if is possible I need to access to the socket without using session. have you idea about this? I hope so :) sorry for my bad english -- 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: Having to rstrip the " [] " from the end of your Key when posted?
I accept this as normal now. I think, what I'll need to do if I'm against stripping off the two characters, is simply putting the value that serves as the key, directly into the array as the last element. Simple enough. So in views function: It'll look like: request.POST["imthekeyval[]"] = ("someval", "anotherval", "imthekeyval") code: for key in request.POST.getlist(key): py_array = request.POST.getlist(key) ( py_array has all I need, no need to use the key which is sporting the mutant "[]" growth at the end ) On May 28, 5:41 pm, pyfreak wrote: > I'm having to, in Javascript, create a dictionary ( my_dict = {} ), > then put in some Arrays. > > my_dict["stringkey"] = Array("hey","hey1") > my_dict["stringkey1"] = Array("more","stuff") > > In the views function: > > for key in request.POST: > prop_rec = request.POST.getlist(key) > > The Python var, "prop_rec" has the array contents that I'm > expecting. > > However, I also need to use "key". But when I'm sending over stuff > from javascript like above, > the key has a "[]" tacked on the end of it, like "stringkey[]" > > If I code the normal in js: > my_dict["stringkey"] = "1", > then if I do a print key in the views function, I don't get > the brackets at the end > > So just wondering if that's normal. -- 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: Having to rstrip the " [] " from the end of your Key when posted?
On Fri, May 28, 2010 at 7:41 PM, pyfreak wrote: > However, I also need to use "key". But when I'm sending over stuff > from javascript like above, > the key has a "[]" tacked on the end of it, like "stringkey[]" You are most likely running into this, or an issue similar to it in another JavaScript library: http://dev.jquery.com/ticket/6057 -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Using Google Fusion tables as database
Hi, Is it possible to use Django with Google Fusion Tables http://code.google.com/apis/fusiontables/ as the backend? -- 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.
Get pk before commit
Hello, I am trying to figure out how to get a pk in the middle of a transaction. I need to set a field in the model based on the ID(default pk) to be given. As far as a i know, this ID should be allocated during the transaction. So i would imagine it would do the INSERT, then i could get the pk and do what i need to do, then proceed with the commit. Is this possible? 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 at http://groups.google.com/group/django-users?hl=en.