Re: django + fastcgi + lighttpd outlog and errlog not working
So you mean there is no way to get this kind of log with fastcgi mode: Validating models... 0 errors found Django version 1.4.2, using settings 'finderauto_dj.settings' Development server is running at http://127.0.0.1:8080/ Quit the server with CONTROL-C. [04/Dec/2012 23:10:47] "GET /admin/ HTTP/1.1" 200 12256 [04/Dec/2012 23:10:49] "GET /admin/recherches/alert/ HTTP/1.1" 200 4644 [04/Dec/2012 23:10:49] "GET /admin/jsi18n/ HTTP/1.1" 200 5649 [04/Dec/2012 23:10:50] "GET /admin/recherches/alert/4/ HTTP/1.1" 200 11877 [04/Dec/2012 23:10:54] "GET /admin/recherches/alert/3/ HTTP/1.1" 200 11879 [04/Dec/2012 23:10:56] "GET /admin/recherches/alert/2/ HTTP/1.1" 200 11840 [04/Dec/2012 23:10:58] "GET /admin/recherches/alert/1/ HTTP/1.1" 200 11929 [04/Dec/2012 23:11:27] "GET /admin/recherches/alert/4/ HTTP/1.1" 200 11877 [04/Dec/2012 23:11:33] "GET /admin/recherches/alert/ HTTP/1.1" 200 4644 [04/Dec/2012 23:11:35] "GET /admin/recherches/alert/1/ HTTP/1.1" 200 11929 On Wednesday, December 5, 2012 12:49:06 AM UTC+1, Chris Cogdon wrote: > > I believe you only get the per-request logs when you're running the > development server (runserver). When you're running in fastcgi mode (and > its been a while since I have), you'll only get entries in outlog and > errlog if you actually send stuff to stdout and stderr yourself. And THAT > will require fiddling with the LOGGING settings. > > > On Tuesday, December 4, 2012 10:17:59 AM UTC-8, Gontran Magnat wrote: >> >> Hello, >> >> I'm running a django app on lighttpd with fastcgi. >> For debugging matters I would need the output logs that usually are >> displayed on the console. >> Because I run my application in a daemonize mode I tried to use the >> outlog and errlog options but it did not work. >> >> Here is the command I run: >> >> python manage.py runfcgi method=threaded host=127.0.0.1 port=3033 workdir >> =/mydir/finderauto_dj/ outlog=out.log errlog=err.log >> >> >> The out.log and err.log files are created but when I access my website, >> this should produce this kind of logs: >> [03/Dec/2012 23:09:11] "GET /admin/recherches/alert/4/ HTTP/1.1" 200 11844 >> >> However, both out.log and err.log files remain empty. >> >> Then I tried to use the daemonize=false option in order to have directly >> the output: >> >> python manage.py runfcgi method=threaded host=127.0.0.1 port=3033 >> daemonize=false >> >> >> I get nothing either... >> >> Anybody for helping me? >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/UjKU7yfP2hUJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
django + fastcgi + lighttpd outlog and errlog not working
Hello, I'm running a django app on lighttpd with fastcgi. For debugging matters I would need the output logs that usually are displayed on the console. Because I run my application in a daemonize mode I tried to use the outlog and errlog options but it did not work. Here is the command I run: python manage.py runfcgi method=threaded host=127.0.0.1 port=3033 workdir= /mydir/finderauto_dj/ outlog=out.log errlog=err.log The out.log and err.log files are created but when I access my website, this should produce this kind of logs: [03/Dec/2012 23:09:11] "GET /admin/recherches/alert/4/ HTTP/1.1" 200 11844 However, both out.log and err.log files remain empty. Then I tried to use the daemonize=false option in order to have directly the output: python manage.py runfcgi method=threaded host=127.0.0.1 port=3033 daemonize=false I get nothing either... Anybody for helping me? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/22s3f645uncJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django request with unicode strings wrongly UTF-8 encoded
I'm having some trouble making my website compatible with accented characters (french website). I have a form where some field values can be with accented chars: "Coupé" for instance. My URL looks like this: http://localhost:8080/recherches/s?marque=Audi=A5+Coup%C3%A9 In my django view I do something like this: def search(request): logger = logging.getLogger('custom') criteria_form = CriteriaForm(request.GET or None) logger.debug("search") logger.debug(request.GET) And what I get in my logs is: If I query my database with this variable "modeles", I get an error: >>> mo = u'A5 Coup\xc3\xa9'>>> Vehicule.objects.filter(valid=True, >>> modele=mo)[0].marque.nameTraceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 211, in __getitem__ return list(qs)[0]IndexError: list index out of range Things work if I query the database with the utf-8 version: >>> mo = 'A5 Coup\xc3\xa9'>>> Vehicule.objects.filter(valid=True, >>> modele=mo)[0].marque.name u'Audi' So I think (but I might be wrong) that my problem comes from the fact that my variable is utf8 and then encoded with unicode. How comes this is encoded that way? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qOX6yFHhnaYJ. 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: Getting a subclass from an abstract Model
You may be right but like I said, I will do differently: for s in MyBaseModel.__subclasses__(): if s.__name__ == "ClassA": MyClass = ClassA elif s.__name__ == "ClassB": MyClass = ClassB it was so simple!!! Thank you anyway. -- 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: Getting a subclass from an abstract Model
Nevermind, I will do differently... -- 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: Getting a subclass from an abstract Model
Hi Micky, sorry for my late answer but I havn't been working this week-end. I just tried your trick but it doesn't work. I don't think it's a probleme of manager, because if I want to query a subclass directly by its name, it works: ClassA.objects.all() works normally. On 8 juil, 19:48, Micky Hulsewrote: > Try adding the below to your base class: > > objects = models.Manager() # Admin uses this manager. > > Sent from my iPhone -- 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.
Getting a subclass from an abstract Model
Hello everyone, my models are defined like this: class MyBaseModel(models.Model): . class Meta: abstract = True class ClassA(MyBaseModel): .. class ClassB(MyBaseModel): .. Then I'm trying to get a subclass of MyBaseModel by doing this: for s in MyBaseModel.__subclasses__(): if s.__name__ == "ClassA": MyClass = s elif s.__name__ == "ClassB": MyClass = s q = MyClass.objects.all()===> Raise an AttributeError: type object 'ClassA' has no attribute '_default_manager' I don't understand why it raises this error, what am I missing? Thank you very much for your help. Cheers, Gontran -- 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: Generic ModelAdmin class
> Do you mean, "in a ModelAdmin subclass instance, how do I get the > model class that instance is associated with?"? If so, self.model. Yes I do. Thank you Tom. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Generic ModelAdmin class
Hello everyone, I have an abstract class that defines a base Model. Given the fact that the extended models are quite identical, in order to administrate these models, I use a generic ModelAdmin class. To sum up: class BaseClass(models.model): ...some fields... class Meta: abstract = True class ClassA(BaseClass): class ClassB(BaseClass): class CommonModelAdmin(admin.ModelAdmin): def my_custom_admin_view(self, request): def get_urls(self) register the view admin.site.register(ClassA, CommonModelAdmin) admin.site.register(ClassB, CommonModelAdmin) I defined a custom admin view in which I would like to get the class that is currently administered. Is it possible to do it? Thank you very much for your help Regards, Gontran -- 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: Many user profiles
Thank you very much Francesco, Works like a charm... On 20 juin, 15:33, francescortiz <francescor...@gmail.com> wrote: > Try doing this in your models.py: > > def get_profile(self): > ...your code to get the profile for a the user... > > User.get_profile = get_profile > > On Jun 20, 9:54 am,gontran<geoffroydecorb...@gmail.com> wrote: > > > Hello evreybody, > > > I wonder how to deal with many user profiles. > > I need to store different informations depending on the status of my > > users. > > > I have a generic UserProfile class: > > > class UserProfile(models.Model): > > user = models.OneToOneField(User, primary_key=True) > > role = models.CharField(max_length=1, choices=USER_ROLE) > > > and other classes for different profiles: > > CustomerProfile, EmployeProfile, ... > > > For the admin part, I managed to separate each category of users with > > proxy models. > > I know that I can override get_profile() on each proxy model based on > > the User class. > > > What I want to do: > > u = User.objects.get(pk=x) > > u.get_profile() ---> return the profile associated depending on the > > status of the user. If u is a customer, return a CustomerProfile > > instance, if u is an employe, return à EmployeProfile instance and so > > on. > > > Is it possible to do it? > > > Thanks in advance for your help. > > > Regards, > > >Gontran -- 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.
Many user profiles
Hello evreybody, I wonder how to deal with many user profiles. I need to store different informations depending on the status of my users. I have a generic UserProfile class: class UserProfile(models.Model): user = models.OneToOneField(User, primary_key=True) role = models.CharField(max_length=1, choices=USER_ROLE) and other classes for different profiles: CustomerProfile, EmployeProfile, ... For the admin part, I managed to separate each category of users with proxy models. I know that I can override get_profile() on each proxy model based on the User class. What I want to do: u = User.objects.get(pk=x) u.get_profile() ---> return the profile associated depending on the status of the user. If u is a customer, return a CustomerProfile instance, if u is an employe, return à EmployeProfile instance and so on. Is it possible to do it? Thanks in advance for your help. Regards, Gontran -- 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.
Display list of users in a group admin page
Hi Everyone, I've been searching again and again but I can't figure out how to display the list of all users in a group admin page. I'd like to select members of a group directly from this group admin page. Does anyone knows if it's possible? Thank you for your help. Regards, Gontran -- 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.
Formset with FileField
Hello everybody, I've a class Document: class Document(models.Model): doc = models.FileField(...) pub = models.ForeignKey(Publication) I've a inlineformset_factory class: DocumentFormset = inlineformset_factory(Publication, Document) In my view, I treat the form correctly an send it to the template. In my template, I use the {{ formset }} tag to display the form. When no files have been uploaded, everthing is fine and I can upload new files. But if I want to edit the previously uploaded files, I have empty text input with delete checkboxes, plus the number of extra empty forms I defined with extra keyword. My question is: how to display the name of the previously uploded files instead of having an empty input? Thank you by advance, Gontran -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Model formset inside ModelForm
Hello everybody, I was wondering if it's possible to insert a Model formset inside another ModelForm. Let me explain myself: here are my models: class Publication(models.Model): author = models.CharField(...) content = models.TextField() ... class Document(models.Model): file = models.FileField(...) publication = models.ForeignKey(Publication) I declared a ModelForm in order to add/edit Publication: class PublicationForm(ModelForm): class Meta: model = Publication I know how to declare a Model formset to add/edit files: DocumentFormSet = inlineformset_factory(Publication, Document) So I know have two forms and I just want one form. Is it possible to simply add the inline formset to PublicationForm ? Thank you in advance, regards, Gontran -- 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: Complex query
Now that I changed my model, the query is a little bit different. So, my models: UserProfile(models.Model): user = models.OneToOneField(User) company = models.ForeignKey(Company) Company(models.Model): ...some fields... Product(models.Model): ...some fields... ProductLicence(models.Model): product = models.ForeignKey(Product) company = models.ForeignKey(Company) News(models.Model): related_products = models.ManyToManyField(Product) And my query: news = News.objects.filter(related_products__productlicence__in=user.get_profile().company.productlicence_set.all()).distinct() I hope that it will be useful to somebody. Regards, Gontran On 29 mar, 10:34, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > On Tue, 2011-03-29 at 01:17 -0700, bruno desthuilliers wrote: > > On 29 mar, 09:33, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > > > Product is not linked to them - they are linked to Product. > > > Sorry but I dont see the point here - you can follow a relationship > > both way. > > pointless nitpick - apologies > -- > regards > KGhttp://lawgon.livejournal.com > Coimbatore LUG roxhttp://ilugcbe.techstud.org/ -- 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: Complex query
Hi Bruno, yes you're right. I should change my model in the way you mentioned it. I saw that a couple of minutes ago. And to answer to my initial question, I might have found the answer. The query would be: news = News.objects.filter(related_products__productlicence__in = user.get_profile().company.product_licences.all()).distinct() On 29 mar, 10:24, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > On 29 mar, 09:11, gontran <geoffroydecorb...@gmail.com> wrote: > > > Hi everybody, > > > considering the folowing models: > > > UserProfile(models.Model): > > user = models.OneToOneField(User) > > company = models.ForeignKey(Company) > > > Company(models.Model): > > product_licences = models.manyToManyField(ProductLicence) > > Sorry if I missed something, but are you sure you want a m2m > relationship here ??? This means that a same licence can "belong" to > many companies, which seems rather weird to me. As far as I'm > concerned I'd make "company" a foreign key in ProductLicence - or I > just don't understand your definition of what "licence" is ??? > > > Product(models.Model): > > ...some fields... > > > ProductLicence(models.Model): > > product = models.ForeignKey(Product) > > (snip) -- 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: Complex query
Ok. I 'll try again Thank you very much for your consideration. Regards, Gontran On 29 mar, 09:33, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > Product is not linked to them - they are linked to Product. I do not > think you can do it in one query because there are ManyToMany fields > which have to be retrieved and then you have to iterate over them. > Certainly more than one query. > > > > > > > > > > On Tue, 2011-03-29 at 00:24 -0700, gontran wrote: > > Yes: ProductLicence and News > > > On 29 mar, 09:19, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > > > On Tue, 2011-03-29 at 00:11 -0700, gontran wrote: > > > > UserProfile(models.Model): > > > > user = models.OneToOneField(User) > > > > company = models.ForeignKey(Company) > > > > > Company(models.Model): > > > > product_licences = models.manyToManyField(ProductLicence) > > > > > Product(models.Model): > > > > ...some fields... > > > > > ProductLicence(models.Model): > > > > product = models.ForeignKey(Product) > > > > > News(models.Model): > > > > related_products = models.ManyToManyField(Product) > > > > > I already know how to retrieve all distinct products for which the > > > > company of the user owns licences, but now, what I want to do is to > > > > retrieve all news, for a given user, that are related to products, for > > > > which the company of the user owns licences. > > > > Product is not linked to any model? > > > -- > > > regards > > > KGhttp://lawgon.livejournal.com > > > Coimbatore LUG roxhttp://ilugcbe.techstud.org/ > > -- > regards > KGhttp://lawgon.livejournal.com > Coimbatore LUG roxhttp://ilugcbe.techstud.org/ -- 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: Complex query
Yes: ProductLicence and News On 29 mar, 09:19, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > On Tue, 2011-03-29 at 00:11 -0700, gontran wrote: > > UserProfile(models.Model): > > user = models.OneToOneField(User) > > company = models.ForeignKey(Company) > > > Company(models.Model): > > product_licences = models.manyToManyField(ProductLicence) > > > Product(models.Model): > > ...some fields... > > > ProductLicence(models.Model): > > product = models.ForeignKey(Product) > > > News(models.Model): > > related_products = models.ManyToManyField(Product) > > > I already know how to retrieve all distinct products for which the > > company of the user owns licences, but now, what I want to do is to > > retrieve all news, for a given user, that are related to products, for > > which the company of the user owns licences. > > Product is not linked to any model? > -- > regards > KGhttp://lawgon.livejournal.com > Coimbatore LUG roxhttp://ilugcbe.techstud.org/ -- 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.
Complex query
Hi everybody, considering the folowing models: UserProfile(models.Model): user = models.OneToOneField(User) company = models.ForeignKey(Company) Company(models.Model): product_licences = models.manyToManyField(ProductLicence) Product(models.Model): ...some fields... ProductLicence(models.Model): product = models.ForeignKey(Product) News(models.Model): related_products = models.ManyToManyField(Product) I already know how to retrieve all distinct products for which the company of the user owns licences, but now, what I want to do is to retrieve all news, for a given user, that are related to products, for which the company of the user owns licences. Is it possible to do it with a single query? Thank you for your time, regards, Gontran -- 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: LANGUAGE_CODE inside the template of an inclusion tag
Still no answers. Is it because it's impossible? By the way, I know that inside the code of my tag I can get the context and then the language used by the user, by I want to access to this value inside my template, without having to pass explicitely the value. On 25 mar, 16:39, gontran <geoffroydecorb...@gmail.com> wrote: > Hello everybody, > > I'd like to use LANGUAGE_CODE in the template of an inclusion tag but > this doesn't work. > I added 'django.core.context_processors.i18n' in the settings, I load > i18n in my template, and I specified to take context when I register > my inclusion_tag. > Am I missing something or is it impossible to use LANGUAGE_CODE in > this case? > > Thank you for your answers. > > Regards, > > Gontran -- 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.
LANGUAGE_CODE inside the template of an inclusion tag
Hello everybody, I'd like to use LANGUAGE_CODE in the template of an inclusion tag but this doesn't work. I added 'django.core.context_processors.i18n' in the settings, I load i18n in my template, and I specified to take context when I register my inclusion_tag. Am I missing something or is it impossible to use LANGUAGE_CODE in this case? Thank you for your answers. Regards, Gontran -- 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: Chaining stacked inline
Hi, back from my WE and still no answers. Should I presume that what I want to do is impossible? On 11 mar, 17:40, gontran <geoffroydecorb...@gmail.com> wrote: > Hi, > > I'm wondering if it's possible to chain StackedInlined object in a > django admin page. > Let me explain it: > I have a class UserProfile which is linked by a OneToOneField to the > django auth module class User. By this way (which is recommended) I > store additionnal informations about my users. In those informations, > I have a ForeignKey to the school of the user. > With a StackedInline class, I can edit user's profile in a user admin > page but I also want to be able to edit the school of a inside this > page, not with a pop-up. > > Is it possible to achieve this? > > Just to sum-up: > > My model: > Class UserProfile(models.Model): > user = models.OneToOneField(User) > extra fields > school = models.ForeignKey(School) > > My admin.py: > admin.site.unregister(User) > > class UserProfileInline(admin.StackedInline): > > model = UserProfile > > class UserProfileAdmin(UserAdmin): > > inlines = [UserProfileInline] > > admin.site.register(User, UserProfileAdmin) > > Thank you for your help -- 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?
I didn't try it, but werefr0g may be right. It seems that Model.clean() is the method do you need. And you can still add a javascript control for more convenience without the risk that if a user deactivate javascript, the error will be saved. Let us know greenie if it's ok with this method. On 11 mar, 22:03, werefr0gwrote: > 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 > [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: How to limit a ManyToManyField to three choices?
edit: you don't need to raise an error if the restaurant already has 3 Cuisine's objects associated, you just need to return a string with the explanation of the error. On 11 mar, 20:11, gontran <geoffroydecorb...@gmail.com> wrote: > Hi greenie, > > you just need to override the save method from your model Restaurant. > Before saving each instance, you check if the restaurant already has > 3 Cuisine's objects associated. If yes, you don't save the instance > and raise an error for exemple, if no, just call the standard method > of the super class Model. > You will find more infos in the django > documentation:http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-pre... > > On 11 mar, 18:06, greenie2600 <greenie2...@gmail.com> wrote: > > > > > > > > > Hi all - > > > I have two models with a many-to-many relationship: Restaurant and > > Cuisine. The Cuisine table contains, e.g., "Italian", "Mexican", > > "Chinese", etc. Each Restaurant record can be associated with one or > > more Cuisines. > > > Here's the thing: I'd like to limit this to three Cuisines per > > Restaurant. So when editing the record for "Bob's Pan-Asian Buffet", > > the user would be able to check "Japanese", "Chinese", and "Korean", > > but wouldn't be able to check a fourth box. > > > My question: can this be enforced within the model, or is this > > something I'd have to build into my interface layer? > > > Here's my models.py. > > > from django.db import models > > from django.contrib.auth.models import User > > > class Restaurant( models.Model ): > > > user = models.ForeignKey( User ) > > name = models.CharField( max_length = 128 ) > > slug = models.CharField( max_length = 24, unique = True ) > > cuisines = models.ManyToManyField( 'Cuisine' ) > > > def __unicode__(self): > > return self.name > > > class Cuisine( models.Model ): > > > name = models.CharField( max_length = 32 ) > > > def __unicode__(self): > > return self.name > > > class Meta: > > ordering = ['name'] -- 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?
Hi greenie, you just need to override the save method from your model Restaurant. Before saving each instance, you check if the restaurant already has 3 Cuisine's objects associated. If yes, you don't save the instance and raise an error for exemple, if no, just call the standard method of the super class Model. You will find more infos in the django documentation: http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods On 11 mar, 18:06, greenie2600wrote: > Hi all - > > I have two models with a many-to-many relationship: Restaurant and > Cuisine. The Cuisine table contains, e.g., "Italian", "Mexican", > "Chinese", etc. Each Restaurant record can be associated with one or > more Cuisines. > > Here's the thing: I'd like to limit this to three Cuisines per > Restaurant. So when editing the record for "Bob's Pan-Asian Buffet", > the user would be able to check "Japanese", "Chinese", and "Korean", > but wouldn't be able to check a fourth box. > > My question: can this be enforced within the model, or is this > something I'd have to build into my interface layer? > > Here's my models.py. > > from django.db import models > from django.contrib.auth.models import User > > class Restaurant( models.Model ): > > user = models.ForeignKey( User ) > name = models.CharField( max_length = 128 ) > slug = models.CharField( max_length = 24, unique = True ) > cuisines = models.ManyToManyField( 'Cuisine' ) > > def __unicode__(self): > return self.name > > class Cuisine( models.Model ): > > name = models.CharField( max_length = 32 ) > > def __unicode__(self): > return self.name > > class Meta: > ordering = ['name'] -- 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.
Chaining stacked inline
Hi, I'm wondering if it's possible to chain StackedInlined object in a django admin page. Let me explain it: I have a class UserProfile which is linked by a OneToOneField to the django auth module class User. By this way (which is recommended) I store additionnal informations about my users. In those informations, I have a ForeignKey to the school of the user. With a StackedInline class, I can edit user's profile in a user admin page but I also want to be able to edit the school of a inside this page, not with a pop-up. Is it possible to achieve this? Just to sum-up: My model: Class UserProfile(models.Model): user = models.OneToOneField(User) extra fields school = models.ForeignKey(School) My admin.py: admin.site.unregister(User) class UserProfileInline(admin.StackedInline): model = UserProfile class UserProfileAdmin(UserAdmin): inlines = [UserProfileInline] admin.site.register(User, UserProfileAdmin) Thank you for your help -- 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: Query involving manytomany relationship
I will answer to myself (after having been trying for over an hour, I found the answer a couple of minutes after posting my question) products = Product.objects.filter(productlicence__client=client).distinct() -- 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: Query involving manytomany relationship
Sorry for the question, but I've been trying for over an hour and just when I post this message, I find the answer!! Here is it: products = Product.objects.filter(productlicence__client=client).distinct() Hope that it will be useful -- 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.
Query involving manytomany relationship
Hello everybody this is maybe simple but I can't succeed in making a query. here is my model: class Client(models.Model): user= models.OneToOneField(User) product_licence= models.ManyToManyField('ProductLicence', blank=True, null=True) class ProductLicence(models.Model): product= models.ForeignKey('Produit') class Product(models.Model): code= models.CharField(max_length=15) name = models.CharField(max_length=50) In my model, clients may buy licences for different products. I'm trying to get in one query all products for which a given client owns a licence. Is it possible to do it or should I make 2 queries? Thanks in advance regards, Gontran -- 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: accessing dict values in a template
that's right! thank you! I don't know how I missed that information in the doc... On 29 sep, 23:51, Javier Guerrawrote: > sorry, the right syntax is > > {% for key, element in toto.items %} > Name: {{ element.name }} - Desc: {{ element.desc }} > {% endfor %} > > (as documented > inhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#for) > > -- > 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-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: accessing dict values in a template
It doesn't change anything On 29 sep, 21:39, Javier Guerra <jav...@guerrag.com> wrote: > On Tue, Sep 29, 2009 at 2:35 PM, gontran <geoffroydecorb...@gmail.com> wrote: > > In my template, I want to access to the name and to the desc of each > > key of toto: > > {% for element in toto %} > > Name: {{ element.name }} - Desc: {{ element.desc }} > > {% endfor %} > > try: > > {% for key, element in toto %} > Name: {{ element.name }} - Desc: {{ element.desc }} > {% endfor %} > > -- > 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-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 -~--~~~~--~~--~--~---
accessing dict values in a template
Hello, here is my problem: I have a dictionary which keys are unknown and which values are dictionaries. (I don't know the keys because they are dynamically created by a loop) For example: toto = {} toto['123'] = {} toto['123']['name'] = 'name of 123' toto['123']['desc'] = 'desc of 123' toto['456'] = {} toto['456']['name'] = 'name of 456' toto['456']['desc'] = 'desc of 456' In my template, I want to access to the name and to the desc of each key of toto: {% for element in toto %} Name: {{ element.name }} - Desc: {{ element.desc }} {% endfor %} but it doesn't work. The only things that work is: {% for element in toto %} {{ element }} {% endfor %} which print: 123 456 I don't understand why. Any help would be great. Thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Performing a db operation at session end
Thank you for your answer. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Performing a db operation at session end
Hello, I would like to know if it's possible to automatically perform a db operation at the end of a session. For example: a client book an item in a store but don't ckeck out his cart and close his browser. The item booked (which was unavailable during the session) is now available for other clients. Any help will be nice. Thank you by advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Select in a ModelForm
Thank you for your quick answer. It works fine now. On 24 avr, 10:13, "wrzymar Gazeta.pl" <wrzy...@gazeta.pl> wrote: > Hello, > > Add co class Town function __unicode__ > > class Town(models.Model): > id_town = models.AutoField(primary_key=True) > name = models.CharField(max_length=30) > > def __unicode__(self): > return self.name > > 2009/4/24 gontran <geoffroydecorb...@gmail.com> > > > > > > > Hello, > > > I have a problem with a select in a ModelForm. > > > My model: > > class Person(models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > id_town = foreignyKey(Town) > > > class Town(models.Model): > > id_town = models.AutoField(primary_key=True) > > name = models.CharField(max_length=30) > > > Then I create a form: > > class PersonForm(ModelForm): > > class Meta: > > model = Person > > > When I use it, in the select for selectionning the town, I have "Town > > object" but I would like to have the town name. > > > Any idea to fix the problem? > > > Thank you for your consideration. > > > Geoffroy > > -- > Pozdrawiam, > Marcin Wrzyciel --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Select in a ModelForm
Hello, I have a problem with a select in a ModelForm. My model: class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) id_town = foreignyKey(Town) class Town(models.Model): id_town = models.AutoField(primary_key=True) name = models.CharField(max_length=30) Then I create a form: class PersonForm(ModelForm): class Meta: model = Person When I use it, in the select for selectionning the town, I have "Town object" but I would like to have the town name. Any idea to fix the problem? Thank you for your consideration. Geoffroy --~--~-~--~~~---~--~~ 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: Recursive function
Ok, thank you all for your help On 12 nov, 15:19, Steve Holden <[EMAIL PROTECTED]> wrote: > By all means use your custom tag. Inside the code for the tag, use a > template to generate the HTML. That's all! > > regards > Steve > > gontran wrote: > > Could you be more explicite because I don't understand everything and > > why not using my custom tag? (which works fine) > > > On 12 nov, 14:43, bruno desthuilliers <[EMAIL PROTECTED]> > > wrote: > > >> On 12 nov, 14:25, gontran <[EMAIL PROTECTED]> wrote:> On 12 nov, 13:22, > >> Steve Holden <[EMAIL PROTECTED]> wrote: > > >>>> gontran wrote: > > >> (snip - about using templates instead of building html in python code) > > >>>>> -> I'm using this function in a custom tag to build a menu > > >>>> And is there a rule that says you can't do that using templates? > >>>> Hello Steve, > > >>> Maybe I'm wrong but I want to display this menu in all pages of my > >>> site, so by using a custom tag, I can display my menu without having > >>> to import my model in my different views. > > >> This doesn't prevent you from using a template to do the html > >> rendering: > > >> class MyNode(Node): > >> def render(self, context): > >> template = get_template('path/to/mytemplate.html') > >> context.push() > >> try: > >> context['foo'] = 'bar' > >> return template.render(context) > >> finally: > >> context.pop() > > >> HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Ok, thank you all for your help On 12 nov, 15:19, Steve Holden <[EMAIL PROTECTED]> wrote: > By all means use your custom tag. Inside the code for the tag, use a > template to generate the HTML. That's all! > > regards > Steve > > gontran wrote: > > Could you be more explicite because I don't understand everything and > > why not using my custom tag? (which works fine) > > > On 12 nov, 14:43, bruno desthuilliers <[EMAIL PROTECTED]> > > wrote: > > >> On 12 nov, 14:25, gontran <[EMAIL PROTECTED]> wrote:> On 12 nov, 13:22, > >> Steve Holden <[EMAIL PROTECTED]> wrote: > > >>>> gontran wrote: > > >> (snip - about using templates instead of building html in python code) > > >>>>> -> I'm using this function in a custom tag to build a menu > > >>>> And is there a rule that says you can't do that using templates? > >>>> Hello Steve, > > >>> Maybe I'm wrong but I want to display this menu in all pages of my > >>> site, so by using a custom tag, I can display my menu without having > >>> to import my model in my different views. > > >> This doesn't prevent you from using a template to do the html > >> rendering: > > >> class MyNode(Node): > >> def render(self, context): > >> template = get_template('path/to/mytemplate.html') > >> context.push() > >> try: > >> context['foo'] = 'bar' > >> return template.render(context) > >> finally: > >> context.pop() > > >> HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Ok, thank you all for your help On 12 nov, 15:19, Steve Holden <[EMAIL PROTECTED]> wrote: > By all means use your custom tag. Inside the code for the tag, use a > template to generate the HTML. That's all! > > regards > Steve > > gontran wrote: > > Could you be more explicite because I don't understand everything and > > why not using my custom tag? (which works fine) > > > On 12 nov, 14:43, bruno desthuilliers <[EMAIL PROTECTED]> > > wrote: > > >> On 12 nov, 14:25, gontran <[EMAIL PROTECTED]> wrote:> On 12 nov, 13:22, > >> Steve Holden <[EMAIL PROTECTED]> wrote: > > >>>> gontran wrote: > > >> (snip - about using templates instead of building html in python code) > > >>>>> -> I'm using this function in a custom tag to build a menu > > >>>> And is there a rule that says you can't do that using templates? > >>>> Hello Steve, > > >>> Maybe I'm wrong but I want to display this menu in all pages of my > >>> site, so by using a custom tag, I can display my menu without having > >>> to import my model in my different views. > > >> This doesn't prevent you from using a template to do the html > >> rendering: > > >> class MyNode(Node): > >> def render(self, context): > >> template = get_template('path/to/mytemplate.html') > >> context.push() > >> try: > >> context['foo'] = 'bar' > >> return template.render(context) > >> finally: > >> context.pop() > > >> HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Ok, thank you all for your help On 12 nov, 15:19, Steve Holden <[EMAIL PROTECTED]> wrote: > By all means use your custom tag. Inside the code for the tag, use a > template to generate the HTML. That's all! > > regards > Steve > > gontran wrote: > > Could you be more explicite because I don't understand everything and > > why not using my custom tag? (which works fine) > > > On 12 nov, 14:43, bruno desthuilliers <[EMAIL PROTECTED]> > > wrote: > > >> On 12 nov, 14:25, gontran <[EMAIL PROTECTED]> wrote:> On 12 nov, 13:22, > >> Steve Holden <[EMAIL PROTECTED]> wrote: > > >>>> gontran wrote: > > >> (snip - about using templates instead of building html in python code) > > >>>>> -> I'm using this function in a custom tag to build a menu > > >>>> And is there a rule that says you can't do that using templates? > >>>> Hello Steve, > > >>> Maybe I'm wrong but I want to display this menu in all pages of my > >>> site, so by using a custom tag, I can display my menu without having > >>> to import my model in my different views. > > >> This doesn't prevent you from using a template to do the html > >> rendering: > > >> class MyNode(Node): > >> def render(self, context): > >> template = get_template('path/to/mytemplate.html') > >> context.push() > >> try: > >> context['foo'] = 'bar' > >> return template.render(context) > >> finally: > >> context.pop() > > >> HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Could you be more explicite because I don't understand everything and why not using my custom tag? (which works fine) On 12 nov, 14:43, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 12 nov, 14:25, gontran <[EMAIL PROTECTED]> wrote:> On 12 nov, 13:22, Steve > Holden <[EMAIL PROTECTED]> wrote: > > > > gontran wrote: > > (snip - about using templates instead of building html in python code) > > > > > -> I'm using this function in a custom tag to build a menu > > > > And is there a rule that says you can't do that using templates? > > > Hello Steve, > > > Maybe I'm wrong but I want to display this menu in all pages of my > > site, so by using a custom tag, I can display my menu without having > > to import my model in my different views. > > This doesn't prevent you from using a template to do the html > rendering: > > class MyNode(Node): > def render(self, context): > template = get_template('path/to/mytemplate.html') > context.push() > try: > context['foo'] = 'bar' > return template.render(context) > finally: > context.pop() > > HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Hello Steve, Maybe I'm wrong but I want to display this menu in all pages of my site, so by using a custom tag, I can display my menu without having to import my model in my different views. On 12 nov, 13:22, Steve Holden <[EMAIL PROTECTED]> wrote: > gontran wrote: > > Merci beaucoup! > > it works fine now. > > >> Now, and while this is none of my problems, I'd seriously question the > > decision of building html that way. This would be better done using > > templates IMVHO. > > > -> I'm using this function in a custom tag to build a menu > > And is there a rule that says you can't do that using templates? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Merci beaucoup! it works fine now. >Now, and while this is none of my problems, I'd seriously question the decision of building html that way. This would be better done using templates IMVHO. -> I'm using this function in a custom tag to build a menu On 12 nov, 10:59, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 12 nov, 09:22, gontran <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > I've got a problem with a recursive function: > > in my model, I have a class named myClass: each object in my class has > > an id, a parentId, and a name. > > I want to make a list of all my objects that looks like this: > > > > object1 > > object2 > > object3 > > > > object4 > > object6 > > > > object5 > > ... > > > > > So I wrote a function displayListObject(): > > def displayListObject(parentId, displayString): > > displayString += '' > > elements = myClass.objects.filter(parentId=parentId) > > for element in elements: > > if myClass.objects.filter(parentId=page.id): > > displayString += '' + page.id + '' > > displayListObject(page.id, displayString) > > (snip) > > > Any idea to fix this? > > Yes : don't pass displayString as an argument, just use the return > value of the function, ie: > > def displayListObject(parentId): > displayString = '' > elements = myClass.objects.filter(parentId=parentId) > for element in elements: > if myClass.objects.filter(parentId=page.id): > displayString += '' + page.id + '' > displayString += displayListObject(page.id, displayString) > else: > displayString += '' + page.id + '' > displayString += '' > return displayString > > The root of your problem is that python strings are immutable. So the > augmented assignment ('+=') rebind the name displayString to a new > string object. And since parameters names are local to the function, > this rebinding (hopefully) only affect the local namespace. > > Now, and while this is none of my problems, I'd seriously question the > decision of building html that way. This would be better done using > templates IMVHO. > > HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Recursive function
Just a correction: replace 'page' by 'element': def displayListObject(parentId, displayString): displayString += '' elements = myClass.objects.filter(parentId=parentId) for element in elements: if myClass.objects.filter(parentId=element.id): displayString += '' + element.id + '' displayListObject(element.id, displayString) else: displayString += '' + element.id + '' displayString += '' return displayString On 12 nov, 09:22, gontran <[EMAIL PROTECTED]> wrote: > Hello, > > I've got a problem with a recursive function: > in my model, I have a class named myClass: each object in my class has > an id, a parentId, and a name. > I want to make a list of all my objects that looks like this: > > object1 > object2 > object3 > > object4 > object6 > > object5 > ... > > > So I wrote a function displayListObject(): > def displayListObject(parentId, displayString): > displayString += '' > elements = myClass.objects.filter(parentId=parentId) > for element in elements: > if myClass.objects.filter(parentId=page.id): > displayString += '' + page.id + '' > displayListObject(page.id, displayString) > else: > displayString += '' + page.id + '' > displayString += '' > return displayString > > then I call my function: displayListObject('index', '') > > It works fine for the first level but doesn't display the others: > > > object1 > object2 > object3 > object5 > ... > > > Any idea to fix this? > > Thank you for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Recursive function
Hello, I've got a problem with a recursive function: in my model, I have a class named myClass: each object in my class has an id, a parentId, and a name. I want to make a list of all my objects that looks like this: object1 object2 object3 object4 object6 object5 ... So I wrote a function displayListObject(): def displayListObject(parentId, displayString): displayString += '' elements = myClass.objects.filter(parentId=parentId) for element in elements: if myClass.objects.filter(parentId=page.id): displayString += '' + page.id + '' displayListObject(page.id, displayString) else: displayString += '' + page.id + '' displayString += '' return displayString then I call my function: displayListObject('index', '') It works fine for the first level but doesn't display the others: object1 object2 object3 object5 ... Any idea to fix this? Thank you for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: don't escape html tags
Sorry but I was working with an old documentation! I fixed it with th e filter 'safe' thank you for the quick answer On 6 nov, 17:48, "Ramiro Morales" <[EMAIL PROTECTED]> wrote: > On Thu, Nov 6, 2008 at 2:16 PM, gontran <[EMAIL PROTECTED]> wrote: > > > hello, > > > I just started to learn django, so my question may be stupid: > > > In my template, I would like to display a html string (stored in my > > database). My problem is that it displays the string but it > > automatically escapes the html tags. > > > for example, if my string is: my text > > instade of showing: my text > > it shows: my text > > > any idea to fix that? > > Searching over the documentation with terms like "automatically > escaping" or "autoescaping" > gives this > > http://docs.djangoproject.com/en/dev/topics/templates/ > > as the first hit. Unsurprisingly, one of the sections in that document > is "Automatic HTML escaping" > > Try reading it to know how you can control the feature. > > Regards, > > -- > Ramiro Morales --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
don't escape html tags
hello, I just started to learn django, so my question may be stupid: In my template, I would like to display a html string (stored in my database). My problem is that it displays the string but it automatically escapes the html tags. for example, if my string is: my text instade of showing: my text it shows: my text any idea to fix that? thanks for your help --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---