Re: New to Django-Installation problem
Are you using python 3? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to Generate a 5 character unique alpha-numeric string
Well, I don't think it is safe but you can first retrive Max('pk') then, you can increment its base 36 related number then use the result's string equivalent. Le 11/04/2011 08:48, GKR a écrit : I meant to say not random. serial eg: .. .. 2A00A 2A00B .. .. .. 2A00Z 2A010 2A011 .. ... 2A019 2A01A 2A01B -- -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Uso de subconsultas
Hello, Maybe you mean: >>> result = A.objects.select_related().annotate(num_b=Count('b')).aggregate(max_num_b=Max(num_b)) >>> result['max_num_b'] In that case, you take each A value, count for each its related B occurences, then retain the highest count. Regards, Le 06/04/2011 16:25, bernatbonet a écrit : Tengo el siguiente modelo de datos: class A(models.model): desc: model.CharField() class B(models.model): a: model.ForeignKey('A') desc: models.CharField() Tengo una vista que quiere sacar la siguiente select: select max(num_a) as max_num_a from (select a, count(desc) as num_a from B group by a) as x; He intentado hacer lo siguiente: result = B.objects.values('a').annotate(num_a=Count('a')).aggregate(Max('num_a')) Esto me da el siguiente error: 1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (SELECT `B`.a` AS `a`, COUNT(`a' at line 1") Si en lugar de obtener el máximo nos quedamos en la agrupación funciona: result = B.objects.values('a').annotate(num_a=Count('a')) y nos devuelve: {'a': 1L, 'num_a': 9}{'a': 2L, 'num_a': 6}{'a': 3L, 'num_a': 4} No se que estoy haciendo mal, ni si hay otra forma de resolver este problema. Si alguien se ha encontrado con el mismo problema y lo ha resuelto, le agradecería mucho que me diera unas pistas para solventarlo. Muchas gracias por todo. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Auto import files into database
IMHO, while dealing with database data modifications from a csv file, you should not let default commit on each save(). This will help you preserve data from accidents (if something is wrong inside the serie, maybe the serie shouldn't be processed) and you'll have better speed processing these modifcations. http://docs.djangoproject.com/en/dev/topics/db/transactions/ Le 20/03/2011 10:08, Daniel Roseman a écrit : On Sunday, March 20, 2011 1:04:46 AM UTC, Corey Farwell wrote: So would it look something along these lines: from app.models import NewModel # parse csv data here meow = NewModel(whatever = parsedData) meow.save() Where should this script live? Is there a general place django developers keep these scripts? If I want this script to run every x minutes, would a cron job be the best approach? You probably want a custom manage.py script: http://docs.djangoproject.com/en/1.2/howto/custom-management-commands/ This can be run from the command line or as a cron job. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Posted Screen Text Field Manipulation
Hank, Would you mind posting the link on the list? I may be wrong, but I believe that sending a message directly to someone is not in the "etiquette". You'll also help keeping this list stalker friendly. 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Defining global names
Hi, After seeing this [1], I use a "conf" package inside all my apps, with a 'settings.py' file. Done properly, this enables you to provide defaults with your apps while allowing to define custom settings at project level if iinside you apps.conf.settings you check first if this value is set at project level. By the way, I'd prefer to do: from myapp.conf.settings import CONST. Hope this helps. Regards, [1] http://michaeltrier.com/2008/02/02/django-screencasts-6---application-settings/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django templates: accessing list element attributes throws error
Hi, you can try {{ list.0.title }} 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Model with several ManyToManyFields - related_name problem
Hello, I believe you need related_name, for disambiguation at least. Maybe by setting a db_table you can bypass the related_name but I'm not convinced. Actually, I'm "parasiting" your post to ask when "[we]'d prefer Django didn't create a backwards relation"? 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: /admin weirdness
Hi Bobby, Maybe some mistake on your url.py, for example if you have an app named "app" and a model named "model", you'll try to get this url to add a new "model" /admin/app/model/add/ Usually, you'll write your urls.py like this: (r'^app/', include('app.urls')), (r'^admin/', include(admin.site.urls)), If you forget the "^" before app/, the url for adding a new model will match the regex 'app/', and the admin will be shorcut, Just a guess against the material you brought ;) 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to format the "value" attribute of an option in a Select List using the template language for loop
Well... here is the lin (right into the relevant section) : http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to format the "value" attribute of an option in a Select List using the template language for loop
Sorry again, Actually, the doc tell us the way [1]. Simply use {{ forloop.counter }} or {{ forloop.counter0 }}. 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to format the "value" attribute of an option in a Select List using the template language for loop
Hi, You'll probably need to prepare the "options" in your view; with enumerate(), for example (paginator may be a little too much, sorry). Regards, [1] http://docs.python.org/library/functions.html#enumerate Le 16/03/2011 04:18, Juan Gabriel Aldana Jaramillo a écrit : Hi, Check this link. http://www.djangobook.com/en/2.0/chapter19/ I think this is an example about what you are looking for: __ _{% for lang in LANGUAGES %} {{ lang.1 }} {% endfor %}_ __ On Tue, Mar 15, 2011 at 3:04 PM, werefr0g <weref...@yahoo.fr <mailto:weref...@yahoo.fr>> wrote: Hello, If you use a paginator [1], you'll prepare the "index number" in the view but this will provide all the context you need in your template. Regards, [1] http://docs.djangoproject.com/en/dev/topics/pagination/ -- 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 <mailto:django-users@googlegroups.com>. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com <mailto:django-users%2bunsubscr...@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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to format the "value" attribute of an option in a Select List using the template language for loop
Hello, If you use a paginator [1], you'll prepare the "index number" in the view but this will provide all the context you need in your template. Regards, [1] http://docs.djangoproject.com/en/dev/topics/pagination/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Initial save()
Hello, I'd rather check for self.pk as you can use primary_key argument on a field whatever is its name. 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to limit a ManyToManyField to three choices?
Well, MAX_CUISINES = 3 def clean(self): # three cuisines max. allowed if self.pk is None: # That's the case that raise the error # you're inserting a new Restaurant pass else: # Here, you're editing an existing Restaurant # (including its relashionship with Cuisine) if self.cuisines.count() > MAX_CUISINES: raise ValidationError('I said, "Choose up to three" cusines!') As we're aiming to prevent, at model's level, saving a new Restaurant when too many related Cuisine are provided, I'm afraid that doesn't fit the needs... unless saving restaurant's intance, run a validation then delete it if it fails the validation :) I'd like to place the validation at 'cusines' field level. I'm not confortable placing it at the "whole" model's level, despite my suggestion. I failed for the moment to find a way and I'll resume tomorrow. Maybe the following unsuccessful tries can help you (with a mix of admin interface playing and shell, both on dev server): * use validator on models.ManyToManyField: I can't even trigger a simple print('test') TT * use a custom field by extending models.ManyToManyField, overriding its isValidIDList method Ok, it is a blind test: I was looking for a way to access values from cuisines for a non saved instance of Restaurant and maybe something is lurking there. I'm a beginner. * accessing self's attributes for a non saved or retrieved instance of Restaurant # desesperately random commands (I tried more :): u = Restaurant() r = Restaurant.objects.all()[0] dir(u) # hey, a "cuisines" attribute, great! dir(u.cuisines) # TT, same error you encountered dir(r.cuisines) # fine u.clean_fields() # 'cusines' is not even mentionned in the error message r.clean_fields() # fine [f.verbose_name for f in r._meta.fields] # no cusines I believe that no control is enforced before saving, but if you try to create an new Restaurant and not provide a cuisine, the validation failed from the admin. How does it handle that? I'll try to find out. Is there a way to access data provided to 'cuisines' for an unsaved Restaurant? 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: test cannot find assertContains
Hi, As far I can tell from the documentation, to use Django's extended TestCase, you should use django.test.TestCase [1]. Using django.utils.unittest allows you to benefit from python 2.7 unittest2 library, [2] Regards, [1] http://docs.djangoproject.com/en/dev/topics/testing/#django.test.TestCase [2] http://docs.djangoproject.com/en/dev/topics/testing/#writing-unit-tests -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to limit a ManyToManyField to three choices?
Hello, Can Model.clean() method help you? [1] You'll still have to pay attention to validation before trying to save your instances.[2] Regards, [1] http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.clean [2] http://docs.djangoproject.com/en/dev/releases/1.2/#model-validation -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form/view for ManyToMany relationship
Le 05/03/2011 00:01, kgardenia42 a écrit : Thanks. This is pretty close to what I'm doing. However, I'd like to not have to write all the associated boiler-plate (i.e. I have to figure out if any film/actor relationships have been deleted since the last save and explicitly write code to remove those and so on). Well, you can delete all related filmrole then save the new set, but I don't know if it's really an "efficient" way to handle that. Out of topic: I have an obsession about providing "undo" ability as much as possible and showing changes before "committing" may help user too. It seems that I would even have this problem if I added a simple "auto now" date/time field to my relationship class, which seems a bit restrictive. Using a "timestamp" allows you to never edit / delete a entry: you just add new ones and work on last "timestamped" related entries for current data. I use this myself intensively because I _need_ to provide audit tables. I use in this case two apps: one "normal" (without timestamps) and an "audit" app that is dependant of the "normal" app. I use two distinct tables (databases, actually) and performances are ok in my context (including about 30,000 modifications by batch at once at least once a week). ModelForm already knows how to do all that (it can do so when the relationship class is implicitly created) so what I imagined was *somewhere* I could override a method and provide the defaults for the missing fields and then it would all just works magically.Does this make sense? Can anyone give me any pointers to how I might do this (I'm keen to learn the "right way" to do things). You can provide defaults in your Model. (I don't know if it's really required, but can use constants in these case: this allows to retrieve these entries without introducing more hardcoded values in your code) I'm happy to hack this myself and contribute something if someone could give me some pointers of where I should start or where something like this ought to live. I don't feel comfortable with your way to handle this relashionship, but it may be appropriate in a "wizard" approach. Maybe some form related project can appreciate your efforts. 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form/view for ManyToMany relationship
sorry, I failed to pass the request to the view's function,.. Le 04/03/2011 22:08, werefr0g a écrit : On Thu, Mar 3, 2011 at 11:50 AM, werefr0g <weref...@yahoo.fr> wrote: Hello, Sorry if I misunderstand, but what is wrong about using a ModelForm on your Film bounded to the film instance? My bad... how did I missed the intermediary model involved in the ManyToMany relashionship. Sorry. When I tried that I kept running into this error: "Cannot set values on a ManyToManyField which specifies an intermediary model. Use foo.FilmRole's Manager instead. As you are using an intermediary model, you must insert multiple FilmRole, one for each actor to this film, but you don't want using a formset, do you?. Is the following going toward your goal? # forms.py class FilmActorsForm(forms.Form): actors = forms.ModelMultipleChoiceField(queryset=Actors..., required=...) # views.py def assign_actors(film_id): film = get_object_or_404(Film, id=film_id) if request.method == 'POST': form = FilmActorsForm(request.POST) if form.is_valid(): chosen_actors = form.cleaned_data['actors'] current_actors = film.actors.all() # handle deletion / creation of filmroles return HttpResponseRedirect(...) else: form = FilmActorForm() 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form/view for ManyToMany relationship
On Thu, Mar 3, 2011 at 11:50 AM, werefr0g <weref...@yahoo.fr> wrote: Hello, Sorry if I misunderstand, but what is wrong about using a ModelForm on your Film bounded to the film instance? My bad... how did I missed the intermediary model involved in the ManyToMany relashionship. Sorry. When I tried that I kept running into this error: "Cannot set values on a ManyToManyField which specifies an intermediary model. Use foo.FilmRole's Manager instead. As you are using an intermediary model, you must insert multiple FilmRole, one for each actor to this film, but you don't want using a formset, do you?. Is the following going toward your goal? # forms.py class FilmActorsForm(forms.Form): actors = forms.ModelMultipleChoiceField(queryset=Actors..., required=...) # views.py def assign_actors(film_id): film = get_object_or_404(Film, id=film_id) if request.method == 'POST': form = FilmActorsForm(request.POST) if form.is_valid(): chosen_actors = form.cleaned_data['actors'] current_actors = film.actors.all() # handle deletion / creation of filmroles return HttpResponseRedirect(...) else: form = FilmActorForm() 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Creating one model row from another model save method
Hello, You should substitute 'subgallery_set' to 'subGallery_set' (different in case) or specify a related_name [1] . Regards [1] http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form/view for ManyToMany relationship
Hello, Sorry if I misunderstand, but what is wrong about using a ModelForm on your Film bounded to the film instance? 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form Functionality
Hi Matt, I think your form should use GET method, not POST method: there is no modification implied when submitting it. Now, I'm perfectly fine using parameters in the url as it is meaningful: your accessing the search ressource and passing it a parameter. It's different for a ressource that should be tight to some content, like a post on a blog where the url is set "dynamically": the ressource exists or not. Another case where I asked me the question of "clean url" was pagination. Here again, I'm confortable with "unclean" url (you can pass a number of occurences per page and the page number you want to access). Well you must handle "unranged" pages... About redirection, I'm not sure, but this can trouble navigator's previous page (why redirect after a successful POST if it doesn't :). In real world, I you search for a keyword and you get only one match, then you can be redirect to the only result details page, so you're redirection cannot be blamed, but this is done more for user experience than purity concern. OK, I'll understand if that don't help you but maybe some experienced people can react ^^ 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: Forms: set required value at runtime
Bence, I think your problem is related to the second case described in documentation about validation fields that depend on each other [1]. Just an observation about your design, if I may: I believe you should explicitly set and store both addresses. You will ease user task by providing a widget that will set the second address according the first, activated or not by default (I prefer not as your helper offer a direct one click "auto-fill" as you can encounter in many date fields with "today" button). Regards [1] http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other -- 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: The same table in 2 apps
Hello, You have defined "MyClass" for "foo" application in its models.py, and you want to use that class in your application "bar"? You'll find how to use models from another app in Django documentation [1]. A widly spread example is the import of User in your app from django.contrib.auth [2]. By searching the web for "from django.contrib.auth import User", I found a discussion about the best way to import [3]. Regards [1] http://docs.djangoproject.com/en/dev/topics/db/models/#models-across-files [2] http://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth [3] http://stackoverflow.com/questions/1704058/python-and-django-best-import-practices -- 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.
Re: UnicodeEncodeError
Sorry, sorry I proposed Jean to send me the actual file to check its encoding. I asked for his OS too in order to see what editor are available and how it allows to "transcode" the text. -- 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: UnicodeEncodeError
Tu peux m'envoyer ton fichier ? je vérifie son encodage. Sinon, quel OS utilises-tu ? Le 29/09/2010 23:14, jean polo a écrit : On Sep 29, 10:38 pm, werefr0g<weref...@yahoo.fr> wrote: Jean, Sorry, the three points are: ># -*- coding: utf-8 -*- line > checking the module's file is actually utf-8 encoded > using codecs module for file like read/ write operations. Well, not sure I have the skills to check these (except the first one). As all this happens in the admin code, I have no clue about how (or where) to look/change something. Any file that contents any accent (yeah french customer: éèê or ç) triggers the error. Sorry but I'm still new to django/python. cheers, _y -- 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: UnicodeEncodeError
Jean, Sorry, the three points are: > # -*- coding: utf-8 -*- line > checking the module's file is actually utf-8 encoded > using codecs module for file like read/ write operations. -- 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: UnicodeEncodeError
Isn't the filename a string? It may not be the solution but I think you should try them at least since they are very quick to apply. As I saw something implying os module I thought that before Django handles the string, it must encode by os module. I found that using previously written steps and explicitly set encoding with "codecs" module while working with text files got rid of my problems encontered with unicode. The fact is that at different levels, there are assumptions on the encoding used while executing it and using utf-8 doesn't make you application work with unicode objects at all levels. When those problem arise, one of the three solutions always end it in my very short python existence. 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: UnicodeEncodeError
Hi, You should check that your file is actually utf-8 encoded and add the folliwing right after shebang: # -*- coding: utf-8 -*- Le 29/09/2010 18:59, jean polo a écrit : Hi. I get an 'UnicodeEncodeError' if I upload a file (ImageField) with non- ascii chars in my application (django-1.2.1). I added: export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8' in my /etc/apache2/envvars as stated here: http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror but I still have the same error (after restarting apache). Any hint much appreciated. cheers, _y ps: Traceback (most recent call last): [snip] File "/usr/languages/python/2.6/lib/python2.6/genericpath.py", line 18, in exists st = os.stat(path) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 53: ordinal not in range(128) -- 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: Where do you put your business logic in django? Organizing big projects in django.
Hello, The following is quite long but reflects a non developper point of view. I'll expose briefly that business analysis already splits logic and why I think you should follow previous recommandations. I'll finish "out of subject" commenting your documentation request. > Split business logic When you have to describe business logic to a dev, seperating business responsabilities is a good start. I think it's a thought orientation shared by "business analysts" (I'm not sure this is the right term in english) and developpers. The process often shows that a same object can be approached from different perspectives (for exemple, sales, comptability, logictic both work with orders but with different perspectives). You'd better keep this object as generic as possible and let each perspective set its own attributes at its very level. This mailing list shows multiple practical examples with the User notion. In the process, you have to be consistent and a direct extra benefit is polishing each application interface. From a non developper point of view, I find far most easier to write applications when the semantic and the interfaces are clean. It helps your application's usability and it's documentation too. As most developpers complain, business logic tends to change and it's implementation has to follow. Both at business and application levels, these changes should be kept at their perpective level (for example, a change in accounting should not compromise other fields and not be a revolution in actual business if possible). My point is that it is a normal business analysis process to split responsabilities as far as possible and Django allows you to write multiple apps to implement that. Implementation problems are about the same that those brought while debatting applications reusability. If your project may have multiple dependencies, your app should keep them minimal at their level: this process is already part of business analysis when modeling "packages". In business, a task can be reassigned: if you want something done, you must ask somewhere else. Putting that in Django, if you want to reach a ressource, you use an url and the url mapper will call the ressource for you. Django allows you to name your urls and you can implement get_absolute_url easily. I see the way Django handles urls as a great strength. I take the opportunity to state that url are part of a web application interface (browsers are only a part of available clients). To rephrase all of that, splitting your project in multiple parts is already a business analysis requierement before reaching the developpement process. > Documentation and guidelines When speaking about Django's pro, the admin and the documentation come often. They reflect both a practical approach. Django's documentation show it's developpers philosophy and puts emphasis on good practices. Django's original design history and the framework's multiple actual fields of application tend to proove that team's member are not totally subject to delusion ;). I found that adding guidelines on a subject to applications' documentation helps greatly: it summarise the concepts, reinforce consistency and puts the recent knowledge on another perspective, acting as a seal. It draws practical schemas and are good entry points to the "practical cases to concepts" learners and can bring "step by step" learners to a more self-implying approach. It reinforce pattern recognition during the analysis. They are often used for feedback. Writing them is time consumming, that's the bad part. Ensuring that applications are designed to properly integrate into the framework helps to reinforce the framework. Extensions / plugins / adapters are considered when chosing a solution and for Django, they are the apps. Django is a practical solution by its extension ability. A pro often advanced in favor of frameworks usage is the standardisation of the developpement process. Explicitly tell the direction is the most simple way to garanty that, as far I can tell. While speaking of designing applications, I think that testing should be shown since the tutorial, at least in a minimal form. (by the way, testing advocates again a rationnal spread of responsabilities into the project). > Thanks Sorry, I lied in the begining. I was quite long so if you reach this point, you'll don't mind if I thank both Django's team to brought me into the enjoyment of developpement and the community for its participation and its enthousiasm. 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: SITE_ID
Hello, I searched the web for your error message and found that maybe you should see at INSTALLED_APPS level [1]. Regards, [1] http://www.pubbs.net/200908/django/40799-django-sites-framework.html -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How do you set choices in your application?
Hello, I'm not legitimate to answer you but I'm adding other options that experienced people can comment. I'd rather use a ForeignKey in that context but I don't have to think to much to performances in my apps. You can easily add status, handle i18n this way. I must confess that writing "data in hard" into the code itself makes me nervous too. This is a documented option so maybe some arguments we'll help to overcome this bias. If performances are an issue, I think about caching and I'll go to your third solution with http://docs.djangoproject.com/en/dev/ref/models/querysets/#pickling-querysets with maybe some "caching" issues to deal with. By the way, I'll add to Russel's comments that even if someone tries to answer you, this can be time consuming because this answer will be send to the community and it better be as correct as possible (both in social, formal and technical domains) and that implies reviewing your answer. You can take also in consideration than for some people, english is not really flowing when their main mentor is exception.Exception. Regards, Le 25/09/2010 02:51, Yo-Yo Ma a écrit : Let's say I have a model with a field called "status". I could set the choices in three ways: 1) status_choices = ((1, 'Completed'), (2, 'Unfinished'), (3, 'Cancelled')) 2) status_choices = (('COM', 'Completed'), ('UNF', 'Unfinished'), ('CAN', 'Cancelled')) Or, 3 ): db_choices = Choice.objects.all() status_choices = [[choice.pk, choice.description] for choice in db_choices] Is there any best practice? Note: Client's won't be able to define these choices. They'll all be defined by me (or else DB would be the answer of course). My thoughts: 1) Risky (data is useless without python file), 2) Slower, and risky because it might be difficult to change later, 3) a lot of work, and slow (because of DB). -- 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: Universal form
Le 25/09/2010 14:52, werefr0g a écrit : You're assuming that form are called only from views. Some Form methods are mostly used inside templates like as_p for example. Sorry for the double post but this statement is far from accurate (to be kind with myself). You can use form in a template without any kind of preparation in the views. This maybe pointless in most practical cases but developpers are inclined to behave weirdly (this is a lame explanation but this is at least accurate). -- 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: Universal form
Hello, You're assuming that form are called only from views. Some Form methods are mostly used inside templates like as_p for example. Another assumption you made is that all url point to html ressources. Images, javascripts can have their url. Generation of pdf, csv and AJAX mechanics are other examples. As far as I understand, you want to display a login form in all your html pages. My first thought is to place it in a template extended by all html pages (I think about Django documentation 'base.html' template). You can't call the form's as_p (or whatever you want) as the form is missing from your context and built-in template tags and filters do not provide directly (AFAIK) what you need for that purpose but you can write your own [1][2]. Your context already provides request.user; you can use it to display login form or logout link according this context. I don't know if this is a correct way to handle the case: maybe I'll do it another way with experience. The purpose is to point that you don't necessaraly need to work on "every function" from your views. Regards [1] http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ [2] http://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.forms -- 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: Relationship question: What do I do wrong?
Hello, I was quite laconic previously in order to spare you my "english". Sorry if you found this rude. Well, you describe the relashionship from one model perspective (Meal) while setting your field (side1).By setting Field side1 in Meal as models.ForeignKey, you state that a Meal has a relationship to one Side as side1 but you also explicitly state that one Side can be related to many Meal through this relashionship. If my_meal is your Meal instance, you'll use my_meal.side1 to reach related Side through side1 relashionship. With my_side as a Side instance, you'll use my_side.meal_set to reach all Meal related to my_side regarding the same relashionship. Now, taking side2 Field in account, you can use my_meal.side2 but you can no longer use my_side.meal_set: you cannot distinguish which relashionship is implied this way. The related_name parameters allows you to make that distinction. Here you can place 'with main course' and 'post main course' and, by the way, I think you should name fields with_main_course_side and post_main_course_side or alike. You'll find at http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects more details with an explanation of the nature of side1.meal_set object type's nature _ in better english ;) 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: Relationship question: What do I do wrong?
Axel, You should use "related_name" attribute in your models.ForeignKey fields. Regards Le 18/09/2010 08:26, Axel Bock a écrit : Hello, I am currently experimenting with a little webapp, and I have the following problem. I want to assign two properties of the same type to a class. (Stupid) Example: I have a meal, and it comes with two sides. The sides itself are another database key - they can change on a whim :) . It looks something like this: class Meal(models.Model): side1 = models.ForeignKey('SidesList') side2 = models.ForeignKey('SidesList') # class SidesList(models.Model): name = models.CharField(max_length=20) availability = models.BooleanField() Now I get an error when compiling this. See, I need exactly two properties of the same type (side1, side2) in two _different_ object properties. The meal comes with exactly two sides, you see? :) And they must be distinguishable (something like post-main-course side", and "side with main course" out of the same pool). The error is: "Accessor for field 'side1' clashes with related field 'SidesList.leg_set'." (the same error for side2). Any help here? I'm quite new to dango, so a little hint would be nice :) thanks a lot in advance, Axel. -- 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: Mudar Senha de um usuário
Hello, I don't accuratly understand what your asking for, sorry. Have you seen what's in http://docs.djangoproject.com/en/1.2/topics/auth/ ? I think that views.password_change already manages what your describing. If not, could you express what doesn't fit your expectations, please? Regards Le 17/09/2010 04:25, Giovanna Ronzé a écrit : Dado que um usuário está logado e quer mudar sua senha, como eu faço para o django mudar a senha daquele user sem que seja preciso que ele preencha esse campo (do nick)? Bem, para resolver esse problema, primeiro eu fiz de uma forma que necessitava do user dizer o nick. Pesquisando, eu vi que tinha uma classe PasswordChangeForm e tentei usar. Olha, se alguém me ensinar como se usa de fato (tanto no urls.py, no html e no views.py se possível ^.^) tudo bem. Mas eu realmente não consegui aplicar essa classe. Diante disso, voltei para ideia inicial de construir minha própria função. O problema voltou a ser o tal do campo user. Já que o usuário está logado, como eu 'pego' seu campo de username pelo views.py? Aí está a tentativa dessa função e os trechos de código relativos: [views.py] @login_required def mudar_senha (request): return render_to_response('matematica/mudar_senha.html') @login_required def mudar_senha_dados (request): erro = False nome = request.POST['username'] user = User.objects.get(username=nome) if request.POST['password'] == '': erro = True return render_to_response('matematica/mudar_senha.html', {'erro': erro}) else: user.set_password(request.POST['new_password']) user.save() return HttpResponseRedirect('/') [mudar_senha.html] Nova senha {{ form.new_password }} [urls.py] (r'^mudar_senha/', 'projeto.matematica.views.mudar_senha'), (r'^mudar_senha_dados/', 'projeto.matematica.views.mudar_senha_dados'), Bem. Desde já agradeço a atenção. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django and third party python apps, best practices for path locations?
Hello, I think you should use virtualenv for lot of reasons: * it is easy to use * you can even change you python interpreter according context without mixing accidentally libs from previous version, for example * you can test if upgrading a library, module, app doesn't break your project (you can try to upgrade Django for example) non-regression * you'll know precisely requirements of each project * you can reproduce live server environment (current and future) Comparing using or not using virtualenv, you'll spend more energy to "manually" manage libraries than using virtualenv each time. 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.