my first (public) app: django-requires_js_css
http://github.com/pappy74/django-requires_js_css Howdy folks, I was hoping to get some feedback on my first public app, django- requires_js_css. The app's purpose is to allow 'sane' JavaScript and CSS requirements. That is, require from within templates, but still load using 'best practices'. Definitely a work in progress, although we are using it at our startup. My questions to you: - Is there another app that does this? - Do other devs find this worthwhile? - What's missing? - I currently use a fairly gnarly hack to make this all work (embedding tokens in the response content, then post-processing those tokens using middleware). Is there a better way? _jason -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: /admin list help ASAP
On 10/20/2010 11:55 PM, Mike Dewhirst wrote: > On 21/10/2010 1:24pm, Bobby Roberts wrote: >> hi all. I have two models setup let's call them >> >> Gallery >> Photos >> >> photos has a field as such: >> >> GalleryId = models.ForeignKey('Gallery', verbose_name=_('Gallery Id'), >> related_name='Gallery_Id',blank=False, null=False, help_text=_("Please >> choose the gallery to which you wish to associate this photo.")) >> >> Ok now here's the question. >> >> In the listing page for my photos, I want to print Gallery.Title >> >> the two models are related on Photos.GalleryId=Gallery.Id >> >> How do I return Gallery title in the listing page in /admin? >> > > You can write a function in __unicode__() to display the two ... > > def getGallery(self): > pass # not sure how to get the Gallery title > > def __unicode__(self): > return u'%s: %s' % (self.getGallery, > self.title) > Shouldn't that be def __unicode__(self): return u'%s: %s' % (self.getGallery(), self.title) You actually have to _call_ the getGallery method. Note that the __unicode__ and getGallery methods Mike describes should be methods of your photos model. regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: /admin list help ASAP
On 21/10/2010 1:24pm, Bobby Roberts wrote: hi all. I have two models setup let's call them Gallery Photos photos has a field as such: GalleryId = models.ForeignKey('Gallery', verbose_name=_('Gallery Id'), related_name='Gallery_Id',blank=False, null=False, help_text=_("Please choose the gallery to which you wish to associate this photo.")) Ok now here's the question. In the listing page for my photos, I want to print Gallery.Title the two models are related on Photos.GalleryId=Gallery.Id How do I return Gallery title in the listing page in /admin? You can write a function in __unicode__() to display the two ... def getGallery(self): pass # not sure how to get the Gallery title def __unicode__(self): return u'%s: %s' % (self.getGallery, self.title) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
/admin list help ASAP
hi all. I have two models setup let's call them Gallery Photos photos has a field as such: GalleryId = models.ForeignKey('Gallery', verbose_name=_('Gallery Id'), related_name='Gallery_Id',blank=False, null=False, help_text=_("Please choose the gallery to which you wish to associate this photo.")) Ok now here's the question. In the listing page for my photos, I want to print Gallery.Title the two models are related on Photos.GalleryId=Gallery.Id How do I return Gallery title in the listing page in /admin? -- 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: dump sqlite to file when testing
On Wed, Oct 20, 2010 at 10:33 PM, Miguel Araujowrote: > Hi everyone, > Is there any way to force sqlite3 to use a file instead of RAM when running > tests? I would like to access the DB somehow to check some fields. This is > the only DB engine I have in this machine. Yes - set the TEST_NAME (or DATABASE_TEST_NAME if you're using pre 1.2 style database settings) to a specific file name [1]. This will override the default behavior of using :memory: as the test database name. [1] http://docs.djangoproject.com/en/dev/ref/settings/#test-name 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-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.
call more than one view action from an uri path?
Djangoistas: We want to call this URL: http://www.server.com/nest/5/pest/6/rest/7 We want each handler to call, with its argument, in order: def nest(request, x): ... def pest(request, y): ... def rest(request, z): ... (Internally, at rest() time, we want x and y to be available on some session or file-scope variable.) How to write an url() call in urls.py that handles part of a path, and then dispatches to the next part of the path, if any? -- Phlip http://bit.ly/ZeekLand -- 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.
checkboxes disappearing in the admin panel?
Hey, I'm seeing some very odd behavior in Django's admin panel. I'm using the admin panel to list about 3500 objects of "people". The list view shows about 17 fields. I'm using the checkboxes to perform certain admin actions I wrote. This all works great, usually. Sometimes, when I'm looking at the list, there are no checkboxes, which means I can't select anything to perform any action. The only way I found to restore the checkboxes is by restarting the Django process. Did anyone see this odd behavior? Is there any reason Django is not showing my checkboxes? Thank you. Yo'av -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: about site price
On 10/20/2010 4:17 PM, Lic. José M. Rodriguez Bacallao wrote: > hi folks, I have a client that need to develop a bet site like this: > http://www.webapuestas.com/ > the problem is that I am new in the business and I don't know how much > money can I ask for a > this work, can someone help me and take a look to the site and give me > an approximate cost for > a site like this? > > PS: sorry for my English, it's not so good. > This really is a dangerous question. First, you have to ask what it will cost you to develop. Do you have any clear idea of that cost? Next you have to ask yourself what it's worth to the customer. If the second figure is lower than the first, stop right there. I would seriously advise you not to undertake a large paid gig such as building a betting site without first getting enough industry experience and learning a lot more about building web sites than you apparently do at the moment. If you don't gain the experience, you risk exposing yourself to large liabilities. regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problems displaying image objects in a Django template using a custom template tag? (coding included)
Hello, I think you should use something like alt="{{ object.title }}" /> in your template: you want to output images' url in your template, not the "object" itself. You'll find explanations in [1] and [2]. Regards [1] http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.storage [2] http://docs.djangoproject.com/en/dev/ref/files/file/#the-file-object -- 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.
about site price
hi folks, I have a client that need to develop a bet site like this: http://www.webapuestas.com/ the problem is that I am new in the business and I don't know how much money can I ask for a this work, can someone help me and take a look to the site and give me an approximate cost for a site like this? PS: sorry for my English, it's not so good. -- Lic. José M. Rodriguez Bacallao Centro de Biofisica Medica - Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo. Recuerda: El arca de Noe fue construida por aficionados, el titanic por profesionales - -- 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: Heriter charField
merci beaucoup , mais mon probleme est le mot de passe ne doit pas etre en claire dans la base .Aussi je peux pas utiliser les hash parceque ya une autre application , java meme , qui accéde a la base de donnee -- 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: call shell script from Django web service
If I were you, I would first investigate why is the script failing. Then, when you know why it's failing, you could make a workaround. It is normally possible to run external apps from Django, because it's just Python. You simply need to give your script the correct set of environment for it to work properly. Most of the time, lack of some directives in the environments is the cause of external apps not running. On Wed, Oct 20, 2010 at 9:47 PM, jintaowrote: > Hi all, > > I implemented some web service with Django framework. I need this > service to execute some shell script on the server. > > I have already tried os.system(), which works in python terminal, but > doesn't work in Django framework. > > Anyone could show some guidance here? > > Thanks tons! > > jintao > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
call shell script from Django web service
Hi all, I implemented some web service with Django framework. I need this service to execute some shell script on the server. I have already tried os.system(), which works in python terminal, but doesn't work in Django framework. Anyone could show some guidance here? Thanks tons! jintao -- 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: Oracle Database Other User Tables/Views
On Oct 20, 8:20 am, "Christopher Conover"wrote: > Hello, > > I am using Django's multiple database support to connect to an existing > Oracle database (10g). I do not have control of the schema nor do I have any > other privileges beyond SELECT. Further, the tables and views that I have > access to are owned by a different user. Because of this I'm having to refer > to these tables in queries using the other_user.table syntax. > > This issue is that Django's Oracle backend wants to quote all table names. > This does not work for the other_user.table syntax. To get this working for > the moment, I have patched the quote_name method on line 192 of > django/db/backends/oracle/base.py to forego the quoting. > > Does anyone have any suggestions of how to work around this without modifying > the Django source? Alternate schema support is the subject of ticket #6148 in the Django ticket tracker. When that finally lands, it will be as simple as setting the db_schema Meta option. In the meantime, the recommended workaround for Oracle is to create synonyms within the Django schema for the external tables and views, e.g.: CREATE SYNONYM MY_SCHEMA.SOME_TABLE FOR OTHER_SCHEMA.SOME_TABLE; This only requires the rather innocuous CREATE SYNONYM system privilege. If the DBA won't even let you have that, you can fall back on specifying the schema and table in the db_table option with the proper interior quoting, e.g.: db_table = 'other_schema"."some_table' This is sufficient to trick Django into doing the right thing in most cases. Cheers, 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-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: Heriter charField
Je suis un débutant en Django, mais je pense que tu doit utiliser un autre widget pour ton mot de passe. Par exemple: password = CharField(widget=PasswordInput) D'autres widget ici: http://docs.djangoproject.com/en/dev/ref/forms/widgets/ 2010/10/20 updo> Bonjour à tout le monde > Je voudrai creer une classe passwordField qui va heriter de la classe > charField afin de crypter les mots dans la base de donnée , je > voudrai savoir quelles sont les méthodes de la classe faudra > redéfinir pour que quand je cree une instance de la classe > passwordField , il prend en parametre le mot de passe en clair , le > crype et le sauve dans la bdd .De même quand j'affiche un objet un > objet passwordField ,il recupere le mot de passe crypte au niveau de > la base , le decrypte et me l'affiche en claire . j'ai deja mes > methodes pour crypter et decrypter du texte > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Heriter charField
On Oct 20, 6:40 pm, updowrote: > Bonjour à tout le monde > Je voudrai creer une classe passwordField qui va heriter de la classe > charField afin de crypter les mots dans la base de donnée , je > voudrai savoir quelles sont les méthodes de la classe faudra > redéfinir pour que quand je cree une instance de la classe > passwordField , il prend en parametre le mot de passe en clair , le > crype et le sauve dans la bdd .De même quand j'affiche un objet un > objet passwordField ,il recupere le mot de passe crypte au niveau de > la base , le decrypte et me l'affiche en claire . j'ai deja mes > methodes pour crypter et decrypter du texte Bonjour, tu devrais savoir que la langue habituelle de ce groupe est l'anglais - il y en a parmi nous qui comprendent le français, mais tu auras plus de chance si tu posais la question en anglais. De toute façon, cela n'est pas un méthode très sur de sauver un mot de passe. Le methode qu'utilise Django est d'employer une fonction "hash", qui marche dans une direction seulement - c'est à dire, il est possible de crypter, mais non pas de decrypter. Quand quelqu'un donne son mot de passe pour accéder au site, on crypte le mot qu'il a donné, et va voir si les deux sont pareils. Cependeant, si tu est certain, il faut voir les docus qui décrivent comment écrire un champ customisé: http://docs.djangoproject.com/en/1.2/howto/custom-model-fields/ [To the group: the OP wanted to know what methods he should use for writing a passwordfield which automatically encrypted and decrypted a password when it was saved to/read from the database. I suggested that wasn't a very secure way of doing it, but pointed him to the custom field documentation. And for those whose French is better than mine, I apologise for the many errors above.] -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Heriter charField
Bonjour à tout le monde Je voudrai creer une classe passwordField qui va heriter de la classe charField afin de crypter les mots dans la base de donnée , je voudrai savoir quelles sont les méthodes de la classe faudra redéfinir pour que quand je cree une instance de la classe passwordField , il prend en parametre le mot de passe en clair , le crype et le sauve dans la bdd .De même quand j'affiche un objet un objet passwordField ,il recupere le mot de passe crypte au niveau de la base , le decrypte et me l'affiche en claire . j'ai deja mes methodes pour crypter et decrypter du texte -- 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: "No module named copycompat" error
That worked. Thanks! On Oct 19, 4:05 pm, timc3wrote: > From a python prompt can you do: > > from django.utils import copycompat > > If not, Django might not be imported properly. Also check your > PYTHONPATH. > > On Oct 18, 10:57 pm, mathphreak wrote: > > > > > I just upgraded my computer to Ubuntu 10.10, and now running "python > > manage.py runserver" gives me "Error: No module named copycompat". > > I've probably also upgraded Django from 1.1.x to 1.2.x, which might be > > the problem too. Which upgrade broke manage.py, and how can I fix > > 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-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.
What is the difference between MEDIA_ROOT and STATICFILES_ROOT in Django1.3?
.. and why staticfiles doesn't work? :-) # django.contrib.staticfiles ... if settings.DEBUG: raise ImproperlyConfigured("The view to serve static files can only " "be used if the DEBUG setting is True") It should be "if not settings.DEBUG" I think. regards. -- 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: Manual ordering
Worked like a charm. This was a limited case so I won't be needing any checks to ensure that the ID's are all in the queryset since there are only 5 or 6. Thanks again. On Oct 20, 10:44 am, Shawn Milochikwrote: > Given a tuple/list of primary keys named ordered_ids and a queryset named > records: > > results = [records.get(pk = x) for x in ordered_ids] > > This is a naive example, as it assumes that ordered_ids will never have IDs > which don't exist in the queryset, but it gives a simple way to do what > you're asking for. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Newbie question: How should I structure my very simple project / app?
Just a quick response to thank everyone for the suggestions. I'll let you all know how I get on. ;-) (Actually, you'll probably guess from the quality or absurdity of my questions that may come up over the coming days / weeks) WZ On 20 October 2010 00:01, timc3wrote: > Take a look at: > > http://lincolnloop.com/django-best-practices/projects/layout.html > > After you have done the tutorials and stuff. > > Tim. -- 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: Manual ordering
Given a tuple/list of primary keys named ordered_ids and a queryset named records: results = [records.get(pk = x) for x in ordered_ids] This is a naive example, as it assumes that ordered_ids will never have IDs which don't exist in the queryset, but it gives a simple way to do what you're asking for. Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Multi-user environment where users can add/edit/delete only their own posts
Your post model should have a foreign key to user, perhaps named "creator" or "owner." Then ensure that the edit and delete views in your application can only modify or delete posts where the owner is request.user. Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Manual ordering
I am working on the output for some data and I would like to manually assign the order as there is no field that I can order by that will give me the desired output. Is there a way to manually declare the order of output based on the PKs of an entry? -- 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.
Multi-user environment where users can add/edit/delete only their own posts
hello all, I'm considering Django for one of my projects but I run into an issue. Suppose I have a multi-user environment (like craigslist) where users can register and, let's say, write posts and create photo galleries. I want a user to be able to edit his or her own posts and galleries. I want all posts and galleries to be viewable by all. How would I do that in Django? In another framework, I'd have User hasMany Post, Post belongsTo User, and then in the controller in action Post/edit/post_id, I'd compare Post.user_id to that from the session of the authenticated user, and kick him out if his id doesn't match. But in Django I'm not sure how to do that. Your help is much appreciated. -- 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: login_required and new class based views
Let me add that the decorator_from_middleware call all the middleware process_* functions if available but these will ofcourse be called at a whole different point in time then the actual middleware. Normally middleware is woven through the whole dispatch process, as a decorator it's wrapped around the view. On Oct 20, 1:12 pm, Russell Keith-Mageewrote: > 2010/10/20 Łukasz Rekucki : > > > On 19 October 2010 19:06, Valentin Golev wrote: > >> Hello, > > > 2) decorate the dispatch method. You need to turn login_required into > > a method decorator first (Django should probably provide a tool for > > this). > > Django does :-) It's called method_decorator. > > from django.utils.decorators import method_decorator > > class MyDecoratedView(MyView): > > @method_decorator(login_required) > def dispatch(self, *args, **kwargs): > #... > > This works for any method on any class, that you want to decorate with > any function-based decorator. > > As a point of interest, the django.utils.decorators module has a > couple of other useful utilities in this vein, such as > decorator_from_middleware (which, predictably, enables you to turn any > middleware into a decorator that wraps a single view). > > 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-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.
django.contrib.auth password reset reveals the user id
Hi, I'd like to use contrib.auth's password reset feature, but wouldn't like to expose my user id. Since user ids (even if they start at an arbitrary number) can be used to deduce the size of the userbase and growth rate, I think it's easy enough to justify this at least as an option. To fix this, I'd like to suggest the token generator (see django.contrib.auth.tokens) be made in charge of creating a single token of whatever form it wishes, and the token would be the only information revealed to the user. The token generator will also be incharge of receiving the token, and returning a user object if the token is valid. If you will look at django.contrib.auth.forms.PasswordResetForm, you will see it sends the user both the uid (encoded to base36) and the token, and the token generator expects to be fed the user object from the outside. Does this make sense? I don't mind submitting a patch, but it will break custom token generators' APIs (or we add a somewhat ugly backwards-compatibility check). At the moment, I believe I'm forced to replace the whole form and the token generator, as well as wrap the view. - Yaniv -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Problems displaying image objects in a Django template using a custom template tag? (coding included)
I have the following code that fails to display object images. But displays normal images fine. My Model class News(models.Model): title--- image = models.ImageField(upload_to='images') body Template tag coding from django import template register = template.Library() from .models import --- def funct(num): myobjects = News.objects.all()[:num] return {'objects': myobjects} register.inclusion_tag('news/template.html')(funct) template coding {% for object in objects %} {{ object.title }} {{ object.body }} {% endfor %} This code outputs all the variable information such as title and body in a list however it does not display the associated image. I have tried numerous variations on this code with no success. This is strange because when an image is called from the image folder in the following manner Everything works fine. The problems occur when its a model image being called. Any help fixing this issue is much appreciated -- 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.
dump sqlite to file when testing
Hi everyone, Is there any way to force sqlite3 to use a file instead of RAM when running tests? I would like to access the DB somehow to check some fields. This is the only DB engine I have in this machine. Thanks, Best regards Miguel Araujo -- 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.
Oracle Database Other User Tables/Views
Hello, I am using Django's multiple database support to connect to an existing Oracle database (10g). I do not have control of the schema nor do I have any other privileges beyond SELECT. Further, the tables and views that I have access to are owned by a different user. Because of this I'm having to refer to these tables in queries using the other_user.table syntax. This issue is that Django's Oracle backend wants to quote all table names. This does not work for the other_user.table syntax. To get this working for the moment, I have patched the quote_name method on line 192 of django/db/backends/oracle/base.py to forego the quoting. Does anyone have any suggestions of how to work around this without modifying the Django source? Thanks, Chris -- 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: Updating a video rating using AJAX
When you change data on your database ALWAYS use the http POST method. So your view should check if request.method == 'POST' and then proceed to change the rating. It should also check if the user is authenticated and if she already voted. As for the ajax part have a look at the jQuery javascript library. You could do something like this: $('#my_form').live('submit',function(){ var self = $this; $.post( self.attr('action'), function(r){ self.replaceWith( $(r).find('#my_form') ); }); return false; }); The javascript code you should write depends on how your app and views work. The above snippet assumes that the url where the form submits will return the form (even if there is an error). On Oct 20, 4:23 pm, Sithembewena Lloyd Dubewrote: > Hi all, > > I have a page where users can rate a video, and in models.py I have a video > model with a 'rating' property. I wish to find out how I can AJAXify the > rating button on the page, so that if a user clicks on it, the button can > call a custom function and pass the video id (cannot call a view as that > would return an entire response). Am thinking of a function roughly as > follows: > > from myproject.myapp.models import Video > > def save_rating(video_id, rating): > video = Video.objects.filter(pk=video_id) > video.rating += rating > video.save() > return video.rating #* The rating label on the page would then be > updated with the returned rating.* > > I would like to do this without using a view or doing a form POST or GET of > any kind. Any pointers? > > Thanks. > > -- > Regards, > Sithembewena Lloyd Dubehttp://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Expense of django query
Brilliant. Thanks! On Oct 20, 9:41 am, Javier Guerra Giraldezwrote: > On Wed, Oct 20, 2010 at 7:59 AM, Ed wrote: > > what is the purpose of ifchanged? > > since the images are sorted by film, if you just show the film for > every image it would be repeated. with {% ifchanged %} it's only > shown before all the images for this film, so the result is like this: > > film A > image a.1 > image a.2 > film B > image b.1 > image b.2 > image b.3 > film C > > > without {% ifchanged %} you would get: > film A > image a.1 > film A > image a.2 > film B > image b.1 > film B > image b.2 > film B > image b.3 > film C > ... > > -- > Javier -- 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: rake routes
There is also a very useful project out there called django-command- extensions http://code.google.com/p/django-command-extensions/ you can install that. Along with a gaggle of things you will have a show_urls command python manage.py show_urls will print out all of the urls from all of the apps in your installed apps On Oct 19, 8:20 pm, Phlipwrote: > A web platform which I will refer to as "Rails" lets you print out all > the equivalents of the matchers and modules in the tree of urls.py > files using "rake routes". > > Does Django have such a command? Or how could one be written? > > -- > Phlip > http://bit.ly/ZeekLand -- 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: Updating a video rating using AJAX
Also, if you DO choose to pass JSON back to your client, you should serialize it first. See this: http://docs.djangoproject.com/en/dev/topics/serialization/ -- 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: Updating a video rating using AJAX
On Oct 20, 8:23 am, Sithembewena Lloyd Dubewrote: > Hi all, > > I have a page where users can rate a video, and in models.py I have a video > model with a 'rating' property. I wish to find out how I can AJAXify the > rating button on the page, so that if a user clicks on it, the button can > call a custom function and pass the video id (cannot call a view as that > would return an entire response). Am thinking of a function roughly as > follows: > > from myproject.myapp.models import Video > > def save_rating(video_id, rating): > video = Video.objects.filter(pk=video_id) > video.rating += rating > video.save() > return video.rating #* The rating label on the page would then be > updated with the returned rating.* > > I would like to do this without using a view or doing a form POST or GET of > any kind. Any pointers? AJAX does in fact do a POST or GET. So you do need to make a view function that your javascript can issue a POST to update the rating. Your javascript will need to pass the video ID to the view somehow, either as part of the URL or as a POST parameter. Your view then needs to return a response to the javascript, and you can do this as either plain old text, JSON, XML, or HTML, depending on what makes the most sense for you. I'd recommend you use a javascript library like jQuery, simply because these libraries hide some of the very tedious things you have to do if you were to code the request by hand. I'd suggest you take a look at some jQuery AJAX tutorials on the web. -- 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: Updating a video rating using AJAX
> I would like to do this without using a view or doing a form POST or GET of > any kind. Any pointers? Why? If you're building a web app, you should use HTTP to for the client to communicate with the app (AJAX is just another form of that communication). You're almost there, though, because your function is pretty close to a view: def save_rating(request, video_id, rating): if request.is_ajax(): # the rest of your code... json_content = '{"rating":"%s"}' % video.rating return HttpResponse(json_content, mimetype='application/json') Just be sure to return some sort of data that your client-side javascript can interpret, such as JSON (of which I've given you an untested example). -- 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: Expense of django query
On Wed, Oct 20, 2010 at 7:59 AM, Edwrote: > what is the purpose of ifchanged? since the images are sorted by film, if you just show the film for every image it would be repeated. with {% ifchanged %} it's only shown before all the images for this film, so the result is like this: film A image a.1 image a.2 film B image b.1 image b.2 image b.3 film C without {% ifchanged %} you would get: film A image a.1 film A image a.2 film B image b.1 film B image b.2 film B image b.3 film C ... -- Javier -- 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: DRY forms
Does your form look like: MyForm (ModelForm): Meta: fields: ['one', 'second'] it updates only those fields listed in meta tag. Other fields aren't touched. On Oct 20, 9:16 am, simontywrote: > Hello, > I have a database table with about 100 fields. > I have a number of forms with only a few fields in each form based on > the fields in the table. > If I create one massive django model to represent the table and a > number of modelforms based on > the django model, this becomes inefficent because every time I update > one of my small modelforms ( > which contain only a few fields), all fields in the table will get > updated. I can see this when I inspect the > sql query. > Alternatively I can create small django models and base my modelforms > on those but this isn't very DRY. > Its a alot of work. > Ideally, when I call save() on my modelform, I only want the fields on > my form to be updated. This makes sense because I am saving the > information in the form, not the entire model. > Could anyone make any suggestions for the above scenario? > Many 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.
Registering a ModelAdmin, but with a different URL
Hey guys, This is my first post in here, and I'm also rather new to Django and a lot of things are still new to me. I'm also very confused going around the documentation, so I'd like to ask directly what should I do. Basically, what I want to do is very very simple really, but I can't exactly find in the documentation what to do. First, for the scope of my question, I have 2 models, "Response" and "Request". A Request object can have multiple Responses. In the "Response" model. Secondly, what I'm trying to achieve is to register both models in the Admin form. But with an exception: that the "Response" model doesn't show-up in the list of models that the admin backend can manage, but show it within /admin/my_app/request/1/response/ ... That is, the list of response can only be related to the give request ... in the example above, I would like to show a list of Responses that are belonging to Response with pk=1. The problem that I'm facing is that if I register the Response (admin.site.register(Response)) then the Request and Response would be shown in the main admin page, which is not I'm looking for. Now, I'm not sure how would I go about displaying the Responses in that /admin/my_app/request/1/response/ and have it use the default admin interface (look and feel, links, add button, ...) but only relevant to the Request that is being worked on. Thanks for any response, Elie -- 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.
Updating a video rating using AJAX
Hi all, I have a page where users can rate a video, and in models.py I have a video model with a 'rating' property. I wish to find out how I can AJAXify the rating button on the page, so that if a user clicks on it, the button can call a custom function and pass the video id (cannot call a view as that would return an entire response). Am thinking of a function roughly as follows: from myproject.myapp.models import Video def save_rating(video_id, rating): video = Video.objects.filter(pk=video_id) video.rating += rating video.save() return video.rating #* The rating label on the page would then be updated with the returned rating.* I would like to do this without using a view or doing a form POST or GET of any kind. Any pointers? Thanks. -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Displaying a template table using a query set
Hi Pranav, I think what Steve was saying is that if you go back to your original template and view: {% for row in table_data %} {% for value in row %} {{ row }} {% endfor %} {% endfor %} and you know, for instance, what fields you want to display and how (like your id field) that you don't need to first go to a list (this is assuming the view you first posted, not the one that goes to a list): {% for row in table_data %} {{ row.id }} {% endfor %} which is how you proposed to fix the list based situation the second time (i.e. how you are thinking it should work is how django actually works if you don't force it to go through the list step). Hope this helps, -- Casey On 10/20/2010 09:07 AM, Pranav wrote: On Oct 20, 5:24 pm, Steve Holdenwrote: On 10/20/2010 7:58 AM, Pranav wrote: On Oct 20, 4:13 pm, Daniel Roseman wrote: On Oct 20, 8:29 am, Pranav wrote: I'm trying to display a table in template using the result retrieved from a query set, but i get problem when i try to display the table iterating through each row'' and column'' view file: from django.shortcuts import get_object_or_404, render_to_response from models import Organization def startpage(request): table_data = Organization.objects.all() return render_to_response('display_table.html', {'table_data': table_data}) display_table template file: {% for row in table_data %} {% for value in row %} {{ row }} {% endfor %} {% endfor %} when i try to run this i get an error saying the object is not itreable for the second for loop. please provide a solution to this issue... Thanks and Regards Pranav `value` is an Organisation instance, and model instances are not iterable, as you could see by trying it in the shell. You could try passing a values_list instead of a queryset: table_data = Organization.objects.all().values_list() as these are iterable. -- DR. Hi Dan, Thanks for the fix it worked. I guess Organization.objects.all().values_list() returns a list. But what if i want to refer to a particular field say Organization.id inside my template? like: {% for row in table_data %} {{ row.Organization.id }} <% endfor %} I guess I'll have to pass another query set object to do this, will this have any effect on the throughput of the database? Is it possible to access cached result of the query set inside the template? The point is that normally you don't just want to iterate over the columns of a retrieved row, since they have differences in meaning that normally require differences in display formatting and the like as well. Therefore the solution you offer above is more or less what you actually do. regards Steve -- DjangoCon US 2010 September 7-9http://djangocon.us/ Hi Steve, I know its a bit odd to display only a column of a table, but thats the only way i can display a href list and a full fledged table next to each other. I guess I'll just have to go with passing 2 query set objects -- 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: Displaying a template table using a query set
On Oct 20, 5:24 pm, Steve Holdenwrote: > On 10/20/2010 7:58 AM, Pranav wrote: > > > > > > > On Oct 20, 4:13 pm, Daniel Roseman wrote: > >> On Oct 20, 8:29 am, Pranav wrote: > > >>> I'm trying to display a table in template using the result retrieved > >>> from a query set, but i get problem when i try to display the table > >>> iterating through each row'' and column'' > > >>> view file: > >>> from django.shortcuts import get_object_or_404, render_to_response > >>> from models import Organization > > >>> def startpage(request): > >>> table_data = Organization.objects.all() > >>> return render_to_response('display_table.html', {'table_data': > >>> table_data}) > > >>> display_table template file: > >>> > >>> {% for row in table_data %} > >>> > >>> {% for value in row %} > >>> > >>> {{ row }} > >>> > >>> {% endfor %} > >>> > >>> {% endfor %} > >>> > > >>> when i try to run this i get an error saying the object is not > >>> itreable for the second for loop. please provide a solution to this > >>> issue... > > >>> Thanks and Regards > >>> Pranav > > >> `value` is an Organisation instance, and model instances are not > >> iterable, as you could see by trying it in the shell. > > >> You could try passing a values_list instead of a queryset: > >> table_data = Organization.objects.all().values_list() > >> as these are iterable. > >> -- > >> DR. > > > Hi Dan, > > Thanks for the fix it worked. > > I guess Organization.objects.all().values_list() returns a list. > > But what if i want to refer to a particular field say Organization.id > > inside my template? > > > like: > > > > {% for row in table_data %} > > > > > > {{ row.Organization.id }} > > > > > > <% endfor %} > > > > > I guess I'll have to pass another query set object to do this, > > will this have any effect on the throughput of the database? > > Is it possible to access cached result of the query set inside the > > template? > > The point is that normally you don't just want to iterate over the > columns of a retrieved row, since they have differences in meaning that > normally require differences in display formatting and the like as well. > > Therefore the solution you offer above is more or less what you actually > do. > > regards > Steve > -- > DjangoCon US 2010 September 7-9http://djangocon.us/ Hi Steve, I know its a bit odd to display only a column of a table, but thats the only way i can display a href list and a full fledged table next to each other. I guess I'll just have to go with passing 2 query set objects -- 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: Expense of django query
Thanks for the suggestion. Javier's was exactly what I needed. The one question I have is why what is the purpose of ifchanged? I'm aware of the command but I don't see the purpose of it within a loop. On Oct 20, 5:18 am, Daniel Rosemanwrote: > On Oct 19, 9:46 pm, Ed wrote: > > > > > > > Thanks for the answers. I thought that the view was already pulling > > the data. I didn't realize it gets pulled when called in the > > template. I was able to rewrite the view to provide the data more > > efficiently. > > > I have another related question on the topic of query expense. What > > is the best practice as far as database table design? > > > I have 3 tables: studio, film, images. If film has a foreign key to > > studio, and images has a foreign key to film. If I wanted to pull all > > of the images for a particular studio, it would be more expensive to > > pull: > > > all films (given studio), and then films.images_set > > > as opposed to: > > > including the studio in the image table and then pulling all images > > (given studio). > > > But there is some data replication here. Technically, I can discover > > studio by following the link from image to film to studio. But it I > > need less queries given this particular need. What is the best > > practice in a scenario like this? > > Well, as you've realised, iterating through each film to get its > images will fire off one query per film. But how to do it efficiently > depends on what you're doing with the data. If you just need all > images for one studio, and don't care about the films, then one query > will suffice: > > Image.objects.filter(film__studio=mystudio) > > If you need all studios and their related images, it's a bit more > difficult. One way of doing it would be to use the queryset `extra` > clause to add a studio ID to each image, group them by that ID, then > studios appending the image list to each one. I can post some code if > that's the sort of thing you need to do. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DRY forms
Apologies, I seem to have misunderstood the situation in my haste to be of assistance. I admit I'm no Django/Python whiz, more of a talented(?) dabbler. Maybe someone else can correct me, but it seems that save() will always hit the entire row if you use a single model. Does save(f It seems a bit hacky, but what about creating a method to parse the modelform's inner Meta.fields then generate and execute a custom UPDATE statement? This might be a bit more difficult if you're using exclude rather than fields. To keep it DRY attach this method to a subclass of modelform then make your existing modelforms subclasses of this. This seems like a lot more work than aught be necessary, so you may be best off waiting for someone more knowledgeable than me to chime in. On Wed, Oct 20, 2010 at 3:34 AM, simontywrote: > I can't change the database design. Even if I could, that would still > mean I would have to define a model and a modelform for each table, > no? > > On Oct 20, 6:13 pm, srb...@gmail.com wrote: > > Can you just break the table up into several tables connected with > one-to-one relations? Maybe look at the model forms you're using the most as > a guide for which fields to include in the new tables? > > Sent from my Verizon Wireless BlackBerry > > > > -Original Message- > > From: simonty > > > > Sender: django-users@googlegroups.com > > Date: Tue, 19 Oct 2010 23:16:38 > > To: Django users > > Reply-To: django-users@googlegroups.com > > Subject: DRY forms > > > > Hello, > > I have a database table with about 100 fields. > > I have a number of forms with only a few fields in each form based on > > the fields in the table. > > If I create one massive django model to represent the table and a > > number of modelforms based on > > the django model, this becomes inefficent because every time I update > > one of my small modelforms ( > > which contain only a few fields), all fields in the table will get > > updated. I can see this when I inspect the > > sql query. > > Alternatively I can create small django models and base my modelforms > > on those but this isn't very DRY. > > Its a alot of work. > > Ideally, when I call save() on my modelform, I only want the fields on > > my form to be updated. This makes sense because I am saving the > > information in the form, not the entire model. > > Could anyone make any suggestions for the above scenario? > > Many thanks. > > > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > > For more options, visit this group athttp:// > groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- 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: Displaying a template table using a query set
On 10/20/2010 7:58 AM, Pranav wrote: > > > On Oct 20, 4:13 pm, Daniel Rosemanwrote: >> On Oct 20, 8:29 am, Pranav wrote: >> >> >> >> >> >>> I'm trying to display a table in template using the result retrieved >>> from a query set, but i get problem when i try to display the table >>> iterating through each row'' and column'' >> >>> view file: >>> from django.shortcuts import get_object_or_404, render_to_response >>> from models import Organization >> >>> def startpage(request): >>> table_data = Organization.objects.all() >>> return render_to_response('display_table.html', {'table_data': >>> table_data}) >> >>> display_table template file: >>> >>> {% for row in table_data %} >>> >>> {% for value in row %} >>> >>> {{ row }} >>> >>> {% endfor %} >>> >>> {% endfor %} >>> >> >>> when i try to run this i get an error saying the object is not >>> itreable for the second for loop. please provide a solution to this >>> issue... >> >>> Thanks and Regards >>> Pranav >> >> `value` is an Organisation instance, and model instances are not >> iterable, as you could see by trying it in the shell. >> >> You could try passing a values_list instead of a queryset: >> table_data = Organization.objects.all().values_list() >> as these are iterable. >> -- >> DR. > > Hi Dan, > Thanks for the fix it worked. > I guess Organization.objects.all().values_list() returns a list. > But what if i want to refer to a particular field say Organization.id > inside my template? > > like: > > {% for row in table_data %} > > > {{ row.Organization.id }} > > > <% endfor %} > > > I guess I'll have to pass another query set object to do this, > will this have any effect on the throughput of the database? > Is it possible to access cached result of the query set inside the > template? > The point is that normally you don't just want to iterate over the columns of a retrieved row, since they have differences in meaning that normally require differences in display formatting and the like as well. Therefore the solution you offer above is more or less what you actually do. regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- 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: Different logins in same browser session and login_required
> > > It shouldn't happen, but it could. It's an office or it's a warehouse, > > people could work with the same user and/or (above all) people may > > work on the same machine...so they should pay attention on what they > > do...but even no. > > > Just an example when the problem can occurs: > > The djangoapp has more users, some of these have privileges to access > > the django-admin to change some user permissions > > > With just one opened browser window the user U1 (not superuser/staff) > > is logged on, then going on the django-admin (in a new window because > > the link opened there, or jsut the user opened a new window by himself > > or whatever) a login is required. Logging on with a different user, > > the first window still seems (especially when the whole application is > > ajax based) to use the U1 user and something of not expected (to the > > user) may occurs. > > > I understand it's normal, the end-user may not. > > In which case the solution is to instruct them not to share logins, > which they would have to do to experience those problems. > > I agree it can be a pain when they do that, but if they are so > unsophisticated that they let two different users interact with the > system through a single login account they must expect trouble with > authenticated systems. > > As is so often the case, education is the answer. And, as is so often > the case, the users would rather sacrifice security for convenience > (then make it the system designer's fault when they realize they can't > have both). > > regards > Steve > > -- > DjangoCon US 2010 September 7-9http://djangocon.us/ 100% agree! If it were for me the thing would have already been stopped here! :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-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: Displaying a template table using a query set
On Oct 20, 4:13 pm, Daniel Rosemanwrote: > On Oct 20, 8:29 am, Pranav wrote: > > > > > > > I'm trying to display a table in template using the result retrieved > > from a query set, but i get problem when i try to display the table > > iterating through each row'' and column'' > > > view file: > > from django.shortcuts import get_object_or_404, render_to_response > > from models import Organization > > > def startpage(request): > > table_data = Organization.objects.all() > > return render_to_response('display_table.html', {'table_data': > > table_data}) > > > display_table template file: > > > > {% for row in table_data %} > > > > {% for value in row %} > > > > {{ row }} > > > > {% endfor %} > > > > {% endfor %} > > > > > when i try to run this i get an error saying the object is not > > itreable for the second for loop. please provide a solution to this > > issue... > > > Thanks and Regards > > Pranav > > `value` is an Organisation instance, and model instances are not > iterable, as you could see by trying it in the shell. > > You could try passing a values_list instead of a queryset: > table_data = Organization.objects.all().values_list() > as these are iterable. > -- > DR. Hi Dan, Thanks for the fix it worked. I guess Organization.objects.all().values_list() returns a list. But what if i want to refer to a particular field say Organization.id inside my template? like: {% for row in table_data %} {{ row.Organization.id }} <% endfor %} I guess I'll have to pass another query set object to do this, will this have any effect on the throughput of the database? Is it possible to access cached result of the query set inside the template? -- 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: Different logins in same browser session and login_required
On 10/20/2010 5:20 AM, PyMan wrote: > > > On 20 Ott, 10:28, Daniel Rosemanwrote: >> On Oct 20, 8:11 am, PyMan wrote: >> Firefox has long had its "profile" functionality. >> firefox -no-remote -ProfileManager >> You can create multiple firefox profiles, then run multiple instances of firefox at once - so long as you use different profiles for them. A bit fiddly, but obviously useful for development/testing. >> >>> First of all thanks for your answers to both of you :) >> >>> Yeah, I know about FX profiles and I already knew it was a working >>> solution, but it's not a good solution. I mean we're speaking about >>> users that don't even know what a browser is. Telling them to do that >>> is just mess. >> >> What's your case for getting end users to log in as two separate >> profiles? If they're non-technical, they shouldn't have to be worrying >> about this level of detail in any case. It's going to be confusing for >> them no matter what you do. >> -- >> DR. > > It shouldn't happen, but it could. It's an office or it's a warehouse, > people could work with the same user and/or (above all) people may > work on the same machine...so they should pay attention on what they > do...but even no. > > Just an example when the problem can occurs: > The djangoapp has more users, some of these have privileges to access > the django-admin to change some user permissions > > With just one opened browser window the user U1 (not superuser/staff) > is logged on, then going on the django-admin (in a new window because > the link opened there, or jsut the user opened a new window by himself > or whatever) a login is required. Logging on with a different user, > the first window still seems (especially when the whole application is > ajax based) to use the U1 user and something of not expected (to the > user) may occurs. > > I understand it's normal, the end-user may not. > In which case the solution is to instruct them not to share logins, which they would have to do to experience those problems. I agree it can be a pain when they do that, but if they are so unsophisticated that they let two different users interact with the system through a single login account they must expect trouble with authenticated systems. As is so often the case, education is the answer. And, as is so often the case, the users would rather sacrifice security for convenience (then make it the system designer's fault when they realize they can't have both). regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- 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: Displaying a template table using a query set
On Oct 20, 8:29 am, Pranavwrote: > I'm trying to display a table in template using the result retrieved > from a query set, but i get problem when i try to display the table > iterating through each row'' and column'' > > view file: > from django.shortcuts import get_object_or_404, render_to_response > from models import Organization > > def startpage(request): > table_data = Organization.objects.all() > return render_to_response('display_table.html', {'table_data': > table_data}) > > display_table template file: > > {% for row in table_data %} > > {% for value in row %} > > {{ row }} > > {% endfor %} > > {% endfor %} > > > when i try to run this i get an error saying the object is not > itreable for the second for loop. please provide a solution to this > issue... > > Thanks and Regards > Pranav `value` is an Organisation instance, and model instances are not iterable, as you could see by trying it in the shell. You could try passing a values_list instead of a queryset: table_data = Organization.objects.all().values_list() as these are iterable. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: login_required and new class based views
2010/10/20 Łukasz Rekucki: > On 19 October 2010 19:06, Valentin Golev wrote: >> Hello, >> > 2) decorate the dispatch method. You need to turn login_required into > a method decorator first (Django should probably provide a tool for > this). Django does :-) It's called method_decorator. from django.utils.decorators import method_decorator class MyDecoratedView(MyView): @method_decorator(login_required) def dispatch(self, *args, **kwargs): #... This works for any method on any class, that you want to decorate with any function-based decorator. As a point of interest, the django.utils.decorators module has a couple of other useful utilities in this vein, such as decorator_from_middleware (which, predictably, enables you to turn any middleware into a decorator that wraps a single view). 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-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.
BrightonPy event: The Why and How of Automated Testing with Python and Django
Hi all, I thought our next BrightonPy meeting might be of interest to this list: The Why and How of Automated Testing with Python and Django Jim Purbrick, Tuesday October 26, 2010, 19:30 at The Skiff http://brightonpy.org/meetings/2010-10-26/ Why do we write tests? How do we write them? What kinds of tests are valuable? Learn and share your experiences of how to do Test Driven Development in Python and Django. The evening will start with a talk by agile software veteran Jim Purbrick followed by a hands-on practical session led by Alan McNeil Jackson, CTO of Aptivate. Bring a laptop if you want to code along. Please sign up on Upcoming or Lanyrd if you will be attending: http://upcoming.yahoo.com/event/7193208/ http://lanyrd.com/2010/brightonpy-october/ -- 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.
Displaying a template table using a query set
I'm trying to display a table in template using the result retrieved from a query set, but i get problem when i try to display the table iterating through each row'' and column'' view file: from django.shortcuts import get_object_or_404, render_to_response from models import Organization def startpage(request): table_data = Organization.objects.all() return render_to_response('display_table.html', {'table_data': table_data}) display_table template file: {% for row in table_data %} {% for value in row %} {{ row }} {% endfor %} {% endfor %} when i try to run this i get an error saying the object is not itreable for the second for loop. please provide a solution to this issue... Thanks and Regards Pranav -- 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.
distinct in autocomplete
Hello, how do I get only distinct values of that query in the autocomplete field: def autocomplete_techlastname(request): if request.GET.has_key('q'): tags = Item.objects.filter(techlastname__icontains=request.GET['q']) [:5] return HttpResponse('\n'.join(tag.techlastname for tag in tags)) return HttpResponse() appending distinct seems not to work. -- 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: Different logins in same browser session and login_required
On 20 Ott, 10:28, Daniel Rosemanwrote: > On Oct 20, 8:11 am, PyMan wrote: > > > > Firefox has long had its "profile" functionality. > > > > firefox -no-remote -ProfileManager > > > > You can create multiple firefox profiles, then run multiple instances of > > > firefox at once - so long as you use different profiles for them. A bit > > > fiddly, but obviously useful for development/testing. > > > First of all thanks for your answers to both of you :) > > > Yeah, I know about FX profiles and I already knew it was a working > > solution, but it's not a good solution. I mean we're speaking about > > users that don't even know what a browser is. Telling them to do that > > is just mess. > > What's your case for getting end users to log in as two separate > profiles? If they're non-technical, they shouldn't have to be worrying > about this level of detail in any case. It's going to be confusing for > them no matter what you do. > -- > DR. It shouldn't happen, but it could. It's an office or it's a warehouse, people could work with the same user and/or (above all) people may work on the same machine...so they should pay attention on what they do...but even no. Just an example when the problem can occurs: The djangoapp has more users, some of these have privileges to access the django-admin to change some user permissions With just one opened browser window the user U1 (not superuser/staff) is logged on, then going on the django-admin (in a new window because the link opened there, or jsut the user opened a new window by himself or whatever) a login is required. Logging on with a different user, the first window still seems (especially when the whole application is ajax based) to use the U1 user and something of not expected (to the user) may occurs. I understand it's normal, the end-user may not. -- 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: Expense of django query
On Oct 19, 9:46 pm, Edwrote: > Thanks for the answers. I thought that the view was already pulling > the data. I didn't realize it gets pulled when called in the > template. I was able to rewrite the view to provide the data more > efficiently. > > I have another related question on the topic of query expense. What > is the best practice as far as database table design? > > I have 3 tables: studio, film, images. If film has a foreign key to > studio, and images has a foreign key to film. If I wanted to pull all > of the images for a particular studio, it would be more expensive to > pull: > > all films (given studio), and then films.images_set > > as opposed to: > > including the studio in the image table and then pulling all images > (given studio). > > But there is some data replication here. Technically, I can discover > studio by following the link from image to film to studio. But it I > need less queries given this particular need. What is the best > practice in a scenario like this? Well, as you've realised, iterating through each film to get its images will fire off one query per film. But how to do it efficiently depends on what you're doing with the data. If you just need all images for one studio, and don't care about the films, then one query will suffice: Image.objects.filter(film__studio=mystudio) If you need all studios and their related images, it's a bit more difficult. One way of doing it would be to use the queryset `extra` clause to add a studio ID to each image, group them by that ID, then studios appending the image list to each one. I can post some code if that's the sort of thing you need to do. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Different logins in same browser session and login_required
On Oct 20, 8:11 am, PyManwrote: > > Firefox has long had its "profile" functionality. > > > firefox -no-remote -ProfileManager > > > You can create multiple firefox profiles, then run multiple instances of > > firefox at once - so long as you use different profiles for them. A bit > > fiddly, but obviously useful for development/testing. > > First of all thanks for your answers to both of you :) > > Yeah, I know about FX profiles and I already knew it was a working > solution, but it's not a good solution. I mean we're speaking about > users that don't even know what a browser is. Telling them to do that > is just mess. What's your case for getting end users to log in as two separate profiles? If they're non-technical, they shouldn't have to be worrying about this level of detail in any case. It's going to be confusing for them no matter what you do. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DRY forms
I can't change the database design. Even if I could, that would still mean I would have to define a model and a modelform for each table, no? On Oct 20, 6:13 pm, srb...@gmail.com wrote: > Can you just break the table up into several tables connected with one-to-one > relations? Maybe look at the model forms you're using the most as a guide for > which fields to include in the new tables? > Sent from my Verizon Wireless BlackBerry > > -Original Message- > From: simonty> > Sender: django-users@googlegroups.com > Date: Tue, 19 Oct 2010 23:16:38 > To: Django users > Reply-To: django-users@googlegroups.com > Subject: DRY forms > > Hello, > I have a database table with about 100 fields. > I have a number of forms with only a few fields in each form based on > the fields in the table. > If I create one massive django model to represent the table and a > number of modelforms based on > the django model, this becomes inefficent because every time I update > one of my small modelforms ( > which contain only a few fields), all fields in the table will get > updated. I can see this when I inspect the > sql query. > Alternatively I can create small django models and base my modelforms > on those but this isn't very DRY. > Its a alot of work. > Ideally, when I call save() on my modelform, I only want the fields on > my form to be updated. This makes sense because I am saving the > information in the form, not the entire model. > Could anyone make any suggestions for the above scenario? > Many thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DRY forms
Can you just break the table up into several tables connected with one-to-one relations? Maybe look at the model forms you're using the most as a guide for which fields to include in the new tables? Sent from my Verizon Wireless BlackBerry -Original Message- From: simontySender: django-users@googlegroups.com Date: Tue, 19 Oct 2010 23:16:38 To: Django users Reply-To: django-users@googlegroups.com Subject: DRY forms Hello, I have a database table with about 100 fields. I have a number of forms with only a few fields in each form based on the fields in the table. If I create one massive django model to represent the table and a number of modelforms based on the django model, this becomes inefficent because every time I update one of my small modelforms ( which contain only a few fields), all fields in the table will get updated. I can see this when I inspect the sql query. Alternatively I can create small django models and base my modelforms on those but this isn't very DRY. Its a alot of work. Ideally, when I call save() on my modelform, I only want the fields on my form to be updated. This makes sense because I am saving the information in the form, not the entire model. Could anyone make any suggestions for the above scenario? Many 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. -- 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: Different logins in same browser session and login_required
> > Firefox has long had its "profile" functionality. > > firefox -no-remote -ProfileManager > > You can create multiple firefox profiles, then run multiple instances of > firefox at once - so long as you use different profiles for them. A bit > fiddly, but obviously useful for development/testing. First of all thanks for your answers to both of you :) Yeah, I know about FX profiles and I already knew it was a working solution, but it's not a good solution. I mean we're speaking about users that don't even know what a browser is. Telling them to do that is just mess. -- 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.
DRY forms
Hello, I have a database table with about 100 fields. I have a number of forms with only a few fields in each form based on the fields in the table. If I create one massive django model to represent the table and a number of modelforms based on the django model, this becomes inefficent because every time I update one of my small modelforms ( which contain only a few fields), all fields in the table will get updated. I can see this when I inspect the sql query. Alternatively I can create small django models and base my modelforms on those but this isn't very DRY. Its a alot of work. Ideally, when I call save() on my modelform, I only want the fields on my form to be updated. This makes sense because I am saving the information in the form, not the entire model. Could anyone make any suggestions for the above scenario? Many 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.