preserve ordering in filtering
Hi, I have the following query which I cannot implement with the django model API because I need to order it according to a calculated field. query = """SELECT id FROM offers_offer AS f1 ORDER BY (f1.original_price-f1.discounted_price) DESC LIMIT 20""" cursor = connection.cursor() cursor.execute(query) offers_list = cursor.fetchall() offers_list_ids = [row[0] for row in offers_list] qs = Offer.objects.filter(id__in=offers_list_ids) The "cursor.fetchall()" method returns the ids in the right order (according to the difference between original_price and discounted_price) but the objects.filter method reorders the objects according to the primary key. How can I preserve the ordering obtained in the first place? If that's not possible how can I reorder the queryset after the filtering? Is there another way of returning ordered objects for the feeds class besides returning a queryset? (we are sending the queryset to an RSS feed class) Any help would be appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
implementing admin filters in my own views
Hi, I'd like to implement in my own views the filter functionality that is available in the admin by setting class Admin: list_filter = ('field_name1', 'field_name2',) I went through the html of the admin and I kind of understand that it's related to the generation of hidden input fields when one of the field is clicked. I also kind of understand that is related to the inclusion_tag from the django.template.Library class but I can't figure out how everything fits together in order to implement such a functionality in my own view. Could anyone give some indications? Also, is javascript needed for this task? Any help would be highly appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
applying patch
Hi, I'm trying to apply the patch given in http://code.djangoproject.com/ticket/3297 using tortoiseSVN on windows but I get the following error message: The line "Index: " was not found Either this is not a diff file or the diff is empty. The file I downloaded and used as patch is: http://code.djangoproject.com/attachment/ticket/3297/filefield.diff It is the last in the list of files related to that ticket and it has been added by russellm on 06/07/07 06:23:16. Does anyone know what I'm doing wrong? thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
accessing dictionary
Hi, I'm using the django-voting application whose method get_votes_in_bulk(object) returns a "votes" dictionary like: {object_id: {''score': score, 'num_votes': num_votes} I'm passing this dictionary as extra_context to a template where I'm also using the regroup tag on theobjects which I pass as the main queryset. So I would need to access the score and the num_votes as follow on a specific item base (I can't iterate sequentially over the items due to the regrouping). To be precise I would need to access as follow: {{ votes.object.id.score }} Of course this doesn't work because we can only use votes.object_id.score but not votes.object.id.score. Instead I need to first lookup the id and then access the dictionary using this id. If it was python I could have done something like: votes[object.id]['score'] Is there a way to do so in a template? Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
accessing dictionary in a template
Hi, I'm using the django-voting application whose method get_votes_in_bulk(object) returns a "votes" dictionary like: {object_id: {''score': score, 'num_votes': num_votes} I'm passing this dictionary as extra_context to a template where I'm also using the regroup tag on theobjects which I pass as the main queryset. So I would need to access the score and the num_votes as follow on a specific item base (I can't iterate sequentially over the items due to the regrouping). To be precise I would need to access as follow: {{ votes.object.id.score }} Of course this doesn't work because we can only use votes.object_id.score but not votes.object.id.score. Instead I need to first lookup the id and then access the dictionary using this id. If it was python I could have done something like: votes[object.id]['score'] Is there a way to do so in a template? Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
geodjango
Hi, I'd simply like to know whether there is a rough estimate of when the geodjango branch will be merged trunk. Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Chaining custom manager methods
Hi, I've created a MyManager class (extending models.Manager) to provide some custom filtering methods, then in the related MyModel(models.Model) class I put objects=MyManager() so I have the custom filtering methods available as MyModel.objects.my_filter(). Now I'd like to be able to chain the custom filters in the way it's currently possible for the default manager methods so that I could call the custom filter methods I defined also on a queryset as queryset.my_filter() and not only as MyModel.objects.my_filter(). Do you have any suggestion on how to accomplish that? Thanks a lot Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Applying custom manager methods on querysets
Hi, in django we can chain multiple filter methods like: MyModel.objects.filter(field1__exact=value1).filter(field2__exact=value2) but I'd like to be able to chain custom filter methods defined by extending the models.Manager class. For example: MyModel.objects.filter(field1__exact=value1).my_filter(field2) In other words I'd like to be able to apply the filter directly to a queryset and not only to MyModel.objects. Do you have any suggestion on how to accomplish that? Thanks a lot Francesco --~--~-~--~~~---~--~~ 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: multiple inner joins in sql
Thanks:-) On Jul 11, 3:10 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote: > On Jul 10, 2:58 pm, novice <[EMAIL PROTECTED]> wrote: > > > but I get error that the offers_offerprice.offerseller_id column > > doesnt exist. > > I think you're missing an underscore. Your model has the field named > offer_seller... shouldn't it then be > offers_offerprice.offer_seller_id? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ip to location
Hi, does anyone in the django community know of a public algorithm to get the location from the ip. If such a thing doesn't exist do you know of a service with an API which does it? Or maybe such a functionality will be available with the upcoming Geodjango? Many thanks Francesco --~--~-~--~~~---~--~~ 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: ip to location
Thanks but I was asking for something more precise, like latitude and longitude (approximated, of course) rather than the country which would be too vague for my application. Any other suggestion? Thanks again On Jul 16, 1:07 pm, xaranduu <[EMAIL PROTECTED]> wrote: > cesco schrieb: > > > Hi, > > > does anyone in the django community know of a public algorithm to get > > the location from the ip. > > If such a thing doesn't exist do you know of a service with an API > > which does it? > > Or maybe such a functionality will be available with the upcoming > > Geodjango? > > > Many thanks > > Francesco > > Coulix has a cool solution to your topic. He has small apllication > that can handle the mapping. > And he points to some files which provide a ip2country mapping and > country flags for you. > > http://coulix.net/blog/2006/aug/17/ip-country-flags-django-comments/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
full-text indexing
Hi, is there any rough estimate on when the full-text indexing branch will be integrated into trunk? Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
automatic form submission
Hi, I need to retrieve automatically some information from an e-commerce site. The site doesn't offer any API, so the only way to perform the search is via the form they provide. The form is submitted via a POST method and the URL doesn't change after clicking the search button even if I select different search criteria (which are only checkboxes). Do you know of any way to automatically or do you have any suggestion on to automatically perform the following? 1. check a specific checkbox in the search form 2. submit the search form 3. save in a file the html source of the webpage displaying the search results Any help would be very appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
UnicodeDecodeError in template rendering
Hi, I'm using sqlite3 as db for my django project. In order to load the data in the db I first generated a unicode string (which contains danish characters "ø, æ, å") and dumped such a string to a file (in json format) as follows: f_hdl = file(json_offers_path, 'w') f_hdl.write(offer_entry.encode('utf-8')) f_hdl.close() I then loaded the data in the database using the command: python manage.py loaddata path/to/json/file I could run the local server for development without any problem. In the homepage I have to display some information that may contain danish characters. If the page I have to display doesn't contain danish characters I don't get any error. If it does contain them I get the following error: Exception Type: UnicodeEncodeError Exception Value: 'ascii' codec can't encode character u'\xe6' in position 27: ordinal not in range(128) Exception Location: C:\Python25\lib\site-packages\django\utils \encoding.py in force_unicode, line 39 Unicode error hint: The string that could not be encoded/decoded was: roanlæg Do you have any suggestion on how to solve the problem? Many thanks Francesco --~--~-~--~~~---~--~~ 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: UnicodeEncodeError in template rendering
Thanks for your replies. Just to avoid any doubt, I'm using __unicode__ instead of __str__ and I'm using the latest development version of django (post unicode merge). > What is most important to know is (a) what is the data that it is > trying to render (both type and content). It's trying to render an object of the class 'my_project.offers.models.Offer', which contains, among other fields, a "name" field (that is models.CharField, which in some cases contains danish characters) and a picture field (that is models.ImageField). In the page I'm trying to render I display 1. a thumbnail of such image using the patch from http://code.djangoproject.com/ticket/4115 which is located in django.contrib.thumbnails. 2. the name of the picture/offer which may contain danish characters. Every time I reload the page, 6 offers objects are pulled randomly from all the available ones. If those objects contain a danish character in their name (like 'æ') then I get the UnicodeEncodeError (please, note the previous title of this post was UnicodeDecodeError while it's actually a UnicodeEncodeError). If the objects don't contain any danish character then I don't get any problem. If I print to a file the repr() of the object then I get the right danish characters. Only in the template rendering for some reason there is this problem. I'm using sqlite3 with the development server and python 2.5 Following are the information I had given before (which I repeat here for completeness) and the full traceback I get from the template error. Exception Type: UnicodeEncodeError Exception Value: 'ascii' codec can't encode character u'\xe6' in position 27: ordinal not in range(128) Exception Location: C:\Python25\lib\site-packages\django\utils \encoding.py in force_unicode, line 39 Unicode error hint: The string that could not be encoded/decoded was: roanlæg Traceback (most recent call last): File "C:\Python25\lib\site-packages\django\template\__init__.py" in render_node 754. result = node.render(context) File "C:\Python25\lib\site-packages\django\template\defaulttags.py" in render 134. nodelist.append(node.render(context)) File "C:\Python25\lib\site-packages\django\template\defaulttags.py" in render 134. nodelist.append(node.render(context)) File "C:\Python25\lib\site-packages\django\template\loader_tags.py" in render 96. return self.template.render(context) File "C:\Python25\lib\site-packages\django\template\__init__.py" in render 181. return self.nodelist.render(context) File "C:\Python25\lib\site-packages\django\template\__init__.py" in render 739. return ''.join([force_unicode(b) for b in bits]) File "C:\Python25\lib\site-packages\django\utils\encoding.py" in force_unicode 39. s = unicode(str(s), encoding, errors) UnicodeEncodeError at / 'ascii' codec can't encode character u'\xe6' in position 27: ordinal not in range(128) I'm struggling with this problem from quite some time. Any help would be very appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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: UnicodeEncodeError in template rendering
Thanks a lot Malcolm, I think we are getting there:-) > So, have a look at the debug screen and click on the "local variables" > link just below this last line in the extended traceback. What is "s" > here (in particular, it would be good know what type(s) is)? Also, what > is the value of 'encoding'? Here are the values. encoding: u'utf-8' errors: u'strict' s: strings_only: False > what is the current value of 'b' (and it's type) > in the previous line of the traceback? Again, using the "locals" link on > the debug page should be able to tell you this. b: Hope I was able to report all the information. If the problem is, like you suspect, the patch I applied, do you have any suggestion on how to solve the problem? Maybe modify the patch itself following the guidelines for transition to Unicode? Thanks a ton Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
CRUD generic views and new forms
In the current django documentation is written that the create_object generic view (from django.views.generic.create_update) returns as template context the "form" variable which is an instance of django.oldforms.FormWrapper. Is there a way to use new forms? Thanks and regards Francesco --~--~-~--~~~---~--~~ 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: Email as username in django auth framework
Hi > I'm using this snippet which works fine. Which snippet? Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
displaying errors after form validation
Hi, I'm a bit puzzled by the following behaviour of newforms. I have a field in the form called 'seller'. In the form validation I have a clean_seller method which if a certain condition is verified will do the following: self.errors.update(seller = ErrorList([u"message1: the indicated seller doesn't exist in our database"])) raise forms.ValidationError(u"message2: seller doesn't exist") In the template I have the following: {{ monitor_f.seller.errors|join:", " }} I would expect the first message (that is: "message1: the indicated seller doesn't exist in our database") to be displayed in case of error and I thought that the forms.ValidationError was just an exception raised to stop the validation. Instead the second message (the one contained in forms.ValidationError is displayed). Probably there is something I'm missing. Would anyone help me understand? Many thanks Francesco --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problem with django tagging application
Hi, I'm using the latest version of the django tagging application (rev. 132) and I'm having problems with the get_by_model method of the TaggedItem manager. Say I have a QuerySet1 generated as follow: QuerySet1 = TaggedItem.objects.get_by_model(MyModel, 'tag1') and a QuerySet2 generated as follow: QuerySet2 = TaggedItem.objects.get_by_model(MyModel, 'tag2') If at this point I try to '&' the two query sets as in: QuerySet3 = QuerySet1 & QuerySet2 then I get the following error: "ambiguous column name: tagging_taggeditem.object_id" Do you have any idea of why I'm getting this error and how I could solve the problem? For completeness in dpaste is the complete traceback I get: http://dpaste.com/36177/ Any help would be very appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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: problem with django tagging application
Hi > So the SQL that is being constructed by the joined queryset isn't valid. > I'm almost certain the answer to this is "it's fixed in > queryset-refactor, so will one day be fixed in trunk." Thanks for the work you are doing:-) > Pull the results back into Python and merge them manually. Could I ask you to be a bit more specific (not so experienced with python and django)? You mean I should take the two query sets separately and merge them based on the id of the objects in each of the querysets? Thanks again Francesco --~--~-~--~~~---~--~~ 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: problem with django tagging application
Hi, > Any chance you were using django-tagging previously and recently > updated to trunk? There are backwards incompatible changes - the > relation names have > changed:http://code.google.com/p/django-tagging/wiki/BackwardsIncompatibleCha... I was actually getting the same error before and after the updates. Thanks anyway Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django tagging usage_for_model problem
Hi, I'd like to use the manager method Tag.objects.usage_for_model(MyModel, filters=dict(field1__exact='value1')) from the django tagging application. In my case MyModel has as attribute a foreign key to the User model. My problem is that I'd like to filter out the authenticated users (and in another situation the anonymous users). Do you have any suggestion on which expression should I give to the field parameter? It would probably be easier if I could pass a queryset rather than the model as first parameter but this doesn't seem to be possible... Any help would be very appreciated Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
best practice to delete an object
Hi, my question is really basic but I'd like to make sure I'm doing the right thing. Say a user owns certain objects and it has the possibility to delete them by clicking on a "delete" link. I'm thinking of associating that link to a get request via a url like: /objects/delete/ but this would give the possibility to a users to delete objects created and belonging to another user by directly typing the url in the bar and putting a random object_pk. What is the best practice to deal with this? Is it a good idea to simply check that the owner of the object is also the one performing the get request? Would something like the following do the job? if request.user.id == object.user.id: object.delete() Is there a well known approach? Thanks a lot Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Bug in django related to sqlite3?
I have to execute the following SQL query: query = """SELECT id FROM my_table \ WHERE my_table.some_id IN %s""" cursor.execute(query, [(1, 2, 3)]) and the aim would be to replace the %s with the tuple (1, 2, 3) but I get the following error: Traceback (most recent call last): File "", line 1, in cursor.execute(query, [(1, 2, 3)]) File "C:\Python25\lib\site-packages\django\db\backends\util.py", line 12, in execute return self.cursor.execute(sql, params) File "C:\Python25\lib\site-packages\django\db\backends \sqlite3\base.py", line 94, in execute return Database.Cursor.execute(self, query, params) OperationalError: near "?": syntax error Is this a bug related to sqlite3 (which I'm using in this case) or am I doing something wrong? Any help would be highly appreciated. Many thanks Francesco --~--~-~--~~~---~--~~ 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: Bug in django related to sqlite3?
Indeed I have to use the query/cursor mode. The query is a way more complex than that and I need some ordering based on calculated fields (which is not supported at the moment from the QuerySet api). I simplified the query simply to isolate the problem. some_id is indeed a foreign key to another table. Any other suggestion? Thanks again Francesco On May 14, 3:28 pm, Martin Winkler <[EMAIL PROTECTED]> wrote: > Hi Francesco, > > Am Mon, 14 May 2007 12:44:46 - > schrieb cesco <[EMAIL PROTECTED]>: > > > query = """SELECT id FROM my_table \ > > WHERE my_table.some_id IN %s""" > > cursor.execute(query, [(1, 2, 3)]) > > why are you diving so deep? > can't you just use > > myobjects = MyTable.objects.filter(some__in=(1,2,3)) ? > > (I am assuming that your model is called MyTable and that the field > "some_id" is in fact a ForeignKey field called "some") > > If you absolutely _have_to_ use the query/cursor code, then sorry, I > personally don't have a solution for that. > > Martin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
dictionary lookup in template within regroup tag
Hi, I'm trying to render a template using a generic view of the list_detail type. The list of objects I'm trying to render in the template (which are offers) have an original_price and a discounted_price and I'd like to display also the relative discount (that is: (original_price-discounted_price)/original_price). For this I'm passing a dictionary to the extra_context dictionary of the generic view with offer.id as key and the relative discount as value. Now in the template I have the following code where I'd like to access the relative discount which is in the offers_discount dictionary. The problem is due to the grouping I cannot use the for loop to iterate over the dictionary. The way I'd like to do it would be as shown below {{ offers_discount.{{offer.id}} }} but of course it doesn't work. {% regroup offers_list by category as grouped %} {% for group in grouped %} {{ group.grouper }} {% for offer in group.list %} offer name: {{ offer.name }} | offer discount: {{ offers_discount.{{offer.id}} }}. {% endfor %} {% endfor %} The other related discussions on this newsgroup (dictionary lookup in templates) don't consider the case of grouping where we can't iterate over the dictionary in the classical way. Do you have any suggestion on how to solve this problem? Thanks a lot Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
loading data from fixtures
Hi, I'm experiencing a problem loading some data from fixtures. Some of the object loaded have danish letters (ø, å, æ) in their fields. If I use the ANSI encoding for the JSON file I'm trying to load I get the following error message: "Problem installing fixture ...: 'utf8' codec can't decode bytes in position 2-6: unsupported Unicode code range" If I use the UTF8 encoding I get the message: "Problem installing fixture ...: No JSON object could be decoded" I tried also replacing the danish letters with their unicode encoding (ø -> \xf8, æ -> \xe6, å -> \xe5) but it didn't work (neither in ANSI nor in UTF-8). Do you have any suggestion on how to solve this problem? Any help would be very appreciated Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
FileInput widget behaviour related to upload_to attribute
I have a model called Offer containing, besides other fields, a picture field as in the following example: class Offer(models.Model): picture = models.ImageField(null=True, blank=False, unique=False, upload_to='offers/') I created a form for adding Offer objects as follows: class AddOfferForm(forms.Form): picture = forms.CharField(widget=forms.FileInput()) Now it happens that when I add an offer object using the admin interface the picture gets stored in the subdirectory of MEDIA_ROOT called "offer" (as specified in the field "upload_to"). When I add an offer object using the form I created there are two problems: 1. the picture doesn't get stored in the in any directory (it simply remains in the original directory) 2. the relative path to the picture doesn't include the subdirectory "offers" as if the picture was stored in the MEDIA_ROOT folder. I guess I'm missing something (maybe in the form or in the view) but I wasn't able to find it (neither in the documentation nor in this group). Any suggestion would be very appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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: FileInput widget behaviour related to upload_to attribute
> Can you tell us more info about your view code ? Thanks for the quick response! in the view I have the following if request.method == 'POST': form = AddOfferForm(request.POST) if form.is_valid(): #new_offer = form.save() Offer.objects.create(name=form.cleaned_data['product_name'], seller=request.user.get_profile().get_seller(), category=form.cleaned_data['category'], description=form.cleaned_data['description'], original_price=form.cleaned_data['original_price'], picture=form.cleaned_data['picture'], ) as you can see, the "picture=form.cleaned_data['picture']" is the one that is not working, as all the other fields are saved properly. Regards, Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
use of save_FOO_file
In the following method available for FileFields: save_FOO_file(filename, raw_contents) what does "raw_contents" represents? I didn't find any example on the web about it. Many thanks Francesco --~--~-~--~~~---~--~~ 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: use of save_FOO_file
On Jun 3, 6:52 pm, sansmojo <[EMAIL PROTECTED]> wrote: > The raw, binary data of the file. After uploading, it ends up at > request.FILES['file']['content'] (where 'file' is the name of your > form field). > > An example: > > if request.FILES.has_key('file'): > new_file = File(some_field='some_val', > date_uploaded=datetime.now()) > new_file.save_file_file(request.FILES['file']['filename'], > request.FILES['file']['content']) # because the field name is file > new_file.save Thanks for the reply but I still can't get it to work. In the form.py I have the following code: class AddOfferForm(forms.Form): picture = forms.CharField(widget=forms.FileInput()) ... and in the template I have: {{ form.picture }} and in the view.py I do print request.FILES but it's always empty (unlike request.POST which gives the expected values). I tried also to include the following in the form: enctype="multipart/form-data" and to have {{ form.picture_file }} beside {{ form.picture }} as pointed out here: http://www.djangoproject.com/documentation/forms/ but the request.FILES was still empty. Do you have any idea on what's wrong? Any help would be very appreciated. Thanks and regards Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Generating Q objects for different model fields
Hi, I'd like to make a filter composed by ORing several Q objects, each of which acts on a different model field. For example I have a model with the fields "name", "title", "description" and I want to make a Q object like the following: Q_name = (Q(name__istartswith="hello") & Q(name__icontains="how are you")) Q_title = (Q(title__istartswith="hello") & Q(title__icontains="how are you")) Q_description = (Q(description__istartswith="hello") & Q(description__icontains="how are you")) Q_final = (Q_name | Q_title | Q_description) Is it possible to avoid writing a Q object for each field and instead simply generate it by passing the field (name, title and description) as parameter? One way could be to generate the string and pass it to eval() but I'd like to avoid that. Any help would be appreciated. Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
filtering based on property
Hi, is it possible to do filtering based on a method or a property of the model? Say I have a model with a from_date field and a to_date field and a method, defined within the model, which checks if the model instance is current, that is: from datetime import date @property def is_current(self): return self.from_date <= date.today() and self.to_date >= date.today() is there any way, in the manager, to do something like MyModel.objects.filter(is_current=True) ? Thanks and regards Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using unitest or doc test with complex output
Hi, I'd like to test a query and the data returned by that query is a list containing a list of objects. For example: [[, , ..., ]] If I try testing using unittests I get the following error: AssertionError: [[]] != [[]] though to me the expected output and the one I get look identical. If I try with doc test then I get the problem when the output span multiple lines: even though the objects returned are the right ones, the expected string and the one I get are different because of newlines and this make the test fail. Is there any solution to this problem (with particular regard to unittest, which I would prefer to use)? thanks and regards Francesco --~--~-~--~~~---~--~~ 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: Using unitest or doc test with complex output
Thanks for the clarification. I understand now the problem regarding doctests and the comparison of the same objects. The thing I'm still missing is how can the test fail when I'm comparing a list containing an empty list with a list containing an empty list as well. No model object is involved in that case. Basically the view I was trying to test returns a list of list of querysets and, for some combination of parameters, the queryset is empty, that is, it returns a list containing an empty list. Shouldn't the comparison work in that case? The line that fails is the following: self.assertEquals(perform_search(category_id=1, shop_id=290, tags=['tag1', 'tag2']), [[]]) and the error message is: AssertionError: [[]] != [[]] Is there an explanation for this as well? Maybe I'm doing something wrong? Thanks again Francesco On Sep 20, 2:13 am, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On 9/20/07, cesco <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > I'd like to test a query and the data returned by that query is a list > > containing a list of objects. For example: > > [[, , ..., ]] > > > If I try testing using unittests I get the following error: > > AssertionError: [[]] != [[]] > > though to me the expected output and the one I get look identical. > > Without the exact test, it's difficult to know exactly what is going > wrong; however, there is one possible generic cause of difficulty. > > Despite all appearances, != . > By extension, lists of won't be equal, either. > > is the output representation of a Django model > object. The thing is, two model objects with that point to the same > database object (i.e., they have the same model and have the same > primary key) _are not equal_. This is because the _wrapper_ objects > are different. [1] > > Generally, if you want to check if two object instances are equal, > compare their primary keys; if you want to compare two lists, compare > lists of primary keys: i.e., > > [obj.id for obj in query.all()] = [1,2,3] > > > If I try with doc test then I get the problem when the output span > > multiple lines: even though the objects returned are the right ones, > > the expected string and the one I get are different because of > > newlines and this make the test fail. > > This is an inherent difficulty with doctests, and it's one of the > reasons you might want to favour using unittest over doctest. > > [1] Before you ask, no, we can't just override __eq__ to check for PK > equality - search the archives if you want to know why. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Union/join of two queryset?
Hi, I have two QuerySets and I need to join them to pass them as first parameter to the ObjectPaginator class. How can I do that? The "+" operator doesn't work (like it does for lists) and there is no a method like the list one "extend()". Any suggestion would be very appreciated. Best regards Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
exclude on two querysets
Hi, I have two querysets: qs_big and qs_small with qs_small subset of qs_big (that is, all the objects in qs_small are also objects of qs_big). I'd like to obtain a queryset of objects which are in qs_big but not in qs_small. If exclude could accept a queryset as parameter I would do something like: qs_big.exclude(qs_small). Unfortunately this is not possible. Do you have any suggestion on how to solve the problem? Thanks Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
postgresql problem with django api (iregex)
Hi, I have the following query which works perfectly with sqlite3: from django.db import models qs.filter(models.Q(myField__iregex="\\b%s\\b" % myString) In the production server, where I'm running postgresql the exact same query is not working. Do you have any idea why this happens? Maybe a bug? Note that I'm running the SVN (most recent) version of django. Thanks Francesco --~--~-~--~~~---~--~~ 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: postgresql problem with django api (iregex)
Sorry for the imprecise description of the problem. After some filtering statements (which I don't show here) I derive a qs containing about 1000 objects. With the following statement I try to filter the query further new_qs = qs.filter(models.Q(myField__iregex="\\b%s\\b" % myString) and new_qs comes to have 93 objects. This happens locally where I'm running sqlite3. In the production server (which I currently can't access, so I can't compare the sql statements) I have the same database (except that I'm using Postgresql 8.2). The qs which I have before the "critical" filter statement contains the same objects (about 1000 of them). After I apply the same filtering I get a resulting qs which is empty. So no error message or infinite loop. Just a different unexpected result. I'm running the following django-version: 0.97-pre-SVN-6694 Do you have any suggestion on what could be wrong? Thanks again Francesco On Nov 19, 1:52 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Sun, 2007-11-18 at 12:46 -0800, cesco wrote: > > Hi, > > > I have the following query which works perfectly with sqlite3: > > > from django.db import models > > qs.filter(models.Q(myField__iregex="\\b%s\\b" % myString) > > > In the production server, where I'm running postgresql the exact same > > query is not working. > > Once again it needs to be pointed out that "not working" is not a > description of the problem. What does it mean? No result was returned? > An error was raised (if so, what error)? The software went into an > infinite loop? > > The standard way to describe a problem is (1) I did this, (2) This > happened, (3) I expected this other thing to happen (in your case, you > could show the corresponding output from SQLite). > > As a head start, try looking at the SQL generated by Django (if the > query gets executed) and see if that gives you any idesa. See the FAQ if > you don't know how to view the SQL. > > > Do you have any idea why this happens? Maybe a bug? > > > Note that I'm running the SVN (most recent) version of django. > > Again, in future, you'll probably want to report the actual subversion > number (run "django-admin.py --version" or "svn info") because "most > recent" is only relative to when you posted the message. You might > already be a few changesets behind trunk by the time somebody reads your > message, particularly if it takes a day or two. > > By all means post more information about your problem, but help us to > help you by providing enough information for us to work with, > particularly when it comes to describing your problem. > > Regards, > Malcolm > > -- > How many of you believe in telekinesis? Raise my > hand...http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: postgresql problem with django api (iregex)
Thanks for the reply. I'm actually trying to match a word boundary with "\\b" before and after the string, not a backspace. Still one thing is unclear to me: isn't the django API supposed to be portable across different database platforms? Does iregex make an exception because of SQLite lack of reg- exp support? If that's the case then the code has to be changed when moving to production (that is, likely to a different database platform)? Thanks again Francesco On Nov 20, 12:58 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-11-19 at 13:59 -0800, cesco wrote: > > Sorry for the imprecise description of the problem. > > > After some filtering statements (which I don't show here) I derive a > > qs containing about 1000 objects. > > With the following statement I try to filter the query further > > new_qs = qs.filter(models.Q(myField__iregex="\\b%s\\b" % myString) > > and new_qs comes to have 93 objects. > > This happens locally where I'm running sqlite3. > > > In the production server (which I currently can't access, so I can't > > compare the sql statements) I have the same database (except that I'm > > using Postgresql 8.2). > > The qs which I have before the "critical" filter statement contains > > the same objects (about 1000 of them). After I apply the same > > filtering I get a resulting qs which is empty. So no error message or > > infinite loop. Just a different unexpected result. > > Does the SQL produced by Django make sense for PostgreSQL? Once you know > that it's likely to be an SQL selection problem, the next step is to > look at the SQL generated and see if it's what you expect. > > The problem is almost certainly the '\b' in your regex, since that is > trying to match "backspace" and I suspect you want '\m' in the first > case and '\M' in the second one. SQLite doesn't have native regexp > matching, so Django provides an interface to Python's regular expression > module. However, this isn't the same as the reg-exp syntax used by > PostgreSQL. > > Regards, > Malcolm > > -- > I've got a mind like a... a... what's that thing > called?http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
db_index and loading data via fixtures
Hi, I recently started using the django-tagging application. The Tag and TagItem models have each a field which is indexed (db_index=True). Does loading data with json fixtures change because of having db_index=True? When the data are loaded via fixtures is the save method called on each loaded instance? Thanks and regards Francesco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---