distinct doesn't work after sorting by reverse foreign key
For instance, I have two objects: 1) Blog 2) Entry with a ForeignKey to Blog, and a Date field titled DateAdded Now, I want to list all my blogs, ordering by the most recent added entry. I tried: blog.objects.all().sort_by('entry__dateAdded').distinct() But the result was that is a given blog had more than 1 entry, then it shows up in the resulting queryset more than once. It appears distinct () is doing nothing in this case. are more knowledgeable minds willing to share their insight on this problem? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: distinct doesn't work after sorting by reverse foreign key
thanks for the thorough reply! I now understand how to proceed. However, I'm not convinced that distinct shouldn't do this for me... but I understand this is a philosophical point, and I put my trust in the django developers to get it right (just like I do with the american government... ) On Dec 4, 9:24 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-12-04 at 19:09 -0800, ryan wrote: > > For instance, I have two objects: > > 1) Blog > > 2) Entry with a ForeignKey to Blog, and a Date field titled DateAdded > > > Now, I want to list all my blogs, ordering by the most recent added > > entry. > > > I tried: > > blog.objects.all().sort_by('entry__dateAdded').distinct() > > > But the result was that is a given blog had more than 1 entry, then it > > shows up in the resulting queryset more than once. It appears distinct > > () is doing nothing in this case. > > The distinct() call is working correctly (you're right that it is > effectively doing nothing, wrong to say it "doesn't work"). The problem > is that you are ordering by something that has multiple values and each > value contributes one output row. There is nothing in your ordering > statement to say that the database should only use the *maximum* value > of dateAdded for each entry. The only reasonable way to interpret > ordering by multi-valued fields is to treat each one as generating a > different output row, since otherwise we might as well just pick one at > random (the SQL specification agrees with that interpretation by the way > -- which is why Django does it. Only MySQL allows effective ordering by > columns not in the output list in this case and it's very non-standard). > > Refer to the massive callout box in the documentation for distinct() for > a more SQL-specific > explanation:http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct > > You could achieve the effect you're after by using extra(select=..., > order_by=...) to select the maximum date added value as an extra > column. > > Alternatively (and this would require some fairly deep poking into Query > internals, so probably not recommended) you could add some extra stuff > to the where-clause to say "where dateAdded = (Select max(dateAdded) > from ...)". Possible some extra(where="") usage could get you most > of the way there on that one. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: distinct doesn't work after sorting by reverse foreign key
thanks for the thorough reply! I now understand how to proceed. However, I'm not convinced that distinct shouldn't do this for me... but I understand this is a philosophical point, and I put my trust in the django developers to get it right (just like I do with the american government... ) On Dec 4, 9:24 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-12-04 at 19:09 -0800, ryan wrote: > > For instance, I have two objects: > > 1) Blog > > 2) Entry with a ForeignKey to Blog, and a Date field titled DateAdded > > > Now, I want to list all my blogs, ordering by the most recent added > > entry. > > > I tried: > > blog.objects.all().sort_by('entry__dateAdded').distinct() > > > But the result was that is a given blog had more than 1 entry, then it > > shows up in the resulting queryset more than once. It appears distinct > > () is doing nothing in this case. > > The distinct() call is working correctly (you're right that it is > effectively doing nothing, wrong to say it "doesn't work"). The problem > is that you are ordering by something that has multiple values and each > value contributes one output row. There is nothing in your ordering > statement to say that the database should only use the *maximum* value > of dateAdded for each entry. The only reasonable way to interpret > ordering by multi-valued fields is to treat each one as generating a > different output row, since otherwise we might as well just pick one at > random (the SQL specification agrees with that interpretation by the way > -- which is why Django does it. Only MySQL allows effective ordering by > columns not in the output list in this case and it's very non-standard). > > Refer to the massive callout box in the documentation for distinct() for > a more SQL-specific > explanation:http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct > > You could achieve the effect you're after by using extra(select=..., > order_by=...) to select the maximum date added value as an extra > column. > > Alternatively (and this would require some fairly deep poking into Query > internals, so probably not recommended) you could add some extra stuff > to the where-clause to say "where dateAdded = (Select max(dateAdded) > from ...)". Possible some extra(where="") usage could get you most > of the way there on that one. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: distinct doesn't work after sorting by reverse foreign key
There's no mind reading required. I have a queryset of Blog objects, not entry objects (or SQL rows for that matter). When I call distinct, I would expect a "distinct set of blog objects". Call it a strong technical point if you prefer, but I still feel this is what the common person would expect. On Dec 4, 10:17 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-12-04 at 20:15 -0800, ryan wrote: > > thanks for the thorough reply! I now understand how to proceed. > > > However, I'm not convinced that distinct shouldn't do this for me... > > It cannot read your mind. How is distinct() meant to know which of the > many multiple values it should use for ordering? Should it pick one at > random? That will only lead to disappointment, I'm sure. > > > but I understand this is a philosophical point, > > No, it's a strong technical point. To pick one value, that distinguished > value has to be well-defined (that is, there has to be a natural, > unambiguous meaning of which value to pick, for all possible > circumstances). This isn't the case here. > > Your trust is welcome (and, I'm sure, well-placed). But realise that > this isn't simply an arbitrary opinion. It's a technical constraint. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: distinct doesn't work after sorting by reverse foreign key
I guess what I'm imagining is that distinct() would take the current queryset, go from the top, and keep the first occurrence of each distinct object in that set (users don't care about SQL rows, that's why they're using django in the first place). Do you think this is NOT what most users would expect from a distinct() function? On Dec 4, 10:22 pm, ryan <[EMAIL PROTECTED]> wrote: > There's no mind reading required. I have a queryset of Blog objects, > not entry objects (or SQL rows for that matter). When I call distinct, > I would expect a "distinct set of blog objects". Call it a strong > technical point if you prefer, but I still feel this is what the > common person would expect. > > On Dec 4, 10:17 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Thu, 2008-12-04 at 20:15 -0800, ryan wrote: > > > thanks for the thorough reply! I now understand how to proceed. > > > > However, I'm not convinced that distinct shouldn't do this for me... > > > It cannot read your mind. How is distinct() meant to know which of the > > many multiple values it should use for ordering? Should it pick one at > > random? That will only lead to disappointment, I'm sure. > > > > but I understand this is a philosophical point, > > > No, it's a strong technical point. To pick one value, that distinguished > > value has to be well-defined (that is, there has to be a natural, > > unambiguous meaning of which value to pick, for all possible > > circumstances). This isn't the case here. > > > Your trust is welcome (and, I'm sure, well-placed). But realise that > > this isn't simply an arbitrary opinion. It's a technical constraint. > > > Regards, > > Malcolm --~--~-~--~~~---~--~~ 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: AlreadyRegistered Exception after newforms-admin merge
Good catch. Thank you On Aug 3, 10:14 pm, "Pedro Valente" <[EMAIL PROTECTED]> wrote: > I'm not sure if it's your case, but I got the AlreadyRegistered errors > because before the merge I used the NFA branch and had an admin import > inside __init__.py (not needed anymore). > > I had forgotten about that, and after I got rid of if my app worked fine. > > Pedro Valente > > On Sun, Aug 3, 2008 at 14:19, Brian Morton <[EMAIL PROTECTED]> wrote: > > > As my original post states, my admin registration calls are all in > > admin.py for each app. No admin declarations or registrations are > > going on in my models. > > > On Aug 3, 5:55 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > The correct way to handle it is to put all your admin stuff inside > > > admin.py for each application and than follow these directions: > >http://www.djangoproject.com/documentation/admin/#hooking-adminsite-i... > > > > On Aug 3, 3:32 am, Ludwig <[EMAIL PROTECTED]> wrote: > > > > > I encountered the same exception -- it is triggered when, assuming your > > > > admin registration takes place in models.py, is imported by something > > else, > > > > e.g. template tags, inclusion into another model. > > > > > A try/except block around the admin registration will suppress this. > > > > > While I consider this an inelegant hack, I am not sufficiently steeped > > in > > > > the logic of the admin registration to say that such multiple > > registration > > > > should or should not trigger an exception. Maybe the developers could > > > > suggest the right pattern for this. > > > > > HTH > > > > > Ludwig > > > > > 2008/8/2 Brian Morton <[EMAIL PROTECTED]> > > > > > > Using revision 8194 from TRUNK (the latest as of writing this post), > > I > > > > > am encountering AlreadyRegistered while starting my application. I > > > > > have all ModelAdmin definitions in admin.py for my two applications. > > > > > App2's models file references the app1's model with an import (like > > in > > > > >http://code.djangoproject.com/ticket/6776). However, I am still > > > > > getting exceptions about each one of my models from app1 being > > already > > > > > registered. If I comment out the admin.site.register lines in > > > > > app1.admin, only about 1/3 of my models appear in the admin. > > > > > > Any ideas what might be causing this? > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
GEOIP_LIBRARY_PATH in settings.py
Is this correct?: GEOIP_LIBRARY_PATH = '/home/USERNAME/geoip/lib/libGeoIP.a' --~--~-~--~~~---~--~~ 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 No module. where is it being called, I don't want it to.
"I do have A feild in my times model named user" Is it a ForeignKey to Django's User model? If so you need to import that at the top of your models.py file -ryan On Oct 17, 3:42 pm, KillaBee <[EMAIL PROTECTED]> wrote: > I keep getting this error that says ViewDoesNotExist: Could not > import intranet.timesheets.views. Error was: No module named User. No > i do not have a User module, I don't want nor need one. How do I find > out Where it is being call at? I got this error today, and I have > been trying to get the users logged in. I do have A feild in my times > model named user, and Have been getting errors about not know what > username is. not sure where it's coming from. > View: Because It is an error in the view I was thinking that it was > in the view.py or a template. no matter want the url or view is bing > used it still comes up. Does that sound like I am looking in the > right spot? > > error http://dpaste.com/85152/ > url http://dpaste.com/85153/ > views http://dpaste.com/85154/ > models http://dpaste.com/85158/ > > Hope you can understand the 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ViewDoesNotExist No module. where is it being called, I don't want it to.
no, i just checked yr code. that's not it. On Oct 17, 5:25 pm, ryan <[EMAIL PROTECTED]> wrote: > "I do have A feild in my times > model named user" > > Is it a ForeignKey to Django's User model? > If so you need to import that at the top of your models.py file > > -ryan > > On Oct 17, 3:42 pm, KillaBee <[EMAIL PROTECTED]> > wrote: > > > I keep getting this error that says ViewDoesNotExist: Could not > > import intranet.timesheets.views. Error was: No module named User. No > > i do not have a User module, I don't want nor need one. How do I find > > out Where it is being call at? I got this error today, and I have > > been trying to get the users logged in. I do have A feild in my times > > model named user, and Have been getting errors about not know what > > username is. not sure where it's coming from. > > View: Because It is an error in the view I was thinking that it was > > in the view.py or a template. no matter want the url or view is bing > > used it still comes up. Does that sound like I am looking in the > > right spot? > > > error http://dpaste.com/85152/ > > url http://dpaste.com/85153/ > > views http://dpaste.com/85154/ > > models http://dpaste.com/85158/ > > > Hope you can understand the 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
upload_to ignored outside of admin?
class Creative(models.Model): creative = models.FileField(upload_to='creative') element = models.ForeignKey(Element) #views.py(1) attachment = request.FILES[attachment_num] element.creative_set.create(creative=attachment) #views.py(2) attachment = request.FILES[attachment_num] Creative.objects.create(creative=attachment,element=new_element) Both of these make an entry in the database 'filename.txt' But doing so from the admin results in 'creative/filename.txt' which is what i want Can anyone spot an error? Do I have to pass upload_to to create function in views.py? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
model subclasses
Let's say I have a Polygon model class Polygon(Models.model): side_length = models.IntegerField() Depending on the view I'm in, I want to calculate the perimeter of the polygons as a square, or as a triangle (or anything other polygon). What I'd like to do is somehow create a subclass of polygon (that doesn't create a new database table), such as a Square or Triangle, and then after I pull a Polygon queryset out of the database, I'd like to cast all the Polygons to either Squares or Triangles, and then I can call the perimeter() method for that object: class Square(Polygon) def perimeter(self): return 3*self.side_length class Meta: abstract=True But what I've ended up doing is added a traingle_perimeter() and a square_perimeter() method to the Polygon object, and it just doesn't seem right. Is there a preferred pythonic / djangoistic way to do 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 -~--~~~~--~~--~--~---
differences in seek method for TemporaryUploadedFile & InMemoryUploadedFile
In the following code, the second loop of "for row in csv_reader:" is empty when dealing with an InMemoryUploadedFile object. Setting FILE_UPLOAD_MAX_MEMORY_SIZE equal to zero forces the use of a TemporaryUploadedFile object and solves the problem. It seems that seek(0) doesn't work with an InMemoryUploadedFile and csv.reader. Anyone know why? if request.method == 'POST': dedupe_csv_form = DedupeCSVForm(request.POST,request.FILES) if dedupe_csv_form.is_valid(): relevant_column = dedupe_csv_form.cleaned_data ['duplicates_column'] csv_file = request.FILES['csv_file'] csv_reader = csv.reader(csv_file) items_in_relevant_column = [] duplicates_in_relevant_column = [] col = int(relevant_column)-1 for row in csv_reader: items_in_relevant_column.append(row[col].strip()) items_in_relevant_column.sort() for (i, item) in enumerate(items_in_relevant_column): if i == 0: continue else: last_item = items_in_relevant_column[i-1] if item == last_item: duplicates_in_relevant_column.append(item) csv_file.seek(0) response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=output.csv' csv_writer = csv.writer(response) for row in csv_reader: item = row[col].strip() if item in duplicates_in_relevant_column: continue else: csv_writer.writerow(row) return response --~--~-~--~~~---~--~~ 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: differences in seek method for TemporaryUploadedFile & InMemoryUploadedFile
answering my own question, i think this has something to do with an exhausted iterator -ryan On Jul 20, 12:39 pm, ryan wrote: > In the following code, the second loop of "for row in csv_reader:" is > empty when dealing with an InMemoryUploadedFile object. Setting > FILE_UPLOAD_MAX_MEMORY_SIZE equal to zero forces the use of a > TemporaryUploadedFile object and solves the problem. It seems that > seek(0) doesn't work with an InMemoryUploadedFile and csv.reader. > Anyone know why? > > if request.method == 'POST': > dedupe_csv_form = DedupeCSVForm(request.POST,request.FILES) > if dedupe_csv_form.is_valid(): > relevant_column = dedupe_csv_form.cleaned_data > ['duplicates_column'] > csv_file = request.FILES['csv_file'] > csv_reader = csv.reader(csv_file) > > items_in_relevant_column = [] > duplicates_in_relevant_column = [] > col = int(relevant_column)-1 > > for row in csv_reader: > items_in_relevant_column.append(row[col].strip()) > items_in_relevant_column.sort() > > for (i, item) in enumerate(items_in_relevant_column): > if i == 0: > continue > else: > last_item = items_in_relevant_column[i-1] > if item == last_item: > duplicates_in_relevant_column.append(item) > csv_file.seek(0) > response = HttpResponse(mimetype='text/csv') > response['Content-Disposition'] = 'attachment; > filename=output.csv' > csv_writer = csv.writer(response) > > for row in csv_reader: > item = row[col].strip() > if item in duplicates_in_relevant_column: > continue > else: > csv_writer.writerow(row) > return response --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django-facebookconnect
Hey folks, I posted code for a facebook connect django app on google code. I refactored code from the News Mixer application to use for another project, and figured it was useful enough that others might want it. http://code.google.com/p/django-facebookconnect/ http://code.google.com/p/newsmixer/ The app is pretty simple, its just built on top of django.contrib.auth and pyfacebook. It works along side django-registration and regular django user accounts. New facebook users can link an existing django user account when they log in or just use a user account that gets automatically generated. News Mixer used the facebook API extensively. So this app handles a lot of the BS headache problems that we ran into working with facebook connect. It uses caching extensively to minimize API calls to facebook, handles session timeouts and a few other things. Check it out, tell me what you think. -- Ryan Mark http://ryan-mark.com 847 691 8271 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
inline model's choices field empty in admin
When I edit a User in the admin, the sales_team and user_class dropdowns are empty. If anyone can point out my error or point me to the django core code that ignores the choices, I would greatly appreciate it. #models.py SALES_TEAM_CHOICES = enumerate(('CLS','CCS','TPS')) USER_CLASS_CHOICES = enumerate(('DOM','DSK','DFA','DTM')) class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) user_class = models.IntegerField(choices=USER_CLASS_CHOICES) #admin.py class UserProfileInline(admin.StackedInline): model = UserProfile max_num = 1 class CustomUserAdmin(UserAdmin): inlines = [UserProfileInline,] admin.site.unregister(User) admin.site.register(User, CustomUserAdmin) --~--~-~--~~~---~--~~ 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: inline model's choices field empty in admin
This additional model, which uses the same choices is emptying the choices dropdown of both User with inline UserProfile and UserProfile itself. Add it prior to UserProfile in models.py of your test app: class Person(models.Model): sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) user_class = models.IntegerField(choices=USER_CLASS_CHOICES) last_name = models.CharField(max_length=40) first_name = models.CharField(max_length=30) This behavior is not mentioned as a caveat in http://docs.djangoproject.com/en/dev/ref/models/fields/#choices ryan On Jun 2, 11:22 am, Karen Tracey wrote: > On Tue, Jun 2, 2009 at 10:59 AM, ryan wrote: > > > When I edit a User in the admin, the sales_team and user_class > > dropdowns are empty. > > > If anyone can point out my error or point me to the django core code > > that ignores the choices, I would greatly appreciate it. > > > [snip code] > > I cannot recreate this with either Django 1.0.2 or current trunk. When I > cut and paste the models/admin defs you show into a test app and then edit a > user in admin, the two profile dropdowns are populated with an empty choice > (all dashes) plus the choices you have specified. There must be something > beyond what you have shown here that is coming into play. > > 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: inline model's choices field empty in admin
Thank you sir. I got this from "Python Web Dev. w/ Django". An unforseen side effect. ryan On Jun 2, 12:05 pm, Daniel Roseman wrote: > On Jun 2, 4:53 pm, ryan wrote: > > > This additional model, which uses the same choices is emptying the > > choices dropdown of both User with inline UserProfile and UserProfile > > itself. Add it prior to UserProfile in models.py of your test app: > > > class Person(models.Model): > > sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) > > user_class = models.IntegerField(choices=USER_CLASS_CHOICES) > > last_name = models.CharField(max_length=40) > > first_name = models.CharField(max_length=30) > > > This behavior is not mentioned as a caveat > > inhttp://docs.djangoproject.com/en/dev/ref/models/fields/#choices > > > ryan > > Because enumerate() is an iterator. So it is consumed the first time > it is run. > > You could call list() on it to flatten it: > SALES_TEAM_CHOICES = list(enumerate(('CLS','CCS','TPS'))) > > I've never heard of anyone doing this, which is presumably why it's > not mentioned in the documentation... > -- > 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-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 -~--~~~~--~~--~--~---
__all__in instead of __in
#models.py class Station(models.Model): station_name = models.CharField(max_length=20) class Order(models.Model): station = models.ManyToManyField(Station, blank=True, null=True) class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) station = models.ManyToManyField(Station, blank=True, null=True) >>> from myapp.models import Station, Order >>> from django.contrib.auth.models import User >>> u = User.objects.get(username__exact='ryan') >>> user_stations = u.get_profile().station.all().values_list('pk', flat=True) >>> user_stations [1L, 2L, 3L] >>> o = Order.objects.filter(station__in=user_stations) >>> o [Too many orders!] Order.objects.filter(station__in=user_stations) returns any order where any of its stations are in user_stations. What I need is only those orders where ALL of its stations are in user_stations. Is there a way to specify __all__in: Order.objects.filter (station__all__in=user_stations) -ryan --~--~-~--~~~---~--~~ 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: __all__in instead of __in
answering my own question, seems like: Order.objects.filter(Q(station=1), Q(station=2), Q(station=3)) -ryan On Jun 4, 2:29 pm, ryan wrote: > #models.py > class Station(models.Model): > station_name = models.CharField(max_length=20) > > class Order(models.Model): > station = models.ManyToManyField(Station, blank=True, null=True) > > class UserProfile(models.Model): > user = models.ForeignKey(User, unique=True) > station = models.ManyToManyField(Station, blank=True, null=True) > > >>> from myapp.models import Station, Order > >>> from django.contrib.auth.models import User > >>> u = User.objects.get(username__exact='ryan') > >>> user_stations = u.get_profile().station.all().values_list('pk', flat=True) > >>> user_stations > [1L, 2L, 3L] > >>> o = Order.objects.filter(station__in=user_stations) > >>> o > > [Too many orders!] > > Order.objects.filter(station__in=user_stations) returns any order > where any of its stations are in user_stations. What I need is only > those orders where ALL of its stations are in user_stations. Is there > a way to specify __all__in: Order.objects.filter > (station__all__in=user_stations) > > -ryan --~--~-~--~~~---~--~~ 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: __all__in instead of __in
actually, you need to do something like this: user_stations = u.get_profile().station.all().values_list('pk', flat=True) excluded_stations = Station.objects.exclude(id__in=user_station_pks) all_terrestrial_active_orders = Order.objects.filter(order_type=0, in_market=True, end_date__gte=today) terrestrial_active_orders = all_terrestrial_active_orders.exclude (station__in=excluded_terrestrial_stations) On Jun 4, 3:05 pm, ryan wrote: > answering my own question, seems like: > > Order.objects.filter(Q(station=1), Q(station=2), Q(station=3)) > > -ryan > > On Jun 4, 2:29 pm, ryan wrote: > > > #models.py > > class Station(models.Model): > > station_name = models.CharField(max_length=20) > > > class Order(models.Model): > > station = models.ManyToManyField(Station, blank=True, null=True) > > > class UserProfile(models.Model): > > user = models.ForeignKey(User, unique=True) > > station = models.ManyToManyField(Station, blank=True, null=True) > > > >>> from myapp.models import Station, Order > > >>> from django.contrib.auth.models import User > > >>> u = User.objects.get(username__exact='ryan') > > >>> user_stations = u.get_profile().station.all().values_list('pk', > > >>> flat=True) > > >>> user_stations > > [1L, 2L, 3L] > > >>> o = Order.objects.filter(station__in=user_stations) > > >>> o > > > [Too many orders!] > > > Order.objects.filter(station__in=user_stations) returns any order > > where any of its stations are in user_stations. What I need is only > > those orders where ALL of its stations are in user_stations. Is there > > a way to specify __all__in: Order.objects.filter > > (station__all__in=user_stations) > > > -ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Handling IntegrityError on transaction middleware commit
I had an IntegrityError come up on transaction commit (using postgres) today on a production site -- trying to insert an invalid foreign key value (an admin deleted something she shouldn't have). The problem was that instead of emailing me the exception like usual, django logged the exception to my apache (using mod_wsgi) error log and then that apache process was semi-broken for about half and hour, refusing to recognize session cookies or log anyone in, but also not throwing up any exceptions either. I realize that I should be validating my data before saving it, but I'll admit I don't guard against every eventuality. My question is, should I be doing something in my code to prevent this kind of poor exception handling, or should I file a bug against django? I would certainly prefer the whole server not to break when the transaction commit fails for whatever reason -- it should rollback the transaction and give a 500 error page. Here's the middleware tuple from my settings.py: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.transaction.TransactionMiddleware', ) Any thoughts? 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.
override TabularInline get_formset - need to call super method?
Hi I'm trying to change the extra value based on a related object's attribute. The relevant bit of code starts with: ## begin alterations This way of doing it works, but should I be calling super() at the end? if so, why? I've been reading up on super a lot. from admin.py class HDChannelInline(admin.TabularInline): model = HDChannel extra = 0 template = 'admin/edit_inline/tabular.html' def get_formset(self, request, obj=None, **kwargs): """Returns a BaseInlineFormSet class for use in admin add/ change views.""" if self.declared_fieldsets: fields = flatten_fieldsets(self.declared_fieldsets) else: fields = None if self.exclude is None: exclude = [] else: exclude = list(self.exclude) defaults = { "form": self.form, "formset": self.formset, "fk_name": self.fk_name, "fields": fields, "exclude": exclude + kwargs.get("exclude", []), "formfield_callback": self.formfield_for_dbfield, "extra": self.extra, "max_num": self.max_num, } ## begin alterations if obj is not None: if obj.asset_type == 'broadcast_radio': defaults['extra'] = 2 ## end alterations defaults.update(kwargs) return inlineformset_factory(self.parent_model, self.model, **defaults) -- 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: override TabularInline get_formset - need to call super method?
would this be preferable? from admin.py class HDChannelInline(admin.TabularInline): model = HDChannel extra = 0 template = 'admin/edit_inline/tabular.html' def get_formset(self, request, obj=None, **kwargs): if obj is not None: if obj.asset_type == 'broadcast_radio': kwargs['extra'] = 2 return super(HDChannelInline, self).get_formset(request, obj, **kwargs) -- 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: Ajax header not sent in all browsers
If you simplify things down to something like the snippets below, does the alert display 'Said it was NOT ajax' for you? It shouldn't (and doesn't for me). Also, do you have the Tamper Data Firefox add-on installed to validate the headers being sent in? That could help narrow things down. urls.py: (r'^isajax/?$', 'some_site.views.is_ajax_worky'), views.py: def is_ajax_worky(request): ajax_header = request.META.get('HTTP_X_REQUESTED_WITH', 'None') if request.is_ajax(): return HttpResponse('Said it WAS ajax. header=' + ajax_header) return HttpResponse('Said it was NOT ajax. header=' + ajax_header) test.html: This test requires javascript! https://ajax.googleapis.com/ajax/ libs/jquery/1.4.2/jquery.min.js"> $(document).ready(function() { $.get('/isajax', function(data) { alert(data); }); }); On Jun 9, 2:14 am, David Escobar wrote: > Hi everyone, > I'm using Django 1.1 with jQuery 1.4.2 and currently testing with the > Django development server. Whenever I send an AJAX request with > $.get(), the HTTP_X_REQUESTED_WITH header only gets sent with Chrome > and Safari. It does not get sent with IE or Firefox. I've verified > this by outputting the request.META keys to a text file for each one. > Needless to say, my AJAX only works correctly with Chrome and Safari. > Also, I'm using request.is_ajax() on the Django side. > > Does anyone know why this might be occurring? Could it be because I'm > testing using the Django development server? It seems to me like this > might be a jQuery issue, but after doing many online searches, I > haven't seen anyone else run into this problem. Every documentation > says that jQuery sends HTTP_X_REQUESTED WITH. > > Thanks in advance. -- 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.
select_related removes broken Foreign Keys, but How?
I noticed this first in the Django Admin. If you have 100 rows in Table A, and 5 of those have a foreign key entry pointing to a nonexistent item in Table B, rather than throwing an error, the admin displays 95. This happens if you set list_select_related = True, or if one of the list_display fields is a ForeignKey. (http://docs.djangoproject.com/en/dev/ref/contrib/admin/ #django.contrib.admin.ModelAdmin.list_select_related) So you can reproduce this by calling select_related. But my question is "How does this happen?". What are the lines of code that remove the 5 rows with broken foreign keys from the queryset? I've been digging through the Django codebase and can't find 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.
Strange cookie error, only for some IE users?
At a client site, I have occasionally had her customers complain that they get cookie errors when they try to log in, even though they have cookies enabled and they are able to log in to other sites. Clearing out their cookies doesn't seem to help. Most (95-99%) users can log in fine. The affected ones seem to be all internet explorer users, but those are the majority of the site's users, so that may just be a coincidence. I had basically dismissed this all as a few funny user browsers malfunctioning, but tonight my client herself got the same error, and was also unable to log in to the django admin, also with a cookie error, so I figure there's actually a real problem somewhere, and it's not just in my code. A few days ago I added the SESSION_COOKIE_DOMAIN setting to "..com" so users would be able to use the same cookie for both the www..com and .com URLs, thinking that might have been part of the problem, but that doesn't seem to have helped. Just now I cleared all the session rows out of the database, to no avail. Any ideas? I'm hosting on webfaction, will post in their forums too. -- 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: Strange cookie error, only for some IE users?
Solved my own problem. User's clocks were set ahead so the Internet Explorer (pinnacle of stupid design) expired the cookie instantly. -- 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 to set individual cache items so they don't timeout?
I found this thread about how a timeout of 0 (= infinite) isn't passed to memcached properly: http://groups.google.com/group/django-developers/browse_thread/thread/a934ec625d35e942 The thread is from July, but the issue still exists in svn, and I couldn't find a ticket for this issue. How do I go about caching an item so it doesn't timeout if I don't want to set the default timeout to zero? Thanks, Ryan -- 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 set individual cache items so they don't timeout?
I'll answer my own question: The way to do this is probably to write your own cache backend that is a wrapper around the django versions so that timeout values of 0 are handled the way you'd like. Johnny Cache does this: http://packages.python.org/johnny-cache/ "The custom backend setting enables a thin wrapper around Django’s memcached (or locmem) cache class that allows cache times of “0”, which memcached interprets as “forever” and locmem is patched to see as forever." Ryan On Nov 24, 2:02 am, Ryan wrote: > I found this thread about how a timeout of 0 (= infinite) isn't passed > to memcached properly: > > http://groups.google.com/group/django-developers/browse_thread/thread... > > The thread is from July, but the issue still exists in svn, and I > couldn't find a ticket for this issue. > > How do I go about caching an item so it doesn't timeout if I don't > want to set the default timeout to zero? > > Thanks, > Ryan -- 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.
Proxy model ContentType question
In django/contrib/contenttypes/models.py (get_for_model), I noticed that for a proxy model object, the contenttype being returned is of the base concrete class since it sets opts to the _meta of proxy_for_model . If one uses a generic relation in the admin app, you can set the generic contenttype to that of a proxy model class. I was just wondering if the contenttype get_for_model call is returning the correct type (concrete base class)? -- 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: Proxy model ContentType question
As an update: Since you can actually assign a generic relation in the admin app to a proxy model object, when using a generic relation, the proxy objects aren't returned because the lookup is using get_for_model which returns an instance of the base class. (I only figured this out after having wrapped the ContentType get_by_natural_key call). I'm wondering what other implications there are if I continue to use the get_by_natural_key as a way to get the proxy content type. On Feb 16, 10:05 pm, Ryan wrote: > In django/contrib/contenttypes/models.py (get_for_model), I noticed > that for a proxy model object, thecontenttypebeing returned is of > the base concrete class since it sets opts to the _meta of > proxy_for_model . If one uses a generic relation in the admin app, > you can set the genericcontenttypeto that of a proxy model class. I > was just wondering if thecontenttypeget_for_model call is returning > the correct type (concrete base class)? -- 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: Is there any way to custom group models in the admin panel?
I am interested in this as well. I've searched for a way to organize models in the admin panel but I haven't found anything. It seems illogical to create multiple apps simply for the fact to separate them in the admin panel. --~--~-~--~~~---~--~~ 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: Best Practices to Make your Apps Portable
I like this setup. I will use this as a basis for my own upcoming project. Thanks. RG On Jul 25, 11:12 am, Sebastian Macias <[EMAIL PROTECTED]> wrote: > Thanks a lot for the feedback everyone. > > I have come up a perfect setup and folder structure (at least > perfect for my needs) that will allow me to work on generic apps and > project specific apps efficiently and just wanted to share it with > everyone in case it can save a anyone a headache. > > *Folder structure for a django project* > > /var/django_root/my_project_name/ > urls.py > settings.py > apps/ > my_project_specific_app_1/ > my_project_specific_app_2/ > my_project_specific_app_3/ > > *Folder structure for generic/portable apps* > > /var/django_root/shared/ > my_generic_portable_app_1/ > my_generic_portable_app_2/ > my_generic_portable_registration_app/ > > *Development Setup* > > I added the following to the top of my_project_name/settings.py so it > appends the portable/generic apps folder to the python path. > > DEVELOPMENT = True > > if DEVELOPMENT: > import sys > sys.path.append('/var/django_root/shared') > > For extended convenience I symlinked my portable/generic apps folder > to my django project so I can quickly make changes to my generic apps > without having to go outside my django project folder structure > > ln -s `pwd`/var/django_root/shared /var/django_root/my_project_name/ > shared > > *Production Setup* > > My Apache conf file: > > > ServerName championsound.local > ServerAlias *.championsound.local > SetHandler python-program > PythonPath "['/var/django_root', '/var/django_root/shared'] + > sys.path" > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE championsound.settings > PythonDebug On > > > Note how '/var/django_root' and '/var/django_root/shared' are added to > the PythonPath > > Enjoy it! > > Sebastian Macias > > On Jul 25, 6:19 am, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote: > > > On 7/24/07, Sebastian Macias <[EMAIL PROTECTED]> wrote: > > > > My dilemma is... what is the point of having projects and apps if the > > > applications created for my project won't be portable in other > > > projects (becase the namespaces will always start with the project > > > name). I can't just copy and app from one project to another. > > > Personally I never use "projects" -- they were just a quick thing we > > made up just before we open-sourced Django, with the thinking being > > "projects" would make it quicker and easier for people to get started. > > They are *not* a good method to use if you want to distribute your > > application, however. > > > We need better documentation about best practices to make apps portable. > > > Adrian > > > -- > > Adrian Holovaty > > holovaty.com | djangoproject.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 -~--~~~~--~~--~--~---
Re: choices/ and getting rid of the dashes?
Use initial when calling your form class. formClass = forms.form_for_model(Person) form = formClass(initial={'gender': 'm'}) On Sep 6, 4:31 pm, Mark Green <[EMAIL PROTECTED]> wrote: > Hi all, > > This is my model: > > class Person(models.Model): > GENDER_CHOICES = ( > ( 'm', 'Male' ), > ( 'f', 'Female' ), > ) > gender = models.CharField( blank=False, "gender", maxlength=1, > choices=GENDER_CHOICES, default='m' ) > > Using form_for_model() on the above model results in HTML like this: > > > - > Male > Female > > > How do I get rid of the first option (the dashes)? > I would prefer to have the -widget default to my default-value. > > Any help appreciated! > > -mark --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Canberra developers
I live in Canberra, Australia and I'm putting together a web start-up, hopefully using the Django framework. Does anyone know of any competent Django developers, or at least Python coders, in my neck of the woods? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Negative numbers comparison bug(?)
Hi, I am currently making a mashup of the Weather Channel's RSS feeds (temperature and wind speed data) and Google maps with Django. Briefly it puts weather data on a map, e.g. sunny in London, rain in Edinburgh. I am having problems with comparing longitudes and latitudes in the database when they are negative. As an example, If I have in the database: locationID=1, lon = 3, lat = -1 If I try to find locations that are within one degree of longitude I believe I would do something like this: Location.objects.filter(lon__range=(2, 4)), this returns the correct locationIDs within 2 and 4 degrees longitudes. However if I do the same for latitude: Location.objects.filter(lat__range=(-3, -1)), it fails. Essentially my problem is I can't filter out database entries when comparing them to negative numbers (always works when positive). Does anyone know it it's a problem with SQL's between syntax or if it's Django? If it helps, the values are floats (decimal 5,2). Could anyone please help me? Thanks in advance, Ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Location of non-app-specific static files?
Hi, I have been wondering where people put their non-app-specific static files in their django projects? For example, the base css file that applies to all pages across the project or perhaps the jquery file? Currently I have the following structure: . ├── app │ ├── __init__.py │ ├── models.py │ ├── static │ │ └── app │ │ ├── css │ │ ├── img │ │ └── js │ ├── templates │ │ └── app │ ├── tests.py │ └── views.py ├── manage.py └── mysite ├── __init__.py ├── settings.py ├── static ├── templates ├── urls.py └── wsgi.py My STATIC_ROOT setting points to the ./mysite/static directory as this is where I would like collectstatic to dump all the static files for deployment, however this is also the obvious place (for me anyway) to place non-app-specific static files as they apply to the project as a whole like the templates directory at this level. Does any one have any input on this? Thanks, Ryan -- 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/-/4H39KqmnTugJ. 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: Location of non-app-specific static files?
That is not a bad idea as everything that is project specific, but not app specific, would live in one place. Thanks, Ryan On Sunday, 4 November 2012 15:14:43 UTC, Xavier Ordoquy wrote: > > Hi, > > One thing I've seen - and adopted - is to have one application that > contains the static files. > It looks like: > > └── mysite > ├── __init__.py > ├── settings.py > > ├── theme > > ├── __init__.py > > ├── models.py (empty file) > > └── static > > ├── static > ├── templates > ├── urls.py > └── wsgi.py > > > Then you add the application in your INSTALLED_APPS and you're done. > > Regards, > Xavier Ordoquy, > Linovia. > > Le 4 nov. 2012 à 00:23, Ryan > a écrit > : > > Hi, > > I have been wondering where people put their non-app-specific static files > in their django projects? For example, the base css file that applies to > all pages across the project or perhaps the jquery file? > > Currently I have the following structure: > > . > ├── app > │ ├── __init__.py > │ ├── models.py > │ ├── static > │ │ └── app > │ │ ├── css > │ │ ├── img > │ │ └── js > │ ├── templates > │ │ └── app > │ ├── tests.py > │ └── views.py > ├── manage.py > └── mysite > ├── __init__.py > ├── settings.py > ├── static > ├── templates > ├── urls.py > └── wsgi.py > > My STATIC_ROOT setting points to the ./mysite/static directory as this is > where I would like collectstatic to dump all the static files for > deployment, however this is also the obvious place (for me anyway) to place > non-app-specific static files as they apply to the project as a whole like > the templates directory at this level. > > Does any one have any input on this? > > Thanks, > > Ryan > > -- > 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/-/4H39KqmnTugJ. > To post to this group, send email to django...@googlegroups.com > . > To unsubscribe from this group, send email to > django-users...@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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/v0gcHJaIbLcJ. 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.
Editing .po files for RTL languages
I'm needing to translate several Django sites/apps into arabic (a Right-To-Left language) and I'm having difficulty editing the .po files when the message to translate contains Left-To-Right variables or HTML markup. Whether I'm using TextMate, TextWrangler or poedit, if I'm editing a translation it correctly has the text RTL, but it also turns any variables/markup RTL when it needs to stay LTR. For example, I get this: verbose_name)s)% تم تحديثه بنجاح. When it needs to be this: %(verbose_name)s تم تحديثه بنجاح. Similar problem if I need to do something like have a or tag around a piece of text in the translation file. As I type the LTR HTML tags in the RTL text it tries to make the tags RTL too. It looks like Django's arabic translation file [1] has variables LTR, so I'm curious what editor the Django arabic translators are using, what fixes I need for poedit or what I'm doing wrong when I edit. >From Googling around, I did see a poedit issue logged a few years ago [2], but they said it's a native control issue, which might explain why I see this same behavior in every Mac OS X editor I've tried thus far. [1] http://code.djangoproject.com/svn/django/trunk/django/conf/locale/ar/LC_MESSAGES/django.po [2] http://www.poedit.net/trac/ticket/296 -- 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.
South African Django Developers
Are there any Django developers in Johannesburg, South Africa? If so, who can I get in touch with? 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.
Django admin and jQuery select filtering
Hi, First of all I will start by saying that I am fairly new to django, jQuery and javascript, but have been using python for a number of years now. In order to get to know django, I thought I would try to develop a ladder application to display player rankings for my local squash club. As part of this I wanted to add some ajax to some of my forms in the django admin in order to dynamically filter some of the options in a select box depending on the users selection in the previous box. For example, when adding a new player to a ladder, it makes little sense to allow the user to select a player who is already a member of that ladder. In order to do this, I have created a new model form as shown here: http://pastebin.com/y2uZxmnF. I then wrote the following javascript (selectfilter.js): http://pastebin.com/vyHXzMH2. Finally I wrote a view to select the required objects: http://pastebin.com/D2JVNHxS. This works great, however, I need to use the same kind of functionality on other forms, but there is a lot hardcoded in to the javascript file and view so would require a new javascript file for each new form. So I was wondering if there was a good way to make this more dynamic so the same code could be used for most (if not all) forms? Any help would be greatly appreciated. Many thanks, Ryan -- 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: choice_set.all()
Can you post your model code please? -- 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: Form and ForeignKey Limiting
Could you not change the queryset of the ModelChoiceField in the view? That way you will have access to the current user from request.user. -- 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: Auditing Record Changes in All Admin Tables
This will show you how to achieve this in the django admin: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_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-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 dynamic form simple Example
I do not know the details of implementing this, however I do know that the approach you are trying to take is incorrect. It is not generally a good idea to dynamically change the definition of a form like that. What I suggest is that you use formsets<https://docs.djangoproject.com/en/1.3/topics/forms/formsets/>to display multiple instances of the same form. So for example, if you changed your form definition to: class testform(forms.Form): Q = forms.CharField() You could then create a formset like so: from django.forms.formsets import formset_factory formset = formset_factory(testform, extra=2) Once displayed in the template, this would show two instances of the form giving you the two fields you require. You could then either change the extra attribute in the view if you know how many fields you require, or you could use the django-dynamic-formset<http://code.google.com/p/django-dynamic-formset/>jQuery plugin in order to allow the user to add or remove more forms dynamically. Hope this helps, Ryan -- 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: Form and ForeignKey Limiting
Yes it is possible, but I think I may have misunderstood you at first. All you want to do is to force the user who created the task to become its manager? If so you can do this very simply in the django admin using this code: https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model. Just make sure you set editable=False in your model definition for manager in the Task model. Ryan -- 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: custom User class
If all you want to do is store additional information about your users, the recommended way to do this is to use a user profile: https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users Ryan -- 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: Form and ForeignKey Limiting
You could always try this: class TaskForm(models.ModelForm): class Meta: model = Task def __init__(self, queryset, *args, **kwargs): super(TaskForm, self).__init__(*args, **kwargs) self.fields['manager'].queryset = queryset and then just pass the required queryset when you create the form instance in your view. Ryan -- 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 - UserProfile m2m field in admin - error
I can confirm that I get the same error. I wonder if it is anything to do with the two different forms auth uses for user creation and change? On a side note, how did you get your code so nicely formatted? Ryan -- 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: Auditing Record Changes in All Admin Tables
That code is supposed to go in the models admin definition like so: admin.py: -- class AuditAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.user = request.user obj.save() Ryan -- 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: Auditing Record Changes in All Admin Tables
The model code still needs to stay in the model, it is just the save_model method had to be moved to the admin.py. I think the following is what you are looking for: models.py --- from django.db import models from django.contrib.auth.models import User class AuditedTable(models.Model): created = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey(User, editable=False) updated = models.DateTimeField(auto_now=True) updated_by = models.ForeignKey(User, editable=False) class Meta: abstract = True class Entity1(AuditedTable): title = models.CharField(max_length=20) def __unicode__(self): return self.title admin.py - from django.contrib import admin from app.models import Entity1 class AuditAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): if change: obj.updated_by = request.user else: obj.created_by = request.user obj.save() class Entity1Admin(AuditAdmin): pass admin.site.register(Entity1, Entity1Admin) Hope that helps, Ryan -- 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/-/NV9uTUJxUVRkTW9K. 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: Auditing Record Changes in All Admin Tables
That bit is the easy bit :p Just change request.user to request.user.username Ryan -- 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/-/RXpUd1BTX2E3RVVK. 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.
column cannot be null
blank = True means that a django form will not require a value, but the database still does so it's expected that you provide a value elsewhere. In order to allow a null entry into the database, you will need to add null = True to that definition aswell Hope this helps, Ryan -- 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/-/WFcxX2R4ZFB1VW9K. 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: Auditing Record Changes in All Admin Tables
No problem. One final piece of advice would be to move the readonly_fields out of Entity1Admin and into AuditAdmin. That way you only have to define it once and inherit from it as with all the other options rather than re-defining it for each new model. Ryan -- 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/-/RDk4VnBBdU1mck1K. 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: confused over use of XYZ.objects.get() method
Right, if what you have typed in your post is the code you are actually trying to use, there are two problems that jump out at me. The first is that *question = models.CaaQuestion(pk=210) *will actually create a new question with the primary key 210, not fetch one from the database, so when you try to use this to find answers in the subsequent lines it will not find anything as it is not currently in any of those tables. The second if the FieldError you are receiving. This is because the question_id and assessment_id arguments should have double underscores to tell django that you are trying to span a relationship. So these two should actually be question__id and assessment__id. However the line above that with question = question and assessment = assessment should work fine when you have a question that is actually in the database. Hope that helps you, Ryan -- 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/-/VHF3WmMyZVVCSVlK. 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: ManyToManyField limit_choices_to that instance via Django admin.
This is possible, but I'm not sure if you could do it via limit_choices_to. The admin docs shows how to accomplish this here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_manytomany Ryan -- 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/-/ZlhkM0JHY3dkbTRK. 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: VERY cheap django hosting?
Do you know how their python is provided? mod_python? mod_wsgi? fgci? Thanks, Ryan -- 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/-/6KIjlspcjIwJ. 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.
migrate command fails with foreign key to user model
I have used django in the past, but not for some time. So the changes surrounding the user models are new to me. I downloaded v1.7b2 and proceeded to start a new development I am planning. However I came across a problem when trying to run migrate after generating the migrations on an app that has a model that contains a foreign key to the user model. So I created a simple test app to isolate the problem, with a model defined as below: from django.db import models from django.conf import settings class TestModel(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) When I run "makemigrations test_app" the migrations seem to be created fine as there are no errors produced. However when I run "migrate" I get the folllowing errors: C:\Users\osborn_r\django\test_project>python manage.py migrate Operations to perform: Synchronize unmigrated apps: admin, contenttypes, auth, sessions Apply all migrations: test_app, auth Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: Applying test_app.0001_initial...Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 427, in execute_from_command_line utility.execute() File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 337, in execute output = self.handle(*args, **options) File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py ", line 145, in handle executor.migrate(targets, plan, fake=options.get("fake", False)) File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 60 , in migrate self.apply_migration(migration, fake=fake) File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 88 , in apply_migration if self.detect_soft_applied(migration): File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 13 2, in detect_soft_applied apps = project_state.render() File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 63, i n render model=dangling_lookup[0])) ValueError: Lookup failed for model referenced by field auth.Permission.content_ type: contenttypes.ContentType Can anyone spot what I have done wrong? -- 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/f38bf94b-da37-4b2e-8722-a3263b12442d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: migrate command fails with foreign key to user model
Thanks for the info. At least I now know it wasn't anything I was doing wrong! On Monday, 28 April 2014 17:54:29 UTC+1, Simon Charette wrote: > > This is a release blocker for Django 1.7 which is being tracked in > #22485<https://code.djangoproject.com/ticket/22485> > . > > Le lundi 28 avril 2014 04:54:32 UTC-4, Ryan a écrit : >> >> I have used django in the past, but not for some time. So the changes >> surrounding the user models are new to me. I downloaded v1.7b2 and >> proceeded to start a new development I am planning. However I came across >> a problem when trying to run migrate after generating the migrations on an >> app that has a model that contains a foreign key to the user model. So I >> created a simple test app to isolate the problem, with a model defined as >> below: >> >> from django.db import models >> from django.conf import settings >> >> class TestModel(models.Model): >> user = models.ForeignKey(settings.AUTH_USER_MODEL) >> >> When I run "makemigrations test_app" the migrations seem to be created >> fine as there are no errors produced. However when I run "migrate" I get >> the folllowing errors: >> >> C:\Users\osborn_r\django\test_project>python manage.py migrate >> Operations to perform: >> Synchronize unmigrated apps: admin, contenttypes, auth, sessions >> Apply all migrations: test_app, auth >> Synchronizing apps without migrations: >> Creating tables... >> Installing custom SQL... >> Installing indexes... >> Running migrations: >> Applying test_app.0001_initial...Traceback (most recent call last): >> File "manage.py", line 10, in >> execute_from_command_line(sys.argv) >> File >> "C:\Python27\lib\site-packages\django\core\management\__init__.py", line >> 427, in execute_from_command_line >> utility.execute() >> File >> "C:\Python27\lib\site-packages\django\core\management\__init__.py", line >> 419, in execute >> self.fetch_command(subcommand).run_from_argv(self.argv) >> File "C:\Python27\lib\site-packages\django\core\management\base.py", >> line 288, >> in run_from_argv >> self.execute(*args, **options.__dict__) >> File "C:\Python27\lib\site-packages\django\core\management\base.py", >> line 337, >> in execute >> output = self.handle(*args, **options) >> File >> "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py >> ", line 145, in handle >> executor.migrate(targets, plan, fake=options.get("fake", False)) >> File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", >> line 60 >> , in migrate >> self.apply_migration(migration, fake=fake) >> File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", >> line 88 >> , in apply_migration >> if self.detect_soft_applied(migration): >> File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", >> line 13 >> 2, in detect_soft_applied >> apps = project_state.render() >> File "C:\Python27\lib\site-packages\django\db\migrations\state.py", >> line 63, i >> n render >> model=dangling_lookup[0])) >> ValueError: Lookup failed for model referenced by field >> auth.Permission.content_ >> type: contenttypes.ContentType >> >> Can anyone spot what I have done wrong? >> > -- 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/d3b85387-1c06-4f48-876c-0f6a75bbb4d6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Syncing two django applications via cURL
You could create a view that accepts a post that includes the following: * admin username (for auth) * admin password (for auth) * username * user password * other attrs... Then from your admin hooks, you can do an http post to the other sites using httplib[1] keeping stuff in sync. 1. http://www.python.org/doc/2.5.2/lib/httplib-examples.html - Ryan On Thu, Nov 13, 2008 at 10:13:25AM -0800, Kurczak wrote: > > Hello everyone, > I've got this unusual problem - I've got few django sites, and I need > to synchronize Users and profiles between them. (it's a closed site > where only admins create accounts so OpenID or similar won't help) I > thought that probably the easiest way is to hook somewhere in admin > interface (add, edit, delete actions) and run a cURL script that would > log in to the rest of the sites as another user and execute same > action. (I hope my description is understandable) > Is it by any chance a good solution? If so, where is the best place to > hook this? > > I'd be profoundly grateful for any insights on this. > > Thanks, > Kurczak > > > > --~--~-~--~~~---~--~~ 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: FastCGI and Django as a continuously running server
On Wed, Nov 05, 2008 at 11:21:14AM -0800, russellneufeld wrote: > The one thing left that I'd like to do is set up Django to run > continuously, even when there are no http requests. My application > runs a bunch of periodic background tasks in addition to serving up > web content, and it seems that after a few minutes with no web > activity, the app is terminated. I'm coming from the java world where > you typically have one long-running jvm which handles all requests and > does not start and stop with new Apache instances. I'd like to set up > something similar with Django. With Django all state is in the database(unless you've setup cookies). There's no guaranteed persistent process. You'll need to use whatever periodic scheduler Dreamhost gives you (cron, other?) to run your background tasks as separate python scripts. Here's an example: #!/usr/bin/python import sys # This is my django model that I want to do something with from mfg.bundle.models import Bundle try: bundles = Bundle.objects.all() for bundle in bundles: bundle.do_something() except: print "Something went crazy wrong!" sys.exit(1) sys.exit(0) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to create a form with dynamic number of fields?
I've recently had a situation where I needed to create dynamic forms and corresponding code to handle them. One thing that you should know about python is that there's nothing special about classes, you can take a collection of attributes and methods and use them to create a new class on-the-fly using python's type() function. You can use this to dynamically build a form class with a new field. My roommate wrote a great blog post on how to do build classes dynamically (http://askawizard.blogspot.com/2008/09/metaclasses-python- saga-part-4_30.html), which you should read before attempting this. Once you understand what that is talking about (or not), you end up writing some code like this: If you want this form to be dynamic: class MyDynamicForm(Form): foo = CharField(max_len = 100) bar = IntegerField() def clean_foo(self): value = self.cleaned_data['foo'] if value != 'foo': raise ValidationError('foo is not foo!') def clean_bar(self): value = self.cleaned_data['bar'] if value != 42: raise ValidationError('wrong answer') You could build it programatically with: # Our base classes (which you could build programatically if you wanted) bases = (Form,) # Our class attributes attys = { 'foo' : CharField(max_len = 100), 'bar' : IntegerField(), } # This returns a clean method built from some parameters def general_clean(name, correct_value, error_text): def inner(self): value = self.cleaned_data[name] if value != correct_value: raise ValidationError(error_text) return inner # Now add the clean methods. You could just define methods and assign, but this illustrates generating them programatically. for name, correct_value, error_text in ( ('foo', 'foo', 'foo is not foo!'), ('bar', 42, 'wrong answer'), ): attys['clean_' + name] = general_clean(name, correct_value, error_text) # Now, to create the dynamic class, you need the following incantation: DynamicForm = getattr(Form, '__metaclass__', type)('DynamicForm', bases, attys) # That only creates the *class*, we still have to create an instance form = DynamicForm({'foo': 'foo', 'bar': 42}) Does this help? It would let you dynamically add elements and handlers to the form that django is aware of, thus you get all the benefits of using the form framework. Let me know if this is a bit thick and I'll be happy to explain it and perhaps blog a more coherent example. --Ryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to create a form with dynamic number of fields?
I've recently had a situation where I needed to create dynamic forms and corresponding code to handle them. One thing that you should know about python is that there's nothing special about classes, you can take a collection of attributes and methods and use them to create a new class on-the-fly using python's type() function. You can use this to dynamically build a form class with a new field. My roommate wrote a great blog post on how to do build classes dynamically (http://askawizard.blogspot.com/2008/09/metaclasses-python- saga-part-4_30.html), which you should read before attempting this. Once you understand what that is talking about (or not), you end up writing some code like this: If you want this form to be dynamic: class MyDynamicForm(Form): foo = CharField(max_len = 100) bar = IntegerField() def clean_foo(self): value = self.cleaned_data['foo'] if value != 'foo': raise ValidationError('foo is not foo!') def clean_bar(self): value = self.cleaned_data['bar'] if value != 42: raise ValidationError('wrong answer') You could build it programatically with: # Our base classes (which you could build programatically if you wanted) bases = (Form,) # Our class attributes attys = { 'foo' : CharField(max_len = 100), 'bar' : IntegerField(), } # This returns a clean method built from some parameters def general_clean(name, correct_value, error_text): def inner(self): value = self.cleaned_data[name] if value != correct_value: raise ValidationError(error_text) return inner # Now add the clean methods. You could just define methods and assign, but this illustrates generating them programatically. for name, correct_value, error_text in ( ('foo', 'foo', 'foo is not foo!'), ('bar', 42, 'wrong answer'), ): attys['clean_' + name] = general_clean(name, correct_value, error_text) # Now, to create the dynamic class, you need the following incantation: DynamicForm = getattr(Form, '__metaclass__', type)('DynamicForm', bases, attys) # That only creates the *class*, we still have to create an instance form = DynamicForm({'foo': 'foo', 'bar': 42}) Does this help? It would let you dynamically add elements and handlers to the form that django is aware of, thus you get all the benefits of using the form framework. Let me know if this is a bit thick and I'll be happy to explain it and perhaps blog a more coherent example. --Ryan --~--~-~--~~~---~--~~ 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 processes under Apache
> Based on my experiments, it does seem like each Apache process > maintains a live Django object which it reuses request after request > and which maintains state such as global variables in modules between > requests. Does that mean that a Django instance has some kind of loop > in it that waits for requests and then creates responses? The wait loop is inside Apache - Django just exports a funtion which Apache calls for every request, e.g. the "handler" function in core/handlers/modpython.py > The slave script that gets called with subprocess.Popen uses > fcntl.flock to lock onto an arbitrary file while it's working. A > middleware looks for tasks that need to be completed on every response > and if work needs to be done, quickly tries to get a lock on the lock > file in a non-blocking way, and if it can, it releases the lock and > uses Popen to start the slave. Since the task files are numbered, they > form a sort of queue. The point of all this is to generate thumbnails > and not wait around for it. You might get some mileage out of the multiprocessing module, which has proper lock and queue objects. Although not available natively in python 2.5, it can be installed as a stand-alone package. This way you could spawn a single worker process (or pool of processes) for each django instance, and have your middleware simply push tasks onto a queue for them to handle. It also lets you specify your worker processes as "daemonic" so they're cleaned up automatically when Django exits. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
model inheritance without a new database table
Hi All, I'm currently working on an authentication backend that adds some functionality to the standard one, and as part of this I want to modify the behaviour of the User class. I've been subclassing auth.models.User using standard model inheritance and it seems to be working fine. However, I don't need to add any fields to the User class, just add/modify some methods. It seems like a waste to have an additional database table created for my model subclass when it won't contain any useful information. I briefly toyed with the idea of just monkey-patching the User class, but figured there must be a better way :-) So, is there a way to have a model subclass avoid the creation of a new database table,and just take its data straight out of the table for its superclass? Thanks, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: model inheritance without a new database table
> There's a ticket open in Trac (my internet connection is terrible at the > moment, so I'm not going to hunt it out) that is to add an option to the > Meta class saying "this model is not to be managed by Django". Thanks Malcolm, I'll definitely take a look and see if I can help out on the ticket at all. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: model inheritance without a new database table
> > is there a way to have a model subclass avoid the creation of a > > new database table,and just take its data straight out of the table for > > its superclass? > > Right now, I suspect you would also have to manually set Meta.db_table > and some things like that. However, I strongly suspect each of those are > fairly straightforward to sort out. We can set db_table automatically > for such models, if it's not set. We have to make sure the pk property > talks to the first ancestor model, too. Basically a bunch of fiddly > stuff, but nothing that's brain surgery levels of difficulty. Following Malcolm's tips, I have managed to get this working. After applying the patch from ticket #3163, I've formulated this class decorator to make the necessary tweaks to the model's meta info: def virtual_inheritance(cls): base = cls.__bases__[0] pk = base._meta.pk # don't create a new db table cls._meta.managed = False # use the superclass table name cls._meta.db_table = base._meta.db_table # remove the auto-created parent reference cls._meta.local_fields[:] = [] # use the superclass primary key cls._meta.pk = pk cls._meta.parents[base] = pk Now I can do the following: class MyUser(auth.models.User): def an_extra_method(self): print "hooray!" virtual_inheritance(MyUser) The resulting model behaves exactly as I wanted, adding functionality to the default User model but taking its data straight out of the auth_user table. If I'm feeling inspired tomorrow, I might try to formulate similar logic as a patch to the ModelBase metaclass, so that subclasses that don't add any fields will get pure-python inheritance by default. In the meantime, I hope some other people might find this trick useful. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: model inheritance without a new database table
> > If I'm feeling inspired tomorrow, I might try to formulate similar logic > > as a patch to the ModelBase metaclass, so that subclasses that don't add > > any fields will get pure-python inheritance by default. > > That (changing the default behaviour) would be a bad idea. The > implicit primary key field shouldn't just magically not appear because > something else isn't there. Indeed - and on further reflection it seems that what I want is a little different from normal subclassing anyway. Standard subclasses require only that all instances of the subclass are also instances of the base class. In this case, I'm trying to make all instances of the base class automatically be available as instances of the subclass. I wonder if there's a standard terminology for this - I'm calling them "virtual subclasses" but maybe they should be called "facade subclasses" or something like that? > The good news, though, is that I suspect a patch to ModelBase will be > a bit simpler than your decorator, since we can just conditionally > check _meta.managed to determine whether to add things like the > auto-fields and the links back to the parent. Yep, getting a patch working for this was pretty straightforward. However, I think it would be better to use a distinct option instead of overloading "managed", since it would be quite legitimate for someone to want an unmanaged subclass that still lived in its own (manually created) database table. My current patch uses "virtual", so I can do the following: def MyUser(auth.models.User): class Meta: virtual = True def an_extra_method(self): print "hooray!" What do you think? I intend to pretty this up and submit a patch sometime this evening. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: model inheritance without a new database table
> Oh, okay. Yeah, that's quite different. I'm not convinced that should go > into Django. Again, there's a consistency thing: we present the object / > class type that is asked for, not some transparently descended version. I think my explanation may have been a bit off... > The use-case for the pure-Python inheritance that has been floating > around is the case when you want to, say, use a different User manager > in your own views. You don't want to change the auth app's behaviour in, > say, admin, but you'd prefer a different default when you're using it. > So you subclass User, using Python-only inheritance, add a new default > manager and then actually use the subclass, rather than User in your > code. because this sounds like exactly how I want to use this feature. I subclass auth.User and add my own managers/methods/etc, and use this subclass in my own code. But if someone creates a new instance of auth.User via the standard class, it should also show up in queries posed through my subclass. Likewise, if I add a new user through my special subclass, it will show up as an ordinary user to e.g. the admin interface. So I'm not trying to add anything magical - the "virtual subclass" is simply a "facade" or "wrapper" around the data in the base class table that presents a modified interface. Yikes, there's that naming problem again... > Still, I wouldn't let that hold things up. I'll think about it and come > up with a name later on, unless a better option appears beforehand. Originally I named it "use_superclass_table" but decided that was just too ugly to deal with. "interface_only"? Glad not to be the one stuck making that decision :-) Thanks for all your feedback, I'll get some code into trac tonight. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: model inheritance without a new database table
Thanks again for your feedback on this Malcolm, I've created the following ticket in Trac: Proxy models: subclass a model without creating a new table http://code.djangoproject.com/ticket/10356 Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: Browser Testing - Selenium or Windmill
> What's the best tool for doing automated browser testing with Django > apps? I have some personal experience with Selenium (although not when > testing Django), which seems fairly mature, and has a great Firefox > extension, but has some serious problems dealing with frames and > popups. I recently discovered Windmill, but haven't heard too much > about it. I don't know about "best", but I've had good experiences using Windmill. It ships with a "WindmillDjangoUnitTest" class for easy integration with the Django testrunner, and it's straightforward to write your testcases in Python using a style quite similar to the native Django test client. Whether it handles frames and popups in the way you want, I have no idea. On the other hand, I think the docs and other community resources available for Selenium are more comprehensive than for Windmill - probably because the latter is a younger project. In the end I went with Windmill because it seemed to fit my development/thinking style better than Selenium - so of course your mileage may vary. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Possible bug with DateTimeFields and admin site
Hello, I thought I would check here first to see if what I am experiencing is, in fact, a bug (using Django 1.0.2). The admin site JavaScript, when creating a new instance of a model with a DateTimeField, attempts to focus on an element that does not exist. Take this example: class Reservation(models.Model): start_date = models.DateTimeField(blank=False, null=False) This results in the use of the AdminSplitDateTime widget being used. The two respective HTML fields have IDs of "id_start_date_0" and "id_start_date_1". However, the JavaScript that is generated is: document.getElementById("id_start_date").focus(); This fails, due to there not being an element on the page with an ID of "id_start_date". I tracked this down to the _auto_id method within the BoundField class. Creating the "auto_id" depends on the field's "html_name" -- in the case outlined above, both fields have html_name's of "start_date". Is this a bug? Cheers, Ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Flatpages-like application and caching
Greetings, I am designing an application that is very simple like flatpages but I need the ability to associate a menu with the content which will be done through the URL (i.e. example.com/products/widget2009 would invoke the products menu and the widget2009 static page). I expect these pages to change rarely but I would still like my client to have the ability to modify menus and and page content. My question is in the Menu model I plan on writing. I want to possibly use signals to create an XHTML document that is the menu code instead. This is basically my simple version of caching instead of dynamically creating the menu upon each access. I'm not really sure if that is true because I don't really know how the cache system works in Django. Is the manager smart enough to where if I created a MenuModel.generate_xhtml() menu which plucked links associated with the menu from the database to create the XHTML, what is the best method to cache this resulting XHTML. Are there any applications that already exist that extend flatpages to include one level deep sub navigation? any help is greatly appreciated! Cheers, Ryan Kaskel http://consulting.ryankaskel.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Checking if a ForeignKey field is NULL
Lets say I retrieve from my database an object foo and foo's model has a ForeignKey field, baz, with null and blank set to True. Will a simple test like if foo.baz ... test whether the field is set to NULL or not? Cheers, Ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django and its caching system help
Greetings, I am designing an application that includes a menu with a many to many relationship with links. These menus will hardly ever change. What is the best way to cache these pages? Should I use the messaging system to create an html file to use when the menu is changed? Is database access quicker than disk access? Do I even need to do this considering Django has a cache system? Any help would be greatly appreciated. Cheers, Ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Circular imports problem
I am creating an application that uses the dispatcher in Django. In the apps models.py file I connect the post_save of two models to functions in a signals.py file. The problem is that I need to use several models in models.py and that leads to a circular import. What is the best way to solve this problem? Cheers, Ryan --~--~-~--~~~---~--~~ 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: Circular imports problem
Well all of the models are part of the same application. So here is the code: models.py: from django.db import models from django.db.models import signlas from django.dispatch import disaptacher from asqcom.apps.staticpages import signals from asqcom.abstract_models import CommonAbstractModel class Link(CommonAbstractModel): url = models.CharField(max_length=1024) title = models.CharField(max_length=64) text = models.CharField(max_length=64) class Meta: verbose_name = 'static page' verbose_name_plural = 'static pages' ordering = ('url',) def __unicode__(self): return u"%s - %s" (self.text, self.url,) class Menu(CommonAbstractModel): name = models.CharField(max_length=64) title = models.CharField(max_length=64) # used in the links = models.ManyToManyField(Link) class Meta: verbose_name = 'menu' verbose_name_plural = 'menus' ordering = ('name',) def __unicode__(self): return u"%s" % (self.name) def to_xhtml(self): pass class StaticPage(CommonAbstractModel): url = models.CharField(max_length=128, db_index=True) title = models.CharField(max_length=256) content = models.TextField(blank=True) menu = models.ForeignKey(Menu, null=True, blank=True) template_name = models.CharField(max_length=70, blank=True) registration_required = models.BooleanField() class Meta: verbose_name = 'static page' verbose_name_plural = 'static pages' ordering = ('url',) def __unicode__(self): return "%s - %s (menu: %s)" % (self.title, self.url, self.menu or 'no menu',) class CachedMenuXhtml(CommonAbstractModel): menu = models.ForeignKey(Menu) xhtml = models.TextField() def __unicode__(self): return self.xhtml dispatcher.connect(signals.build_menu_from_link_mod, signal=signals.signals.post_save, sender=Link) dispatcher.connect(signals.build_menu_from_menu_mod, signal=signals.signals.post_save, sender=Menu) signals.py: import threading from asqcom.apps.staticpages.models import Link, Menu, StaticPage from asqcom.apps.staticpages.models import CachedMenuXhtml class GenerateMenuXhtmlByLink(threading.Thread): def __init__(self, instance): self.instance = instance threading.Thread.__init__(self) def run(self): pass class GenerateMenuXhtmlByMenu(threading.Thread): def __init__(self, instance): self.instance = instance threading.Thread.__init__(self) def run(self): pass def build_menu_from_link_mod(... def build_menu_from_menu_mod(.. I hope this better specifies the issue. Should I import these in the run method for each Thread subclass? On Jul 8, 4:47 pm, Alex Gaynor wrote: > On Wed, Jul 8, 2009 at 3:45 PM, Ryan K wrote: > > > I am creating an application that uses the dispatcher in Django. In > > the apps models.py file I connect the post_save of two models to > > functions in a signals.py file. The problem is that I need to use > > several models in models.py and that leads to a circular import. What > > is the best way to solve this problem? > > > Cheers, > > Ryan > > Depending on how you're using these other models you can a) do imports > inside of functions, or > b)http://docs.djangoproject.com/en/dev/ref/models/fields/#lazy-relation > Or both (probably this) > > 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 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Middleware help -- screwing up the admin
I'm getting a very strange error: TypeError at /admin/ object.__new__() takes no parameters I've isolated the problematic code to my middleware for an application I built called staticpages. It uses the same mechanism and so the same middleware as flatpages. This is the code: from django.http import Http404 from django.conf import settings from asqcom.apps.staticpages.views import staticpage class StaticpageFallbackMiddleware(object): def process_response(self, request, response): if response.status_code != 404: return response try: return staticpage(request, request.path_info) # Return the original response if any errors happened. Because this # is a middleware, we can't assume the errors will be caught elsewhere. except Http404: return response except: if settings.DEBUG: raise 'staticpages.middleware error' return response When I comment out this middleware, everything is okay. Below is the traceback: # /usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py in get_response 85. # Apply view middleware 86. for middleware_method in self._view_middleware: 87. response = middleware_method(request, callback, callback_args, callback_kwargs) 88. if response: 89. return response 90. 91. try: 92. response = callback(request, *callback_args, **callback_kwargs) ... 93. except Exception, e: 94. # If the view raised an exception, run it through exception 95. # middleware, and if the exception middleware returns a 96. # response, use that. Otherwise, reraise the exception. 97. for middleware_method in self._exception_middleware: 98. response = middleware_method(request, e) # /usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py in wrapper 185. return update_wrapper(inner, view) 186. 187. def get_urls(self): 188. from django.conf.urls.defaults import patterns, url, include 189. 190. def wrap(view): 191. def wrapper(*args, **kwargs): 192. return self.admin_view(view)(*args, **kwargs) ... 193. return update_wrapper(wrapper, view) 194. 195. # Admin-site-wide views. 196. urlpatterns = patterns('', 197. url(r'^$', 198. wrap(self.index), # /usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py in inner 177. url(r'^my_view/$', self.admin_view(some_view)) 178. ) 179. return urls 180. """ 181. def inner(request, *args, **kwargs): 182. if not self.has_permission(request): 183. return self.login(request) 184. return view(request, *args, **kwargs) ... 185. return update_wrapper(inner, view) 186. 187. def get_urls(self): 188. from django.conf.urls.defaults import patterns, url, include 189. 190. def wrap(view): # /usr/local/lib/python2.6/dist-packages/django/views/decorators/ cache.py in _wrapped_view_func 37. 38. def never_cache(view_func): 39. """ 40. Decorator that adds headers to a response so that it will 41. never be cached. 42. """ 43. def _wrapped_view_func(request, *args, **kwargs): 44. response = view_func(request, *args, **kwargs) ... 45. add_never_cache_headers(response) 46. return response 47. return wraps(view_func)(_wrapped_view_func) # /usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py in index 359. context = { 360. 'title': _('Site administration'), 361. 'app_list': app_list, 362. 'root_path': self.root_path, 363. } 364. context.update(extra_context or {}) 365. return render_to_response(self.index_template or 'admin/ index.html', context, 366. context_instance=template.RequestContext(request) ... 367. ) 368. index = never_cache(index) 369. 370. def display_login_form(self, request, error_message='', extra_context=None): 371. request.session.set_test_cookie() 372. context = { # /usr/local/lib/python2.6/dist-packages/django/template/context.py in __init__ 99. def __init__(self, request, dict=None, processors=None): 100. Context.__init__(self, dict) 101. if processors is None: 102. processors = () 103. else: 104. processors = tuple(processors) 105. for processor in get_standard_processors() + processors: 106. self.update(processor(request)) ... --~--~-~--~~~---~--~~ 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: Middleware help -- screwing up the admin
Please ignore this. I'm an idiot and placed the reference to the middleware in the template_context_processros settings. And so strange errors resulted. Please delete if possible. --~--~-~--~~~---~--~~ 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: Some post_related_objects_save signal or workaround?
Is there any reason you can't create your own signal and put it in the rounds save() method and then just call the parents save? http://docs.djangoproject.com/en/dev/topics/signals/#defining-and-sending-signals Cheers, Ryan On Jul 9, 6:12 am, Eugene Mirotin wrote: > Hello! > > I have a tricky (as seems to me :) problem. > > Consider I have 2 simply related models - a Game and a Round (with FK > to Game). Each has some generic fields like name and description. > Also, the Round has the ordering field (called number) (oh, I can > imagine your sighs =) > They are edited on the single admin page for Game with TabularInline > for game rounds. > > I know about the way to use jQuery for inlines reordering, but this is > not the question. Currently I am exactly interested in the manual > number field filling. > > So what happens when I save the game? First, the game itself is saved > because of the need of the saved FK object for rounds saving, and I > understand it. Then the rounds are saved in order. > At this point due to some reason the rounds' numbers might be any > numbers. But my applications requires them to be exactly the > consequent positive integers starting from 1. > > This could be easily fixed by a simple loop, but it should be done at > the appropriate point - on the per-game basis and _after_ all the > related objects are saved (otherwise nasty bugs with incorrect > ordering are possible). > > So I have to know the moment when all the current game's related > objects are saved. And there is no appropriate standard signal for > this. > Any thoughts? > > Gene --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
post_save signal bug
Hello, I am trying to implement a cache system using the post_save signal. The problem is the code below, a Thread subclass that ends up calling run(), the cache database never runs. It's driving me crazy!!! Is there something going on with the way Django cache's queries which is what I expect? Can I turn this off? This is the Thread subclass code is below. What I am trying to do is implement a staticpages app which is much like flatpages but it adds a menu foreign key to what is basically a flatpage. I am trying to make a cache system whereby when a user saves a link or a menu, the below code rebuilds the XHTML to use in the staticpage Context. Here is a sample run: 1) I am in the admin and change a menu to consist of a title called "Cool Sites 222" and three links 2) post_save runs and here is what is supposed to be saved in the database (a print is called in my code: Menu 2 Cool Sites 222 http://www.google.com/";>Google Inc http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage If I don't change anything in the menu, eventually it gets the right XHTML and prints it 3) The cached XHTML in the database is never changed and still contains the information from its creation. I think this is a bug because the following this code: def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: cm = self.CachedMenuXhtml.objects.filter(menu__exact=menu) if cm[0]: print cm[0].xhtml cm[0].xhtml = xhtml cm[0].save() print cm[0].xhtml print xhtml else: new_cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) new_cm.save() produces... Cool Sites http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage [11/Jul/2009 05:03:47] "POST /admin/staticpages/menu/2/ HTTP/1.1" 302 0 Cool Sites http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage Cool Sites 222 http://www.google.com/";>Google Inc http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage CODE for Thread subclass that post_save signal calls # Signlas for caching of menu XHTML import threading from django.template.loader import get_template from django.template import Context from django.utils.safestring import mark_safe from django.core.exceptions import ObjectDoesNotExist from asqcom.apps.staticpages.settings import STATICPAGE_TEMPLATE, MENU_TEMPLATE from asqcom.apps.staticpages.settings import LINK_TEMPLATE, MENU_CSS_ID class GenerateMenuXhtml(threading.Thread): """ Subclasses a threading.Thread class to generate a menu's XHTML in a separate thread. All Link objects that have this menu associated with it are gathered and combined in an XHTML unordered list. If the sender is of type Link, then all menus associated with that link are iterated through and rebuilt. """ def __init__(self, instance): from asqcom.apps.staticpages.models import Menu, Link, CachedMenuXhtml self.Link = Link self.Menu = Menu self.CachedMenuXhtml = CachedMenuXhtml self.instance = instance self.menus_to_build = [] self.xhtml_for_menus = [] self.menus_for_cache = [] threading.Thread.__init__(self) def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: print menu print xhtml cm = self.CachedMenuXhtml.objects.filter(menu__exact=menu) if cm[0]: cm[0].xhtml = xhtml cm[0].save() else: new_cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) new_cm.save() def cache_menus(self): """ Unpacks the menu objects and the XHTML for that menu and iterates through the list calling _cache_menu which does the real work. """ for pair in self.menus_for_cache: self._cache_menu(pair[0],pair[1]) def _generate_xhtml(self, menu): link_tmpl = get_template(LINK_TEMPLATE or 'staticpages/ link_default.html') menu_tmpl = get_template(MENU_TEMPLATE or 'staticpages/ menu
Re: post_save signal bug
I modified the above _cached_menu method to just create a new object every time (shown below). It only seems to get the links right, a ManyToMay field, after I save it _twice_? Hmmm...how I get the updated many2many table? def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) cm.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 -~--~~~~--~~--~--~---
Does post_save signal need to be in models.py?
I am trying to avoid circular dependency issues between signals.py and models.py. Is there any reason why I can't connect the post_save signal in signals.py itself (the function is connects with would be in the same file? Should I import it in the apps/__init__.py file to ensure the signal is installed? Cheers, Ryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Question regarding post_save signal and ManyToMany field objects
Recently I've been trying to get answers about the post_save signal behavior and perhaps have been asking too much of readers without narrowing down the problem enough myself. So here is my effort to ask a rather straightforward question: The code that connects to the post_save signal, according to the signal docs, is passed three objects and I am only concerned about one: the instance that was saved. Now this instance has a ManyToManyField and what I am finding out according to be debugging is that the instance's ManyToMany field is NOT being updated after save is called. So, for example, when the signal calls the handler (this is being done via the admin interface but it shouldn't matter) and I check instance.manytomanyfield, it does not show the most recent changes. What is the best way to "force" the update of the table so I can get accurate data from the ManyToMany field? Even if I explicitly do something like this: def __init__(self, sender, instance): self.sender = sender self.instance = sender.objects.select_related().get (id=instance.id) What seems like cached data is being when I test: self.instance.manytomanyfield.all() Can anyone help with this behavior? Cheers, Ryan --~--~-~--~~~---~--~~ 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: .views._CheckLogin.__call__ didn't return an HttpResponse object
Are you returning render_to_response in the view? On Jul 14, 6:12 am, alecs wrote: > Hi all :) Can u help me with .views._CheckLogin.__call__ didn't return > an HttpResponse object . I'm trying from my view 'jump' to another > view by calling mail_to_user(request,username,dummy) The > mail_to_user view contains render_to_response and if I simply copy the > contents of mail_to_user into main view everything works OK. But I > think it's better to call another view than to copy a whole conent. > What can be 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: .views._CheckLogin.__call__ didn't return an HttpResponse object
To be a little more explicit, perhaps your view code contains: render_to_response('template.html",{},RequestContextInstance) as opposed to return render_to_response(...) Cheers, Ryan --~--~-~--~~~---~--~~ 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: Question regarding post_save signal and ManyToMany field objects
Yea...it would be so elegant too! Here is a "bug" filing: http://code.djangoproject.com/ticket/5390. It's been open for two years I understand that your really getting what you asked for, just the instance of the model you just saved but to me (and it seems you and a lot of other people), intuition leads people to write code that drives them nuts because its not really "post_transaction." On Jul 14, 4:08 am, Eugene Mirotin wrote: > If I understand right, the problem is that you want the signal after > all related fields are already saved. If so, this is exactly the > problem I have too. > You see, when you have such a relation (and, for example, edit the > parent object with inlined related objects from the admin page, Django > _has to_ save the parent object first, and only then it saves the > related objects (you can verify it by adding print statements to your > save methods or handlers and running the dev server from terminal). > The reason is that when you initially create the object, related > objects have to link to the existing object, so the parent object is > saved before them. > > On Jul 13, 9:27 pm, Ryan K wrote: > > > > > Recently I've been trying to get answers about the post_save signal > > behavior and perhaps have been asking too much of readers without > > narrowing down the problem enough myself. So here is my effort to ask > > a rather straightforward question: > > > The code that connects to the post_save signal, according to the > > signal docs, is passed three objects and I am only concerned about > > one: the instance that was saved. Now this instance has a > > ManyToManyField and what I am finding out according to be debugging is > > that the instance's ManyToMany field is NOT being updated after save > > is called. > > > So, for example, when the signal calls the handler (this is being done > > via the admin interface but it shouldn't matter) and I check > > instance.manytomanyfield, it does not show the most recent changes. > > What is the best way to "force" the update of the table so I can get > > accurate data from the ManyToMany field? Even if I explicitly do > > something like this: > > > def __init__(self, sender, instance): > > self.sender = sender > > self.instance = sender.objects.select_related().get > > (id=instance.id) > > > What seems like cached data is being when I test: > > > self.instance.manytomanyfield.all() > > > Can anyone help with this behavior? > > > Cheers, > > Ryan --~--~-~--~~~---~--~~ 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: .views._CheckLogin.__call__ didn't return an HttpResponse object
I'm not really sure I understand your question but you don't need to jump to another view...you just need to pass the relevant objects to the mailer function and then "return render_to_response(...)." If the mailer function is already in another view, refactor the code and create a non view function that handles mail. Cheers, Ryan On Jul 14, 6:33 am, alecs wrote: > Ok, a simple question: > Are there any possibilities to call from current view another view. > For instance you have a large view and in the middle of it you need to > perform THE SAME actions which are already defined in def foo > (request,username). > Of course, you can copy the contents of foo(request,username) view > into your big view, but I don't think it's a correct 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-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: Object attributes in change_form.html
I'm not sure but try {{ original }} ...here is the code: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py context = { 860 'title': _('Change %s') % force_unicode (opts.verbose_name), 861 'adminform': adminForm, 862 'object_id': object_id, 863 'original': obj, 864 'is_popup': request.REQUEST.has_key('_popup'), 865 'media': mark_safe(media), 866 'inline_admin_formsets': inline_admin_formsets, 867 'errors': helpers.AdminErrorList(form, formsets), 868 'root_path': self.admin_site.root_path, 869 'app_label': opts.app_label, 870 } On Jul 14, 5:37 am, janedenone wrote: > On Jul 13, 10:05 pm, janedenone wrote: > > > > > > > On Jul 13, 6:07 pm, Daniel Roseman wrote: > > > > On Jul 13, 4:02 pm, janedenone wrote: > > > > > Hi, > > > > > I read the documentation on customizing admin templates, but I still > > > > wonder how to access the object attributes in the change_form.html. I > > > > am capable of getting the id using {{ object_id }}: > > > > > {% if change %}{% if not is_popup %} > > > > > > > > > > > class="historylink">{% trans "View Calculation" %} > > > > ... > > > > > but I need to access a couple of other attributes. {{ object_name }} > > > > does not work, nor does {{ object_cottage_name}} for getting a related > > > > object's name. > > > > > Thankful for any hint. > > > > > - Jan > > > > The syntax for looking up attributes - in templates just like in > > > Python - is a dot, not an underscore. So you should use object.name, > > > etc. > > > Many thanks, but that does not work either. > > > - Jan > > PS. I was using {{ object_id }} because this worked in the > object_tools block. "object" does not seem to be the object modified > via change_form.html, though. --~--~-~--~~~---~--~~ 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: Question regarding post_save signal and ManyToMany field objects
Alex, So I have my Menus that contain links and a Link can be in multiple Menus. Are you saying make an explicit model like: class MenuLinks(models.Model): menu = models.ForeignKey(Menu) link = models. ForeignKey(Link) ? Basically what I am doing is making an enhanced flatpages app called staticpages. I want my client to have full control over the page's content, menus associated with a page as well as links in the menu.. Here is my signals.py: http://pastebin.com/m3c333dd If I modify it to use the above table and connect to its post_save signal, is my solution worth it? I use signals to generate an XHTML menu and cache it in my database. I do this in a thread. Someone said don't use threads. What is the consensus on that? Cheers, Ryan On Jul 14, 10:43 am, Alex Gaynor wrote: > On Tue, Jul 14, 2009 at 9:35 AM, Russell Keith-Magee > > > > > > wrote: > > > On Tue, Jul 14, 2009 at 6:27 PM, Ryan K wrote: > > > > Yea...it would be so elegant too! Here is a "bug" filing: > > >http://code.djangoproject.com/ticket/5390. It's been open for two > > > years > > > A little history may help explain why this has been open for so long. > > > Historically (i.e., when dinosaurs roamed the Django source code) > > signals were _very_ expensive - even signals that had no listeners. As > > a result, there was a lot of resistance to adding new signals. Given > > the performance cost, the decision was made to live without m2m > > signals. > > > Just prior to v1.0, the signal framework was updated, which made > > signals much faster. However, in an attempt to actually hit the > > deadline for getting 1.0 out the door, adding new signals wasn't on > > the plan. > > > Adding new signals was discussed as a possible feature for v1.1 (see > > the features page [1]); however, nobody took charge of getting it > > done, and other development priorities took over. The feature deadline > > arrived before anyone got around to implementing (and integrating) the > > change. > > > When the v1.2 development cycle starts, I'm sure this will be back on > > the schedule again. > > > [1]http://code.djangoproject.com/wiki/Version1.1Features > > > Yours, > > Russ Magee %-) > > The best way now to get this feature is to use an intermediary model which > obviously get's its own signals. Additionally I've been working on > refactoring m2ms to always use an intermediary model, thus signals would > always be sent. > > 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 --~--~-~--~~~---~--~~ 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 bug
What I tried to build is stopped by the fact that I am incorrectly assuming that a ManyToMany field is updated at the time Menu.save() is called (or post_save signal handler called in this case). These two methods of customizing what happens after you save an object DO NOT apply to ManyToMany fields because they are not updated yet. The transaction is not complete. I think Django should abstract transactions and allow signals like pre_transaction_finished and post_transaction_finished in addition to the ideas found at the page for this "bug:" http://code.djangoproject.com/ticket/5390. (this post if for anyone searching the topic) On Jul 11, 1:57 am, Ryan K wrote: > I modified the above _cached_menu method to just create a new object > every time (shown below). It only seems to get the links right, a > ManyToMay field, after I save it _twice_? Hmmm...how I get the updated > many2many table? > > def _cache_menu(self, menu, xhtml): > """ > Stores xhtml into the CachedMenuXhtml table where the row's > menu matches > the menu_obj. > """ > if menu and xhtml: > cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) > cm.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: problems with large data
I'm starting to see that I too need to participate in Django sprints to help incorperate the features I want in Django and I think we all should and perhaps you do which is great. This is great software there is still a lot of work to be done. Ryan Kaskel http://consulting.ryankaskel.com/ On Jul 16, 1:29 pm, Petry wrote: > Hi Ian > > I had been looking on django source and I changed some attributes on > base.py file > > see this[1] ticket, it is works fine for me! > > [1]http://code.djangoproject.com/ticket/11487 > > On 16 jul, 13:15, Ian Kelly wrote: > > > On Jul 16, 7:51 am, Petry wrote: > > > > Hello, > > > > I am working on a project where I have to store a large amount of > > > content, (html) in a record from a table, I am using Oracle as the > > > database > > > > What is very strange ... is put a text reasonably small, (around 2000 > > > characters) and it works correctly, save without problems, but > > > doubling this size, this content is saved completely changed. > > > > Initially used with standard and type of field in Oracle Textfield > > > that it generates a type NCLOB, then when i saved it adds various > > > ideograms that believe they are Chinese. changed the type of field to > > > CLOB and now when saved, several questions are stored in text ("??") > > > > About my work environment: Django 1.1 (svn), debian, and Oracle 10g > > > with cx_oracle 4.4.1 > > > Hi Petry, > > > I've heard of similar problems a couple of times > > (seehttp://code.djangoproject.com/ticket/9152), but so far nobody seems to > > want to stick around long enough to figure out what's going on. What > > are the database character set and national character set of your > > database? Is the text you're trying to store str or unicode? If str, > > what encoding is it? > > > You mentioned that it fails around 4000 characters. Does it fail just > > in the 2001-4000 character range, just in the 4001+ character range, > > or both? > > > Thanks, > > Ian > > --~--~-~--~~~---~--~~ 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: Checking if user is logged in and log in form
> urlpatterns = patterns('', > (r'^someurl/', login_required(direct_to_template), { 'template': > 'template.html', }), > ) http://groups.google.com/group/django-users/browse_thread/thread/e9f85ce0666da8c/ Cheers, Ryan http://consulting.ryankaskel.com On Jul 19, 5:31 pm, AKK wrote: > Hi, i have a login form using the generic view like so: > > (r'^accounts/login/$', 'django.contrib.auth.views.login', > {'template_name': 'blogSite/login.html'}), > > but i only want the form to show up if your not logged in, but since > its is a generic view how can i use > > if not request.user.is_authenticated(): > > as well as the view and also pass the template name. > > 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: Checking a User in another Table ...
What exactly are your models? If you are using a ManyToMany fields you could do it Rating.objects.get(user=request.user) and see if that returns anything. Cheers, Ryan On Jul 19, 10:06 am, The Danny Bos wrote: > Hey there, this should be easy, but my code just won't play along. > > I've let a logged in user Rate a music record. I'm saving it like so > 'rating | user | record'. (Rating model) > What I need to do is only display the Rating form if the logged in > user hasn't rated the record yet, know what I mean. > > What code would I need to check that? > I'm still new, albeit I feel I've read every book on the subject > twice. > > d --~--~-~--~~~---~--~~ 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: ModelForm and ForeignKeys
I have experienced this same issue, and that link didn't really help. I am trying to hook into a legacy database using "inspectdb", and I can't index the tables. class Character(models.Model): guid = models.IntegerField(primary_key=True) name = models.CharField() ... ... class CharacterHome(models.Model): character = models.IntegerField(primary_key=True) ... ... Even though django accurately assesses the datatypes of these tables, I want to be able to set CharacterHome.character as a ForeignKey (Character) and have Character return the "guid" integer value. On Aug 22, 5:29 am, Léon Dignòn wrote: > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a... > > Good luck! > > -ld > > On Aug 21, 3:49 pm, goobee wrote: > > > hi there > > > I'm in dire need of a good idea. django drives me crazy with its > > foreignkey-resolver. > > > class person(models.Model): > > name ... > > firstname > > > > > > > class participant(models.Model): > > group .. > > person(foreignkey(person)) > > funk ... > > > I want to show 'participant' using the ModelForm-feature. From model > > 'person' I need name and firstname only (or __unicode__) of the > > particular participant, but django delivers the entire table 'person' > > which is an unnecessary overkill (especially with several FKs in > > 'participant'). There must be an option to avoid this behaviour!? > > > thanks for any ideas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Strange error while trying to access admin: rendering fails (latest SVN)
I am getting a very strange error and I can't tell if it is coming from my code or Django's code. I have not modified the templates of the admin interface at all. Below is the error. I am trying to access http://localhost:8080/. This error still occurrs if I remove all apps from the install apps list and only leave contrib apps. TemplateSyntaxError at /admin/ Caught an exception while rendering: unsupported operand type(s) for +=: 'function' and 'list' Request Method: GET Request URL:http://localhost:8000/admin/ Exception Type: TemplateSyntaxError Exception Value: Caught an exception while rendering: unsupported operand type(s) for +=: 'function' and 'list' Exception Location: /usr/local/lib/python2.6/dist-packages/django/ template/debug.py in render_node, line 81 Python Executable: /usr/bin/python Python Version: 2.6.2 - Cheers, Ryan --~--~-~--~~~---~--~~ 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: Strange error while trying to access admin: rendering fails (latest SVN)
This is where it says the problem is in the template: Template error In template /usr/local/lib/python2.6/dist-packages/django/contrib/ admin/templates/admin/base.html, error at line 30 Caught an exception while rendering: unsupported operand type(s) for +=: 'function' and 'list' 20 21 22 23 {% block branding %}{% endblock %} 24 25 {% if user.is_authenticated and user.is_staff %} 26 27 {% trans 'Welcome,' %} 28 {% firstof user.first_name user.username %}. 29 {% block userlinks %} 30 {% url django-admindocs-docroot as docsroot %} <- ERROR HERE --~--~-~--~~~---~--~~ 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: Strange error while trying to access admin: rendering fails (latest SVN)
State in admin rendering process when error occurred: /usr/local/lib/python2.6/dist-packages/django/template/debug.py in render_node 74. e.source = node.source 75. raise 76. except Exception, e: 77. from sys import exc_info 78. wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace')) 79. wrapped.source = node.source 80. wrapped.exc_info = exc_info() 81. raise wrapped ... 82. return result 83. 84. class DebugVariableNode(VariableNode): 85. def render(self, context): 86. try: 87. output = force_unicode(self.filter_expression.resolve(context)) ▼ Local vars VariableValue context [{'block': , , , , , , , , , , / '>, , , , , , '>]>}, {'root_path': None, 'app_list': [{'app_url': 'auth/', 'models': [{'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'auth/group/', 'name': }, {'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'auth/ user/', 'name': }], 'has_module_perms': True, 'name': 'Auth'}, {'app_url': 'sites/', 'models': [{'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'sites/site/', 'name': }], 'has_module_perms': True, 'name': 'Sites'}, {'app_url': 'staticpages/', 'models': [{'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'staticpages/link/', 'name': u'Links'}, {'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'staticpages/menu/', 'name': u'Menus'}, {'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': 'staticpages/ staticpage/', 'name': u'Static pages'}], 'has_module_perms': True, 'name': 'Staticpages'}], 'title': u'Site administration'}, {'MEDIA_URL': 'http://localhost/static/sccom'}, {'perms': , 'messages': [], 'user': }, {}] e TypeError("unsupported operand type(s) for +=: 'function' and 'list'",) exc_info node self [, , , , , , , , , , / '>, , , , , , '>] wrapped TemplateSyntaxError(u"Caught an exception while rendering: unsupported operand type(s) for +=: 'function' and 'list'",) --~--~-~--~~~---~--~~ 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: Strange error while trying to access admin: rendering fails (latest SVN)
Thanks Karen you've been helping me out recently with debugging a few things and have been a really great asset. Cheers, Ryan Kaskel On Aug 26, 7:19 pm, Karen Tracey wrote: > On Wed, Aug 26, 2009 at 3:33 PM, Ryan K wrote: > > > This is where it says the problem is in the template: > > > Template error > > > In template /usr/local/lib/python2.6/dist-packages/django/contrib/ > > admin/templates/admin/base.html, error at line 30 > > Caught an exception while rendering: unsupported operand type(s) for > > +=: 'function' and 'list' > > 20 > > 21 > > 22 > > 23 {% block branding %}{% endblock %} > > 24 > > 25 {% if user.is_authenticated and user.is_staff %} > > 26 > > 27 {% trans 'Welcome,' %} > > 28 {% firstof user.first_name user.username %}. > > 29 {% block userlinks %} > > 30 {% url django-admindocs-docroot as docsroot %} <- ERROR HERE > > Double check your url patterns. The {% url %} tag causes your entire url > configuration to get processed, and any errors will get reported as being > due to the {% url %} tag, even though that specific tag is blameless. The > problem is likely in something you recently added/changed in your url > configuration. > > 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: interaction of django with paypal
On Sun, 2009-08-30 at 19:54 -0700, Rafael Ferreira wrote: > you could also use this (I haven't used it myself but looks > promising): > > http://github.com/johnboxall/django-paypal/tree/master I can second this recommendation, I've been doing some basic paypal integration and django-paypal has saved me a *heap* of mucking around. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part