Model Formsets Have an Extra Blank Form?
I'm following the instructions here: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ But when I do this kind of thing: formset = AuthorFormSet(queryset=Author.objects.filter (name__startswith='O')) I always get an extra blank form at the end of my formset - regardless of how I set up the query set. How can I prevent this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how save data into more than one table?
How about posting the code here for a review? On Jul 30, 5:21 pm, Asinox wrote: > Thanks, i did it, i dont know if in the best way but im saving data in > two tables :) thanks :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: dynamic form
On Jul 31, 10:31 am, Salvatore Leone wrote: > Hi, > > I've got a form with various information and a file upload widget. > > Is there a way to uploads many files at the same time? So to have a link > "add file" (and even "remove" file for already selected files). > Look at: http://scompt.com/archives/2007/11/03/multiple-file-uploads-in-django --~--~-~--~~~---~--~~ 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: Scientific Data Frontend with Django
On Aug 3, 1:31 pm, Torsten Bronger wrote: > Hallöchen! > > blaine writes: > > [...] > > > My question: Has anyone used (or heard of using) a Django-powered > > application as a quick and powerful frontend to a scientific > > database? > > My scientific institute is about to create a database for the > samples (thin silicon layers) produced here. We have already 15.000 > lines of Django code, which is half of the way I estimate. > > Is anybody interested in building a small > community around it? In particular, an adaption to a specific > institution would need ca. 10.000 LOC, but an "apparatus library" of > re-usable components could help with that significantly. Torsten I work in a science research organisation and would be interested. The only downside would the volume of code you estimate is needed. 10k/30k is about 1/3 that needs rewriting for each organisation? That sounds very high. Maybe once the dust settles on this project and the refactoring can be done, the re-usability will be higher? I'd think that there would be many in universities and "open science" organisations (as opposed to proprietary research companies) that could help with such an effort. It's also clear that some thought will need to go into this "up front" in order to maximise reuse of code. My 2c Derek --~--~-~--~~~---~--~~ 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: multiple projects shared database
> > On the other hand, if the two websites are entirely independent, putting > > them into a single database is simply poor design. It's trivial to > > create a separate database and why not use the tools that are available > > instead of adding extra complexity?! > > I think the idea is to allow common authorisation between the two sites. I am a complete newbie here, so pardon me chipping in, but... would it not be possible to do authorisation in one database and then have the groups-specific databases being separate? Derek --~--~-~--~~~---~--~~ 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 deploy Django on the web server?
On Aug 9, 7:49 pm, justin jools wrote: > o thanks for that :) > as soon as my administrator finally sorts out Python script executing for me > - omg! ,I'll try that Not sure if this is off-topic or not, but I see Google is also offering free Django deployment on their App Engine: http://code.google.com/appengine/articles/django.html and http://code.google.com/appengine/docs/whatisgoogleappengine.html quote: "App Engine costs nothing to get started. All applications can use up to 500 MB of storage and enough CPU and bandwidth to support an efficient app serving around 5 million page views a month, absolutely free." disclaimer: I've not had any experience with this at all. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Uploading and using images in a database application
Given that I am a "wet behind the ears" newbie, maybe I should not be attempting this, but... I need some simple and straightforward guidance on uploading and using images in a simple database application, which (so far) only uses the admin interface. I working on my development machine (i.e. no Apache integration as yet). The use case is not that complex. If I have an "Event" object, with which I want to associate a number of images (typically, photos taken by people at that event), then I also need an "EventImage" object, with the event.id as the foreign key. So, the models look like: class Event(models.Model): id = models.AutoField(primary_key=True) date_time = models.DateTimeField() title = models.CharField(unique=True,max_length=250) class EventImage(models.Model): id = models.AutoField(primary_key=True) caption = models.CharField(unique=True,max_length=10) title = models.CharField(max_length=250) event = models.ForeignKey(Event) image = models.ImageField(upload_to='photos') What I have gathered so far, from browsing articles and snippets and Q&A, is that I also need: 1.to add/change settings.py: MEDIA_ROOT = '/home/blah/blah/mysite/media/' MEDIA_URL = 'http://127.0.0.1:8000/media/' ADMIN_MEDIA_PREFIX = '/media/' STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/' 2. add the following to the start of urls.py: from django.conf import settings 3. add the following to the end of urls.py: if settings.DEBUG: urlpatterns += patterns('', (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), ) (I have also tried variations on the above, such as: (r'^media/(?P.*)$', 'django.views.static.serve', and (r'%s(?P.*)' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), ) but in all cases, although the file does get uploaded and appears in the '/home/blah/blah/mysite/media/photos/' directory, when I click on the link - which is shown as http://127.0.0.1:8000/media/photos/test.jpg I get a "Page not found: /media/photos/test.jpg" This seems like a simple thing to fix - but not for me? Any help to fix this is appreciated, as is any guidance on what will need to change once this project needs to run under Apache... Thanks Derek --~--~-~--~~~---~--~~ 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: Calling Database functions into Django Application.
I have not used triggers/functions in Postgresql, but did find what may be a useful blog article: http://www.eflorenzano.com/blog/post/database-triggers-arent-evil-and-they-actually-kin/ On Nov 2, 3:28 pm, Geobase Isoscale wrote: > Hi all, > > Does anyone have an idea of how to call the functions created in the > database into Django application ? > > I'm working with Postgresql database. I have created a function using a > server-sided programming language called Pl/pgsql that will help me in > handling complex spatial business logic that I cannot define within Django. > How do I call such functions? > > I'm informed that django supports triggers and function though it cannot > create them . Thats why I have defined then in the Database.. > > Many Thanks > > Isoscale. --~--~-~--~~~---~--~~ 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 a view of a single record?
One of the needs I have (and, I imagine, others too) is to be able to display a view of a single record in a table. This is the case when the record has many fields, not all of which are appropriate for (or need to be) display in the normal list view. What I need to know is: is this a "standard" feature in the admin interface? If so, how do I go about activating it? If not, could someone please explain how to extend the admin interface for this to work? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Display a view of a single record?
I am not sure what you mean by "on change list"? The usual way that records get displayed is in a tabular list format. This is suitable when a record only has a few fields; some tables however have many fields in them and so would need to be displayed "in full" just by themselves. I am looking for a way to have a link to this "detail view" embedded in each line entry of the normal tabular list display - a type of "click here for more details" link. This would not form part of a search or query. On Nov 7, 1:24 am, Tomasz Zieliński wrote: > On 6 Lis, 07:55, derek wrote: > > > One of the needs I have (and, I imagine, others too) is to be able to > > display a view of a single record in a table. This is the case when > > the record has many fields, not all of which are appropriate for (or > > need to be) display in the normal list view. > > > What I need to know is: is this a "standard" feature in the admin > > interface? If so, how do I go about activating it? If not, could > > someone please explain how to extend the admin interface for this to > > work? > > Do you mean displaying single record on change list? > You can try using search or filtering features for this. > > -- > Tomasz Zielińskihttp://pyconsultant.eu --~--~-~--~~~---~--~~ 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: Display a view of a single record?
Well, the link to view a record would appear on each and every record line in the nomal tabular list. On Nov 8, 3:27 pm, joker wrote: > do u want to see last or first record? > > On 8 Kasım, 08:44, derek wrote: > > > > > I am not sure what you mean by "on change list"? > > > The usual way that records get displayed is in a tabular list format. > > This is suitable when a record only has a few fields; some tables > > however > > have many fields in them and so would need to be displayed "in full" > > just > > by themselves. > > > I am looking for a way to have a link to this "detail view" embedded > > in each > > line entry of the normal tabular list display - a type of "click here > > for more > > details" link. This would not form part of a search or query. > > > On Nov 7, 1:24 am, Tomasz Zieliński > > wrote: > > > > On 6 Lis, 07:55, derek wrote: > > > > > One of the needs I have (and, I imagine, others too) is to be able to > > > > display a view of a single record in a table. This is the case when > > > > the record has many fields, not all of which are appropriate for (or > > > > need to be) display in the normal list view. > > > > > What I need to know is: is this a "standard" feature in the admin > > > > interface? If so, how do I go about activating it? If not, could > > > > someone please explain how to extend the admin interface for this to > > > > work? > > > > Do you mean displaying single record on change list? > > > You can try using search or filtering features for this. > > > > -- > > > Tomasz Zielińskihttp://pyconsultant.eu- Hide quoted text - > > - Show quoted 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-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: Display a view of a single record?
Yes, the fields should not be editable in a "view". However, I do not see it as "a problem" - more as "a desirable feature". There are any number of use cases for letting users see detailed record data but not be able (or not need, at that point in time) to edit it. This feature is not meant to replace the existing ability to edit a record; but to add another option to the interface. It just seems strange to me that the admin interface allows for display of multiple records in a listing, but has no facility to display a complete, single record "view". I do not want to have redevelop an admin-like interface just to allow for this option (given that is such a generic one). It is not clear from what you say - but I assume that it is not possible to readily alter the current admin interface to incorporate the generic views you refer to? If it is, any guidance, or examples, along these lines would be appreciated. On Nov 9, 2:37 pm, Ludwik Trammer wrote: > I have a really hard time understanding what do you need, and I > suspect I'm not the only one. You are talking about the admin > interface, right? It displays a list containing all records, and when > you click on a record you go to a page that shows all fields for this > record (and lets you change their values). Isn't that exactly what you > want? > > If the problem is that you don't want the fields to be editable, > because you just want to display read-only lists of records: re-think > using admin interface. It is meant specifically for managing records > on your website. Just use > "django.views.generic.list_detail.object_list" (display list of > records) and "django.views.generic.list_detail.object_detail" (display > detailed view of a single record) generic views: > > http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-... --~--~-~--~~~---~--~~ 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: Uploading and using images in a database application
Bruno All the help is much appreciated - its working now, and I need to spend time to understand all the changes. On Nov 5, 5:53 pm, bruno desthuilliers wrote: > On 3 nov, 16:02, derek wrote: > > > Given that I am a "wet behind the ears" newbie, maybe I should not be > > attempting this, but... > > Attempts at thing we don't yet fully grasp can be a good way to > learn. > > > I need some simple and straightforward guidance on > > uploading and using images in a simple database application, which (so far) > > only uses the admin interface. > > > I working on my development machine (i.e. no Apache integration as yet). > > > The use case is not that complex. If I have an "Event" object, with which I > > want to associate a number of images (typically, photos taken by people at > > that event), then I also need an "EventImage" object, with the event.id as > > the foreign key. > > > So, the models look like: > > > class Event(models.Model): > > id = models.AutoField(primary_key=True) > > Hint : if you leave this previous line out, Django will automagically > add this very same field to your model !-) > > > > > date_time = models.DateTimeField() > > title = models.CharField(unique=True,max_length=250) > > > class EventImage(models.Model): > > id = models.AutoField(primary_key=True) > > caption = models.CharField(unique=True,max_length=10) > > title = models.CharField(max_length=250) > > event = models.ForeignKey(Event) > > image = models.ImageField(upload_to='photos') > > > What I have gathered so far, from browsing articles and snippets and Q&A, is > > that I also need: > > > 1.to add/change settings.py: > > > MEDIA_ROOT = '/home/blah/blah/mysite/media/' > > MEDIA_URL = 'http://127.0.0.1:8000/media/' > > ADMIN_MEDIA_PREFIX = '/media/' > > Using the same path component for both the static medias and the admin > media usually leads to unexpected results. Either change your static > medias component path to something else or - way simplier -, change > the ADMIN_MEDIA_PREFIX (here we canonically set it to 'admin-media'). > > > STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/' > > > 2. add the following to the start of urls.py: > > > from django.conf import settings > > > 3. add the following to the end of urls.py: > > > if settings.DEBUG: > > urlpatterns += patterns('', > > (r'^static/(?P.*)$', 'django.views.static.serve', > > {'document_root': settings.STATIC_DOC_ROOT}), > > ) > > This url pattern is not consistant with the your MEDIA_URL settings. A > good way to avoid this kind of problems is to follow the SPOT rule: > > ### in settings.py > import os > > PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) > SITE_URL = "http://127.0.0.1:8000"; > > MEDIA_DIR = "media" > MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) > MEDIA_URL = "%s/%s/" % (SITE_URL, MEDIA_DIR) > > ADMIN_MEDIA_PREFIX = '/admin-media/' > > # decouple this from the DEBUG flag - you may want to > # set DEBUG to true in preproduction > # (ie, running behind apache or another web server) > DEV_SERVER = True > > ### in urls.py > from django.conf import settings > > # urls here... > > if settings.DEV_SERVER: > urlpatterns += patterns('', > (r'^%s/(?P.*)$' % setting.MEDIA_DIR, > 'django.views.static.serve', > {'document_root': settings.MEDIA_ROOT}), > ) > > > (I have also tried variations on the above, such as: > > (r'^media/(?P.*)$', 'django.views.static.serve', > > which may have worked, minus the conflict between MEDIA_URL and > ADMIN_MEDIA_PREFIX > > > and > > (r'%s(?P.*)' % settings.MEDIA_URL[1:], > > MEDIA_URL is a string, so MEDIA_URL[1:] is the same string minus the > first character, ie, in your case : "ttp://127.0.0.1:8000/media/". > Probably not what you expected !-) > > > 'django.views.static.serve', > > {'document_root': settings.MEDIA_ROOT}), > > ) > > > but in all cases, although the file does get uploaded and appears in the > > '/home/blah/blah/mysite/media/photos/' directory, when I click on the link - > > which is shown as > > >http://127.0.0.1:8000/media/photos/test.jpg > > > I get a "Page not found: /media/photos/t
Re: Uploading and using images in a database application
Adrian Does the Photologue app store the image references in the database? On Nov 5, 6:58 pm, adrian wrote: > The easiest way is to use the Photologue application. > It has done most of the work for you. > > On Nov 5, 9:53 am, bruno desthuilliers > wrote: > > > On 3 nov, 16:02, derek wrote: > > > > Given that I am a "wet behind the ears" newbie, maybe I should not be > > > attempting this, but... > > > Attempts at thing we don't yet fully grasp can be a good way to > > learn. > > > > I need some simple and straightforward guidance on > > > uploading and using images in a simple database application, which (so > > > far) > > > only uses the admin interface. > > > > I working on my development machine (i.e. no Apache integration as yet). > > > > The use case is not that complex. If I have an "Event" object, with > > > which I > > > want to associate a number of images (typically, photos taken by people at > > > that event), then I also need an "EventImage" object, with the event.id as > > > the foreign key. > > > > So, the models look like: > > > > class Event(models.Model): > > > id = models.AutoField(primary_key=True) > > > Hint : if you leave this previous line out, Django will automagically > > add this very same field to your model !-) > > > > date_time = models.DateTimeField() > > > title = models.CharField(unique=True,max_length=250) > > > > class EventImage(models.Model): > > > id = models.AutoField(primary_key=True) > > > caption = models.CharField(unique=True,max_length=10) > > > title = models.CharField(max_length=250) > > > event = models.ForeignKey(Event) > > > image = models.ImageField(upload_to='photos') > > > > What I have gathered so far, from browsing articles and snippets and Q&A, > > > is > > > that I also need: > > > > 1.to add/change settings.py: > > > > MEDIA_ROOT = '/home/blah/blah/mysite/media/' > > > MEDIA_URL = 'http://127.0.0.1:8000/media/' > > > ADMIN_MEDIA_PREFIX = '/media/' > > > Using the same path component for both the static medias and the admin > > media usually leads to unexpected results. Either change your static > > medias component path to something else or - way simplier -, change > > the ADMIN_MEDIA_PREFIX (here we canonically set it to 'admin-media'). > > > > STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/' > > > > 2. add the following to the start of urls.py: > > > > from django.conf import settings > > > > 3. add the following to the end of urls.py: > > > > if settings.DEBUG: > > > urlpatterns += patterns('', > > > (r'^static/(?P.*)$', 'django.views.static.serve', > > > {'document_root': settings.STATIC_DOC_ROOT}), > > > ) > > > This url pattern is not consistant with the your MEDIA_URL settings. A > > good way to avoid this kind of problems is to follow the SPOT rule: > > > ### in settings.py > > import os > > > PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) > > SITE_URL = "http://127.0.0.1:8000"; > > > MEDIA_DIR = "media" > > MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) > > MEDIA_URL = "%s/%s/" % (SITE_URL, MEDIA_DIR) > > > ADMIN_MEDIA_PREFIX = '/admin-media/' > > > # decouple this from the DEBUG flag - you may want to > > # set DEBUG to true in preproduction > > # (ie, running behind apache or another web server) > > DEV_SERVER = True > > > ### in urls.py > > from django.conf import settings > > > # urls here... > > > if settings.DEV_SERVER: > > urlpatterns += patterns('', > > (r'^%s/(?P.*)$' % setting.MEDIA_DIR, > > 'django.views.static.serve', > > {'document_root': settings.MEDIA_ROOT}), > > ) > > > > (I have also tried variations on the above, such as: > > > (r'^media/(?P.*)$', 'django.views.static.serve', > > > which may have worked, minus the conflict between MEDIA_URL and > > ADMIN_MEDIA_PREFIX > > > > and > > > (r'%s(?P.*)' % settings.MEDIA_URL[1:], > > > MEDIA_URL is a string, so MEDIA_URL[1:] is the same string minus the > > first characte
Re: Display a view of a single record?
Cool! Thanks Alex - that is exactly what I want. On Nov 10, 4:55 pm, Alex Robbins wrote: > Derek, > > If you want something that display data but doesn't allow you to edit > it, you should check out the databrowse[1] contrib app. You just > register a model with it (like the admin) and it generates all the > pages. It lets users look through the data, but not edit it. > > [1]http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/ > > Hope that helps, > Alex > > On Nov 10, 3:36 am, derek wrote: > > > Yes, the fields should not be editable in a "view". > > > However, I do not see it as "a problem" - more as "a desirable > > feature". There are any number of use cases for letting users see > > detailed record data but not be able (or not need, at that point in > > time) to edit it. This feature is not meant to replace the existing > > ability to edit a record; but to add another option to the interface. > > > It just seems strange to me that the admin interface allows for > > display of multiple records in a listing, but has no facility to > > display a complete, single record "view". I do not want to have > > redevelop an admin-like interface just to allow for this option (given > > that is such a generic one). > > > It is not clear from what you say - but I assume that it is not > > possible to readily alter the current admin interface to incorporate > > the generic views you refer to? If it is, any guidance, or examples, > > along these lines would be appreciated. > > > On Nov 9, 2:37 pm, Ludwik Trammer wrote: > > > > I have a really hard time understanding what do you need, and I > > > suspect I'm not the only one. You are talking about the admin > > > interface, right? It displays a list containing all records, and when > > > you click on a record you go to a page that shows all fields for this > > > record (and lets you change their values). Isn't that exactly what you > > > want? > > > > If the problem is that you don't want the fields to be editable, > > > because you just want to display read-only lists of records: re-think > > > using admin interface. It is meant specifically for managing records > > > on your website. Just use > > > "django.views.generic.list_detail.object_list" (display list of > > > records) and "django.views.generic.list_detail.object_detail" (display > > > detailed view of a single record) generic views: > > > >http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-.. > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Override length of CharField on admin form
After much searching, the closest answer I can find for this is here: http://groups.google.com/group/django-users/browse_thread/thread/24edd54c637f19a7 with the "solution" being: text = forms.CharField(label="text", max_length=10, widget=forms.TextInput( attrs={'size':'10', 'class':'inputText'})) This does not work for an admin form: class Test(models.Model): id = models.AutoField(primary_key=True) comments = models.CharField(label="comment",max_length=250,blank=True,null=True,\ widget=forms.TextInput(attrs={'size':'50', 'class':'inputText'})) ... So how do I set it here? (Sidebar: it strikes me that I likely do not grok the differences between model and form in this circumstance.) -- 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: Complicated Form "Workflow" - Need ideas/direction
Baurzhan If you are serious about doing this, you may want to look at what has been "invented" elsewhere. The one example I know of (and have used) is Apache Cocoon's flow model: http://cocoon.apache.org/2.1/userdocs/flow/continuations.html Worth reading around ideas/concepts. Derek On Dec 14, 11:04 pm, Baurzhan Ismagulov wrote: > On Mon, Dec 14, 2009 at 12:17:31PM -0800, Almost George wrote: > > An Attendee, being added to an Event, must already exist in the > > system. If the given Attendee doesn't exist, the user should be > > prompted to create it/them (validly) before continuing further. > > > Likewise when selecting the Event Venue - if it doesn't exist, it must > > be created. > > > Of particular note, Venues have some required meta-information that > > must be filled out before it can be considered valid. > > > That's quite a bit of "add and/or create+validate", and I'm not sure > > how to implement that. I'm assuming I'll be using the Form Wizards, > > but at this point I'm just not sure where to start. > > This is implemented in admin using popups, your easiest way would be to > copy / reuse that. > > I'll have to work on a solution without popups in order to have: > > 1. A single browser window, to avoid user confusion if you have nested > ForeignKeys (admin opens a popup for each). > > 2. Pagination / filtering, since admin's controls don't scale > if you have anything more than a dozen of Attendees. > > I've looked into form wizards for that, but I don't think they are > flexible enough. First, if you already have an Attendee, I couldn't find > a way to skip that form. Second, the state is held in the POST requests. > The advantage is that a user may open several browser windows and use > different forms with complex workflows. The disadvantage is POST -- if > you want POST-redirect-GET to avoid some of the issues with back / > refresh (I'm using 1.0; you might want to look > athttp://code.djangoproject.com/ticket/9200). > > So, ATM I think we need a "workflow engine", which would display forms > with PRG and hold intermediate data and "return stack" in sessions. I've > scribbled together a couple of lines (not general, and nothing working > yet); the problem with my design is, it will always have its > limitations. For instance, if the user opens two browser windows and > would add two new Events, continuing in another window at an > "unfavorable" moment may result in a mess, although one may always > customize that for one's needs. Another hurdle was pickling the form > data into the session; I've skimmed through #9200 for that, but couldn't > find how it does that yet. > > If anyone has code or ideas, I'd like to hear about that, too. > > With kind regards, > -- > Baurzhan Ismagulovhttp://www.kz-easy.com/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: URGENT - Please help. Boolean field shows up as [null]
Perhaps you can say here what you fixed so others can learn. On Apr 14, 7:25 pm, pedjk wrote: > Problem solved. I just had to fix the code in mysql. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Admin inline extra field
On Apr 19, 2:07 am, nulvinge wrote: > I managed to solve it. > > part of my model was: > class Hour(models.Model): > store = models.ForeignKey('Store', unique=True) > > And it shouldn't have been unique. > Hmm, maybe there should be some warning message to clarify this or > atleast document it, > because I have searched a lot of docs to find what the problem was. It > was only thru debugging > the program that I found the code in the inlinfesformset_factory. > > On Apr 19, 1:27 am, nulvinge wrote: > > > > > Since this thing seems to be under some development now I should maybe > > say that I'm > > using the debian python-django package version 1.1.1-5. > > > On Apr 19, 1:21 am, nulvinge wrote: > > > > I simply can't get the extra field of inlining to work with the admin > > > interface. > > > Whatever I do the admin interface only shows one row of Hour > > > Here's my admin.py: > > > > from gshop.gs.models import (Store, Brand, District, Category, Hour) > > > from django.contrib.gis import admin > > > > class MyGeoAdmin(admin.OSMGeoAdmin): > > > default_lon = 1331500 > > > default_lat = 7904900 > > > default_zoom = 14 > > > > class HourInline(admin.TabularInline): > > > model = Hour > > > max_num = 7 > > > extra = 3 > > > > class MyStoreAdmin(MyGeoAdmin): > > > inlines = [HourInline] > > > > admin.site.register(Store, MyStoreAdmin) > > > admin.site.register(District, MyGeoAdmin) > > > admin.site.register(Brand) > > > admin.site.register(Category) > > > admin.site.register(Hour) > I am curious about this because I have also sometimes had this problem; but I have so much to develop that I have not spent lots of time trying to track down each occurrence. When you say " it shouldn't have been unique" - do you mean "it cannot be unique because that is a faulty model definition" or "it cannot be unique because this type of model definition will prevent inlines displaying"? If the former, then I am not sure that Django can really help. Its almost impossible to think of every possible error that users can make and report on this. If the latter, then that is worrying as it implies there is limited usage for inlines. Thanks Derek -- 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: Generate brochure pdf
On Apr 21, 1:14 pm, Alessandro Ronchi wrote: > 2010/4/20 cootetom : > > > django and and pisa are great for creating PDF's because you can > > combine django's templating engine with pisa's HTML to PDF conversion. > > Pisa uses the reportlab tool kit.http://pypi.python.org/pypi/pisa/ > > I think I can't use PISA because I need the pdf to be precise as > pixels, and HTML is not the best solution for that. > > -- > Alessandro Ronchi > > http://www.soasi.com > SOASI - Sviluppo Software e Sistemi Open Source > > Hobby & Giochi, l'e-commerce del > divertimentohttp://hobbygiochi.comhttp://www.facebook.com/pages/Forli/Hobby-Giochi/185311523755 Well, ReportLab will give you sub-mm control; even more accurate than pixels (which are really only useful for on-screen displays): http://www.reportlab.com/software/opensource/rl-toolkit/faq/#2.1.2 -- 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: Extending admin views?
On Apr 20, 10:48 pm, When ideas fail wrote: > If i have an admin form and want to transform some data to another > format using AJAX within the form, what is the best way to do this. In > a normal form I can do this within the view but is there any way to > extend admin views to add new functionality without loosing the > default admin view functionality? > > This is more a theoretical question than a practical one. I have > searched the docs but maybe I was searching for the wrong thing since > I couldn't find anything. > > Thanks in advance, > > Andrew Have a look at: http://www.djangobook.com/en/1.0/chapter17/ under the heading "Custom JavaScript" -- 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: modelForm ordering
On Apr 20, 4:09 pm, darren wrote: > I am not able to figure out how to order the records that fill the > drop down list in a model form. On line 112 below, I have attempted > to order the Rotation model by player. But, the drop down list that > is created for me is not ordered that way. I also tried relocating > line 112 to within the Meta class definition. But, that didn't work > either. I see field ordering in the docs. But, I don't see this > mentioned. > > Any suggestions would be more than appreciated. > > 101 class Rotation(models.Model): > 102 player = models.ForeignKey(Person, to_field='f_name', > verbose_name='Player', limit_choices_to={'relationship' : 'Player'}) > 103 date = models.DateField('Date', default=datetime.date.today) > 104 game_type = models.CharField("Game Type", > choices=(('Scrimmage', 'Scrimmage'), ('Tournament', 'Tournament')), > max_length=10) > 105 inning_count = models.IntegerField("Innings Out", default=1) > 106 def __unicode__(self): > 107 return '%s || %s %s || %s || %s' % (self.date, > self.player.f_name, self.player.l_name, self.game_type, > str(self.inning_count)) > 108 class Meta: > 109 ordering = ['date'] > 110 > 111 class RotationForm(forms.ModelForm): > 112 Rotation.objects.order_by('player') > 113 class Meta: > 114 model = Rotation > 115 exclude = ['date', 'inning_count'] You can add an 'ordering' property to your Rotation model's Meta class: class Meta: ordering = ['player'] The order will then be the same as the order specified in the Player model. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is there any way to create char data type in django.
On Apr 20, 1:31 pm, Huang Stanley wrote: > Hi all: > > I try to find all fields but only IPAddressField is char data type, > but it's a fix-length char data type for 15 characters. > > Is there any field that I can use for this purpose. > > PS. I use django 1.2 beta 1 on Ubuntu. > > Thanks for your kindly assistance. > > regards, > > Stanley Huang How about: http://docs.djangoproject.com/en/1.1/ref/models/fields/#charfield or http://docs.djangoproject.com/en/1.1/ref/forms/fields/#charfield -- 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.
Display first name and last name for user in dropdown lists in the Admin
This thread: http://groups.google.com/group/django-users/browse_thread/thread/b303c1ce3e724407/d99ee36e031d7393 ends with the comment that "whatever string (actually unicode) representation you want as constructed from the object attributes when you bring an object via foreign key." This is certainly true, and the example pointed to shows this: class Choice(models.Model): # ... def __unicode__(self): return self.choice However, what does the equivalent code look like for the customizing the built-in admin user (actually stored as "auth_user" in the database), including the neccesary class statement line? (Detailed issue: I have been using UserProfile to customize the User for my application. However, all the links to the user in the other models go direct to User and not UserProfile. Ideally, I'd like the dropdown list for users to show the information returned by this: def __unicode__(self): return u'%s,%s (%s)' % (self.last_name, self.first_name, self.fieldX) where "fieldX' is a field added in the UserProfile. If someone can show me the code to achieve this, it would be incredibly helpful... and maybe I could learn something about users and profiles!) Thanks Derek -- 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: Display first name and last name for user in dropdown lists in the Admin
On Apr 22, 3:03 pm, Tom Evans wrote: > On Thu, Apr 22, 2010 at 1:52 PM, derek wrote: > > This thread: > >http://groups.google.com/group/django-users/browse_thread/thread/b303... > > ends with the comment that "whatever string (actually unicode) > > representation you want as constructed from the object attributes when > > you bring an object via foreign key." > > > This is certainly true, and the example pointed to shows this: > > > class Choice(models.Model): > > # ... > > def __unicode__(self): > > return self.choice > > > However, what does the equivalent code look like for the customizing > > the built-in admin user (actually stored as "auth_user" in the > > database), including the neccesary class statement line? > > > (Detailed issue: I have been using UserProfile to customize the User > > for my application. However, all the links to the user in the other > > models go direct to User and not UserProfile. Ideally, I'd like the > > dropdown list for users to show the information returned by this: > > > def __unicode__(self): > > return u'%s,%s (%s)' % (self.last_name, self.first_name, > > self.fieldX) > > > where "fieldX' is a field added in the UserProfile. If someone can > > show me the code to achieve this, it would be incredibly helpful... > > and maybe I could learn something about users and profiles!) > > > Thanks > > Derek > > http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#django.contri... > > Register a different ModelAdmin for the auth.User class, and define > the fields you wish to display. Note that you can pass a callable as a > field, and the callable will be called with the user instance, from > which you can generate whatever content you like, even from the > UserProfile. > > Cheers > > Tom Thanks Tom I had thought I understood these concepts, but cannot see how to apply them to the User specifically. That is why specific examples of code always help (apart from the ones in the manual). What would the code for "Register a different ModelAdmin for the auth.User class" look like? And can you expand further on this : "you can pass a callable as a field, and the callable will be called with the user instance, from which you can generate whatever content you like, even from the UserProfile." How would this be represented in code form? (I appreciate I may seem obtuse here, but for some reason I can't grasp these aspects of Django although everything else about it has made perfect sense up to now.) Thanks Derek -- 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.
Template tag to display boolean values?
I am looking for a way to display a boolean value, with the "on" / "off" icon that the Django Admin uses in the change list, but within a template view of a single object. The documentation refers to a "custom tag", but I am not sure if the code or tag is accessible from elsewhere - there is no documentation for any tags to display booleans on the API document page ( http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#built-in-tag-reference). The tag also needs to be able to handle MySQL "booleans" (which are tinyint fields with values of 0 or 1). Thanks Derek -- 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.
Track "before" and "after" state of an object when editing in the Admin?
The Django docs point to the "hooks" you can use for custom code when saving/deleting objects in the Django admin http://www.djangoproject.com/documentation/models/save_delete_hooks/ What is not clear is how (or rather, where) to create a copy of an object before editing, so that it can be compared to the "revised" version altered by the user and appropriate code be executed. How and where can this be done? Thanks Derek -- 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: Template tag to display boolean values?
On Apr 25, 6:55 pm, Dmitry Dzhus wrote: > Derek wrote: > > I am looking for a way to display a boolean value, with the "on" / "off" > > http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno > -- Thanks - but that outputs strings, not URL links to images... -- 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: Track "before" and "after" state of an object when editing in the Admin?
Nick & Tony - many thanks! Derek -- 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: Template tag to display boolean values?
On Apr 28, 11:12 am, Daniel Roseman wrote: > On Apr 28, 9:08 am, derek wrote: > > > On Apr 25, 6:55 pm, Dmitry Dzhus wrote:> Derek wrote: > > > > I am looking for a way to display a boolean value, with the "on" / "off" > > > >http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno > > > -- > > > Thanks - but that outputs strings, not URL links to images... > > Except if you define the strings as URL links to images... > -- So a '' string will automatically show as an image - that's neat! -- 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 Admin limits
On Apr 29, 12:47 pm, Martin Tiršel wrote: > Hello, > > I am still a newbie exploring possibilities of Django but you learn > advanced techniques often on really big applications. I have here my two > projects I want to do in Django (1. advanced eshop system and 2. > webhosting management [customer database, invoicing, webhosting settings, > trouble tickets, ...]). Django Admin can be very customized but I don't > know if it can handle such projects. I am asking this because I don't know > if I have first to go deep into Django Admin and spend some weeks > exploring and testing all of the functionality first or I should begin > with building the application from scratch the old classic way. > > Here are some examples I will need to do: > > * combine Admin pages (CRUD) with normal pages (e.g. listing of sales > summaries or another overviews [with linking to details page for example], > displaying an amount of mixed informations [combined from multiple > models], ...) > > * dynamic edit forms - e.g. customer has a product which consist from > multiple parts which can be combined. So, one customer has fieldsets A, B, > C another A, C, D . Every fieldset has some editable and some static > fields (read only). > > * advanced permissions - some employees have editing access only to some > fields in a fieldset and these not editable without permissions are > displayed only as text instead of a textfield > > I don't think that such things will be possible, but as I found yesterday, > Django Admin has wider possibilities than I expected :) Indeed it has. The "standard" reply is "don't use the Admin." My view is "use the Admin to learn Django." E.g. you say "combine Admin pages (CRUD) with normal pages" - I am not sure exactly what you mean by "combine" but its very easy to add many other kinds of views to a Django site, happily running alongside the CUD pages [sorry, no "R" without some effort :( - I'll blog on this shortly], such as ones "displaying an amount of mixed information". Re "* dynamic edit forms" => there had just been a thread on that http://groups.google.com/group/django-users/browse_thread/thread/48f243a020b244e9 . [Sidebar - wait for version 1.2 for read-only field]. Re "* advanced permissions - some employees have editing access only to some fields" => I have not done this, but would think you can do this as part of the "dynamic edit forms" (certainly permissions can be fine-grained at a row level - many topics discussing this). In short - push the limits on the Admin - it can do far more than I thought after a read through of the Django book and similar documents (you must read these first, of course!). My 2c Derek (recent Django convert) -- 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: Saving the query object for later
On Apr 28, 7:45 pm, Peter Landry wrote: > +1 to this. I had similar requirements, and initially went down the road of > pickling a queryset. It became clear quickly that (at least in my case) a > better solution was to have a function that translates a Form instance into > a Queryset. Then serialize the form (or form data) and regenerate the > Queryset that way. > > Peter > > On 4/28/10 12:28 PM, "Bill Freeman" wrote: > > > > > The request may have references to objects that will no longer > > exist, or may be inappropriate when rerun later. I can't promise > > that it won't work, but I believe that pickling the request is at > > best a fragile solution. > > > To save just the required parameters won't take much code, > > especially if you refactor the code that turns the parameters into > > a the search operation into a function (or method) that you can > > use both initially and when you rerun the search. > > > Having to do some preparation again probably isn't going to be > > as big a performance drain as unpickling enough context to > > make it work without extra code. > > > On Wed, Apr 28, 2010 at 11:56 AM, Mark Jones wrote: > >> I was thinking I could pickle/unpickle the request then run it thru > >> with an extra flag of (send email) thru the same code that wsgi uses. > >> If I jsonify the data, how would I get that back into a python object? > > >> Is it really as simple as str=json.dumps(request) and request = > >> json.loads(str) > > >> I don't see how json keeps track of the object it is dumping, and not > >> sure how to construct a request object from the json return value. > > >> I can see how easy that part would be in C++, but my python skills are > >> a good deal weaker I guess I'm hunting for "how to do this in > >> python" > Peter This sounds intriguing: "a function that translates a Form instance into a Queryset". Is this a generic solution? Even if not, would you mind sharing the code here? Thanks! Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to filter a query set based on a calculated date value?
I would like to be able to filter a query set based on a calculated date value. Googling did not bring up anything obvious. As close as I can express it in "pseudo syntax", I'd like to do something along these lines: import datetime from dateutil.relativedelta import * today = datetime.now() MyModel.objects.filter( (my_date_field + relativedelta(months = +my_month_field))__lt = today ) i.e. compare one date with another - the second is calculated using a date field and a second numeric field (value representing months). The above syntax does not work - I am not sure how to code the calculation part... Thanks Derek -- 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.
Creating hierachical views and processing these in templates?
I am struggling to grasp the "full picture" when it comes to view queries and associated templates which deal with sets of "nested" parent/child relationships, and am hoping someone here can enlighten me. All the examples I have seen seem to deal with simple views showing one, or maybe two models at a time with very little processing (e.g. calculations). A "typical" (but very very simplified) sales model for a business could look something like this: class Area(models.Model): ZONE_CHOICES = ( (u'U', u'USA'), (u'E', u'Europe'), (u'A', u'Asia'), ) name = models.CharField(max_length=50) zone = models.CharField(maxlength =1, choices=ZONE_CHOICES) class Customer(models.Model): name = models.CharField(maxlength = 50) phone = models.CharField(maxlength = 50) area = models.ForeignKey(Area) class Order(models.Model): date = models.DateField() customer = models.ForeignKey(Customer) shipped = models.BooleanField() #has order been shipped? class Widget(models.Model): SIZE_CHOICES = ( (u'1', u'Small'), (u'2', u'Medium'), (u'3', u'Large'), ) name = models.CharField(maxlength = 50) size = models.IntegerField(choices=SIZE_CHOICES) price = models.FloatField() class OrderDetails(models.Model): widget = models.ForeignKey(Widget) order = models.ForeignKey(Order) number = models.IntegerField() #number of widgets purchased A typical report (Django view+template) that someone might want to see, is to show all orders for the current year, with order details, along with totals (counts and cost) at customer and order levels, for a given set of criteria e.g. all customers in Europe, who have ordered widgets of size 2, with orders that have a total value of $300 or more, in 2010. The report would need to be laid out in a hierarchical fashion, showing: alphabetically sorted customer name / phone and their total no. of orders, followed below by each order in date sequence - date, id and shipping status - followed below by the order details for that order (line for each widget, with name, size, number purchased and total cost), followed at the end by the total order cost. At the very end of the report, after all customers are displayed, the total cost of all orders, plus the average order cost. I would really like to see how (a) the view code would be constructed and (b) what the corresponding template specification would be. I can see, as a start, that the view might look something like: def view_order_details (request, zone, year, size, order_value): customers = Customer.objects.filter(area__zone=zone) But here is where I get stuck! How do I "nest" the orders for each customer, and also the order details (and the associated calculations)? What type of data structure gets created as a result? When does it get created? What does the template code, in turn, look like to be able to process this structure (or structures)? Note 1: Please note this is NOTHING at all like the models I am using - in case anyone thinks I am asking them to do my work! - its so that I can understand how such a nested system would be constructed - and how the template, in turn, would process it. Note 2: Yes, I realize these set of models could be improved with many-to-many or one-to-many relationship fields added. But, if at all possible, please just work with it "as is". Thanks - this will really help improve my understanding of a crucial conceptual area. Derek -- 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: Beyound django auth - custom login function - where?
On Apr 30, 4:44 pm, Aitch wrote: > I'm fearful this is a really dumb question but I'll go ahead anyway. > > My app is starting to need to go beyond basic auth. e.g. when a user > logs in, I need to check various related statuses, provide distinct > messages, set session vars and such like. > > What's not clear to me is, if I provide my own login() method (one > that calls auth.authenticate, auth.login etc, and doing my custom > activities as per docs) ... where (how) is it considered best practice > to implement this? > > Problem is similar to that described half way down > here:http://www.djangobook.com/en/2.0/chapter14/ > > Do I create a separate app dedicated to this task, or simply embed it > in an existing one? Aitch Not dumb. I think this would be a useful blog post. That aside... I think signals are the way to go. Look at recent posts on this topic (some linked to my name), e..g to "set session variables". I have not got this working yet, but if you do, perhaps you can "write up" some guidelines? Derek -- 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: Form with ChoiceField that collects additional info with each choice
On Apr 30, 4:00 pm, gsnyder2007 wrote: > I'm looking for a pointer to sample code or advice regarding what is > the best way to build a form that allows the user to select from > several options and supply additional textual input that is associated > with the option they chose, e.g. > > choices = [ > ('option1', 'value1'), # additional text input that is tied to > this option > ('option2', 'value2'), # additional text input that is tied to > this option > ('option3', 'value3'), # additional text input that is tied to > this option > ] > > The options (choices) are fixed (i.e not dynamic) but the input > obviously is. I know how I could do this using a Model-based approach > (the options become ForeignKey's to the Model class that collects the > input), but is there an easy way to do this with forms, fields, and > widgets? I tried playing around with MultiWidget and MultiField but > couldn't put it together the way I wanted. Something tells me the > obvious eludes me this morning. :-) I am not sure of the specifics of the problem you are trying to solve, but another way could be simply to make the "fixed choices" be "fixed fields". Then the " additional text input" becomes the value of the field. For example, if choices are: MasterCard, VisaCard and/or Cheque Account. These become fields and the user fills the name/number of the card or account as the " additional text input". Derek -- 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.
Translation error triggered by HttpResponse
The online documentation has the following example in this section: http://docs.djangoproject.com/en/1.0/topics/i18n/#standard-translation from django.utils.translation import ugettext as _ def my_view(request): output = _("Welcome to my site.") return HttpResponse(output) My example looks like this: def my_function(request): output = _("Activities") return HttpResponse(output) and generates this error when called: Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 279, in run self.result = application(self.environ, self.start_response) File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 651, in __call__ return self.application(environ, start_response) File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "/usr/lib/python2.5/site-packages/debug_toolbar/middleware.py", line 91, in process_response response.content = replace_insensitive(smart_unicode(response.content), u'', smart_unicode(self.debug_toolbars[request].render_toolbar() + u'')) File "/usr/lib/python2.5/site-packages/django/http/__init__.py", line 365, in _get_content return smart_str(''.join(self._container), self._charset) TypeError: sequence item 0: expected string, __proxy__ found As soon as I remove the _() it works just fine. Any clues as to what could be the cause? (I am running Django 1.1 on a local desktop, using the development server). Thanks Derek -- 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.
Syntax for displaying field values from parent model(s) in a template?
I have set of models, with relationships D -> C -> B -> A, where the "->" indicates a "many to one" relationship. I have been able to create a filtered queryset on child model D, based on a value in a parent model A, using the following syntax: my_query = D.objects.filter(C__B__A__name__icontains = "foo") where model A has a field called "name". I need to be able to display the value of the "name" field from A, along with the field attribute data from D in a template. I have therefore added the following to the end of my_query: .select_related('C__B__A__name') Assuming the template is called with the context containing: 'results': my_query then I can use {{ results.name }}, for example, to retrieve the value of the "name" field from model D. However I am unable to figure out the correct syntax for retrieving the value of the "name" field from related model A. I have tried {{ results.C.B.A.name }} with no effect? What is the correct way to do this? Thanks Derek -- 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: Syntax for displaying field values from parent model(s) in a template?
On May 5, 9:15 pm, Daniel Roseman wrote: > On May 5, 6:27 pm, Derek wrote: > > > > > I have set of models, with relationships D -> C -> B -> A, where the > > "->" indicates a "many to one" relationship. > > > I have been able to create a filtered queryset on child model D, based > > on a value in a parent model A, using the following syntax: > > > my_query = D.objects.filter(C__B__A__name__icontains = "foo") > > > where model A has a field called "name". > > > I need to be able to display the value of the "name" field from A, > > along with the field attribute data from D in a template. > > > I have therefore added the following to the end of my_query: > > > .select_related('C__B__A__name') > > > Assuming the template is called with the context containing: > > > 'results': my_query > > > then I can use {{ results.name }}, for example, to retrieve the value > > of the "name" field from model D. > > > However I am unable to figure out the correct syntax for retrieving > > the value of the "name" field from related model A. > > > I have tried {{ results.C.B.A.name }} with no effect? > > > What is the correct way to do this? > > > Thanks > > Derek > > Firstly, your select_related syntax is wrong. You don't need it to > access related objects, but it does help cut down on db queries. > However, it doesn't go down to field level, so you just want > 'C__B__A'. > > Secondly, your 'results' object is a queryset, so you *can't* do > 'results.name' as you claim. A queryset is a collection of items, not > a single one, so 'results' as a whole doesn't have either 'name' or > 'C' attributes. However, once you iterate through the queryset, each > individual item inside it does have both 'name' and 'C' attributes. So > this will work: > > {% for result in results %} > {{ result.name }} : {{ result.C.B.A.name }} > {% endfor %} > > An easy way of exploring all this is via the shell - you could have > seen the result of your query there, and accessed the individual > objects and their attributes. > -- > DR. Daniel Thanks for the heads-up about working in the shell. I have found out more useful commands and syntax in doing so (e.g. showing the SQL from the query via my_query.query.as_sql() ). I had the right idea (e.g. I was working with the {% for result in results %} loop, even though I did not indicate that to the original question) . The root of the problem was that my model relationships were incorrect i.e. D <- C -> B -> A and so I had to restructure the query. Derek -- 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: Generic web-dev question: Best way to do a processing page?
On May 1, 4:39 pm, Javier Guerra Giraldez wrote: > On Sat, May 1, 2010 at 7:22 AM, Joshua Russo wrote: > > This is mainly just curiosity at the moment. How do you create a > > "processing" intermediate page, like you see on travel sites when they are > > looking for the rates? I would always avoid this if at all possible, but > > sometimes you have a process that takes longer than usual. > > some ideas: > > - a view checks if the task is done, if so, shows the result. if not, > uses another template with the 'wait a sec..' message and a 'refresh' > HTML header that reloads the page after a few seconds. > I am curious as to how a view would actually "check if the task is done"? In my case, I would be uploading and processing a large file which could take some time. How would the view "know" that how far that file processing has progressed ... should it be writing out to a temp file which the view could "read"? What if there are multiple uploads occurring at the same time? Or are there simpler, more "Django-orientated" methods of doing this? Thanks! Derek -- 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: Generic web-dev question: Best way to do a processing page?
On May 13, 9:19 pm, robotmurder wrote: > Usually when I do this for an upload, etc... it means that a user just > did something that resulted in an row being created in the db. I > usually keep a boolean field in the table for processing. Then when I > load the next page I can just query that value right before I choose > the template to see if it's done processing, if it's done show the > result page, if not show the processing page and send the id of that > process along so I can query it using ajax every so often to see if > it's done then load the results page. > > Progress is a little harder. If it's a large file I would use > something like swfupload to show the user real time progress on the > page before loading the next page. > > If there is a better way to do these things, I'd love to know too. > > On May 13, 4:14 am, derek wrote: > > > > > On May 1, 4:39 pm, Javier Guerra Giraldez wrote:> On > > Sat, May 1, 2010 at 7:22 AM, Joshua Russo wrote: > > > > This is mainly just curiosity at the moment. How do you create a > > > > "processing" intermediate page, like you see on travel sites when they > > > > are > > > > looking for the rates? I would always avoid this if at all possible, but > > > > sometimes you have a process that takes longer than usual. > > > > some ideas: > > > > - a view checks if the task is done, if so, shows the result. if not, > > > uses another template with the 'wait a sec..' message and a 'refresh' > > > HTML header that reloads the page after a few seconds. > > > I am curious as to how a view would actually "check if the task is > > done"? In my case, I would be uploading and processing a large file > > which could take some time. How would the view "know" that how far > > that file processing has progressed ... should it be writing out to a > > temp file which the view could "read"? What if there are multiple > > uploads occurring at the same time? Or are there simpler, more > > "Django-orientated" methods of doing this? > > > Thanks! > > Derek Thanks for the ideas - not sure _I_ will use them though. "I usually keep a boolean field in the table for processing." - I don't really want to change my existing models; and anyway, data from the uploads usually get processed into multiple models (which vary depending on the data in the file) so this approach is too simplistic for my needs. "If it's a large file I would use something like swfupload" - for a number of reasons I am "Flash averse" so I would look for some other way of tracking the upload status (of course, this does not deal with the main issue of processing the file once it _is_ uploaded). Anyone else with ideas or "best 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.
Using a variable for a field name in a filter?
Given a model Foo, with a field bar: Foo.objects.filter(bar = "found") works just fine. But, in my case, different fields are needed at different times, so I would like to use: Foo.objects.filter(var_field = "found") where "var_field" is a variable which will be set to the name of a field (such as "bar"). The above is incorrect - how do I accomplish this? Thanks Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Displaying dictionaries
On May 18, 11:35 am, Tom Evans wrote: > On Tue, May 18, 2010 at 12:46 AM, Barry wrote: > > Hi-- > > > I want to dynamically display the contents of results (an array of > > dictionaries with the same keys) as a table where the column headers > > are a select group of keys in the variable result_col_titles and the > > order of the columns is the same as the order of the keys in > > result_col_titles. I imagine the template code would be something like > > what is below but I don't know how to reference a dictionary item > > value when the key value is in a variable and not hard-coded in the > > template. > > > This seems pretty basic but I didn't see it in the Definitive Guide > > to Django. > > > Thanks > > > Barry > > === > > > > > > {% for title in result_col_titles %} > > > > {{ title }} > > > > {% endfor %} > > > > {% for dictionary in result %} > > > > {% for title in result_col_titles %} > > > > {{ dictionary.title }} > > {{ dictionary.{{title}} }} > > > > {% endfor %} > > > > {% endfor %} > > > > It's considered 'poor form' by django devs - too much work in the > template. If you want the data in that order, arrange it so in the > view. > > If you don't agree, add this 5 line template tag: > > from django import template > register = template.Library() > > @register.filter > def dict_get(hash, key): > return hash[key] > > It should go in /templatetags/dict_get.py > > You can then do: > > {% load dict_get %} > > {% for dict in list_of_dicts %} > > {% for title in titles %} > {{ dict|dict_get:title }} > {% endfor %} > > {% endfor %} > > Cheers > > Tom Having _just_ struggled for a week with this and finally discovering a link here: http://www.bhphp.com/blog4.php/2009/08/17/django-templates-and-dictionaries that saved my sanity, I curious as to why this is considered "too much work". All the data in Django seems to be passed around via dictionaries (or, rather, if you do any kind of interim processing on it in the view logic, it ends up in lists of dictionaries) , so it would seem logical to allow sorting by dictionary keys. -- 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: Can you give me explanation for my
On May 18, 10:38 pm, Hendra Kurniawan wrote: > Hi all, > Can you give me a bright explanation for Django Framework ? how can > Django being configure in cloud computing? it's support? can you give > me some link article for this ? > > Thanks Before that.. > > Sincerely > > Hendra Try: http://www.youtube.com/watch?v=YI_2l6rc5Kw -- 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.
Installation problem (version 1.2.1)
I have just upgraded my version of Ubuntu, which then also installed Python 2.6. I thought this was a good opportunity to upgrade to Django 1.2. I removed all traces of Django 1.1.1 that I could find, along with extra plugins/modules/apps etc, and ran the install for Django 1.2.1, checking that I was specifying "python2.6" when doing so. However when I try and start a new project (django-admin.py startproject test), I get: Traceback (most recent call last): File "/usr/local/bin/django-admin.py", line 2, in from django.core import management File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 11, in AttributeError: 'module' object has no attribute 'get_version' If I start a Python session, I can do: >>> import django >>> dir(django) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] which seems incomplete? What (probably obvious) step or action have I missed or messed up? Thanks Derek -- 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: Twisty Little Passages... widgets, fields, forms
On Jun 1, 1:24 am, Michael Davis wrote: > I'm trying to implement a simple grade book application using a > modelformset where the students' names are READONLY and the grades are > the only thing the teacher can edit. I've been looking for sample code > to implement the readonly portion and one fellow (on another site) > suggests I use his, but he never posts sample usage code along with > it. > > He suggests I use a custom widget: > class ReadOnlyWidget(forms.Widget): > def __init__(self, original_value, display_value=None): > self.original_value = original_value > if display_value: > self.display_value = display_value > super(ReadOnlyWidget, self).__init__() > def _has_changed(self, initial, data): > return False > def render(self, name, value, attrs=None): > if self.display_value is not None: > return unicode(self.display_value) > return unicode(self.original_value) > def value_from_datadict(self, data, files, name): > return self.original_value > > But I can't figure out how to set the original_value in my > application. > The "obvious" choice like: > class GradeForm(ModelForm): > student = forms.CharField(max_length=50, > widget=ReadOnlyWidget(instance)) > doesn't work as I'm fairly sure instance isn't set here or if it is > how I can invoke it so it does the right thing in a modelformset. > > The less obvious choice of setting it from within the form's __init__ > function is currently beyond my ability as I do not understand the > code flow through here and am not sure how to instantiate the widget > from within the form's __init__ function. > > Can someone point me to a good source of documentation at this level > of detail? I know this is not answering your question directly, so please just sigh and ignore it if not relevant... If this is a simple application", as you mention above, maybe consider (or reconsider) using the Admin application, which has built-in support for readonly fields. http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields -- 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: select multiple without using foreignkey
On Jun 2, 3:00 am, HARRY POTTRER wrote: > I have a models that represents an event. > > I want it to have a field that represents the days of the week that > the event occurs. This is easy if all you need to be able to do is be > able to select one day, but if you want to select multiple, the right > way seems to be to create a DayOfWeek object, create 7 instances in > your db, the use ManyToMany relations. To me that just seems wrong. > I'd rather store it as a string like "WFS" or "MWF". Is there an easy > way to do this in django? You may want to think about storing the weekdays as numeric equivalents e.g. 0 = Sunday, 1 = Monday etc. Then you could use a CommaSeparatedIntegerField to store any combo you need - see: http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield http://stackoverflow.com/questions/1208698/how-do-i-use-commaseparatedintegerfield-in-django http://www.pubbs.net/200908/django/9885-how-to-use-selectmultiple-widget-with-commaseparatedintegerfield-.html Alternatively, you write a custom field - see: http://www.davidcramer.net/code/181/custom-fields-in-django.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.
Establish "reverse relationships" between models?
I have a situation which is parallel to the following: class Building(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) def __unicode__(self): return self.name class Manufacturer(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name class Alarm(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) building = models.ForeignKey(Building) master = models.BooleanField(default=0) manufacturer = models.ForeignKey(Manufacturer) def __unicode__(self): return self.name Now I need to display a list of all buildings, along with any alarm details, bearing in mind that not all buildings have alarms, while some have more than one (but only one master). However, when iterating through Buiding objects, a call to display "alarm.manufacturer__name" gives me an "AttributeError: 'Building' object has no attribute 'alarm'". Clearly, this is because, from the building point of view, there is no known relationship to Alarm. How do I create such a relationship in Django, without changing the database structure (e.g. creating an alarm field on Building, with a one-to-many relationship to Alarm)? (and, ideally, also being able to filter the result so only "master" alarms show up?) Thanks Derek -- 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: Model validation (not form validation)
On Jun 16, 8:20 am, MH wrote: > Hi, > I'm making a model, that has a bit complex dependencies between the fields, > such as date progression (start_date must not be later than finish_date). > I'm looking for a way to validate these dependencies while creating (or > saving) the model, but I am not sure which approach should I use. > > The best solution would be overriding Model's method *clean*, but this seems > to work only when working with forms. Another solution utilizes pre_save() > or save() methods. > > Which one is the "proper" one? > > Regards, > Mateusz Haligowski There's a good example at: http://www.jroller.com/RickHigh/entry/django_admin_and_field_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-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.
"'str' object has no attribute 'source'" for a simple test tag
Running Django 1.2.1 with Python 2.6 I am trying to create a simple test tag (the more complex ones are not working either...). In the templatetags directory, I have this code in the my_tags.py file: from django import template register = template.Library() @register.tag def foo(eggs=None, spam=None): return "foo" foo.is_safe = True And in the template file that uses it I have: {% load my_tags %} {% foo %} However, when I try and load the template file, I get a: Exception Type: AttributeError at /path/to/url Exception Value: 'str' object has no attribute 'source' error, and the full trace path includes no references to my source file(s). What (presumably obvious) mistake am I making? Thanks Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin filters getting reset after admin action
On Jun 17, 5:44 am, rahul jain wrote: > Hi there, > > I have some filters set-up on admin page. As soon as I perform admin > action. All filters are getting reset. > > Is this is a bug from framework ? No. There are work-arounds to get back to these; Google this group for suggestions. -- 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.
Primary key error for ManyToManyField in a legacy database
I have a legacy database setup like this: class Team(models.Model): id = models.AutoField(primary_key=True, db_column='TeamID') name = models.CharField(max_length=100, db_column='TeamName') groupings = models.ManyToManyField(Grouping, related_name='groupings', db_table='teamgrouping') class Grouping(models.Model): id = models.AutoField(primary_key=True, db_column='GroupingID') name = models.CharField(max_length=250, db_column='GroupingName', unique=True) class Meta: db_table = 'grouping' ordering = ['name'] class TeamGrouping(models.Model): id = models.AutoField(primary_key=True, db_column='teamgroupingID') grouping = models.ForeignKey(Grouping, db_column='grouping_id') team = models.ForeignKey(Team, db_column='team_id') class Meta: db_table = 'teamgrouping' unique_together = (('grouping', 'team'), ) When I display the Team model for editing in the Admin interface, it shows up OK. All the TeamGrouping's also show up, in a neat many-to- many widget, via the "groupings" field. However, when I try and save the entry, I get this error: OperationalError at /admin/edit/team/42402/ (1054, "Unknown column 'teamgrouping.id' in 'field list'") Request Method: POST Request URL:http://127.0.0.1:8000/admin/edit/team/42402/ Django Version: 1.2.1 Exception Type: OperationalError Exception Value: (1054, "Unknown column 'teamgrouping.id' in 'field list'") Exception Location: /usr/lib/pymodules/python2.6/MySQLdb/ connections.py in defaulterrorhandler, line 35 I am not sure (a) why Django is expecting to find a "'teamgrouping.id'" (I assume because "id" is the default name of a table's primary key field?) and (b) how to tell it to use 'teamgrouping.teamgroupingID' as the primary key (as specified in the TeamGrouping class)? Note: I am not using the "through" keyword because this is only needed when there are additional fields that are required on the intermediate table. Thanks Derek -- 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: Clean method across multiple models?
On Jun 17, 2:50 am, JHeasly wrote: > Hello all, > > Is there a sane way to make a clean [1] method that depends on fields > from across multiple models? > > I've got a view that uses two form classes and want to write custom > validation that checks clean_data fields in both models and I'm > looking for an example of such. > > TIA, > John > > [1]http://docs.djangoproject.com/en/1.1/ref/forms/validation/#s-cleaning... John Some actual code examples showing what you are trying to achieve would help... Bear in mind that "cleaning" relates to form data and not models per se (as per the example you point to). Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin filters getting reset after admin action
On Jun 18, 9:18 pm, swinton wrote: > On Jun 17, 4:13 pm, derek wrote: > > > On Jun 17, 5:44 am, rahul jain wrote: > > > > Hi there, > > > > I have some filters set-up on admin page. As soon as I perform admin > > > action. All filters are getting reset. > > > > Is this is a bug from framework ? > > > No. There are work-arounds to get back to these; Google this group > > for suggestions. > > Hi there, > > I'm trying to do the same (retain admin filters after action). I've > searched this group for suggestions, but have failed to come up with > anything. Can anyone give me some pointers? Not sure how you searched or why you missed this: http://groups.google.com/group/django-users/browse_thread/thread/d403af7a8dcdc90e/d69717b0e9a1f075 Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to access the request inside a model manager's get_query_set?
I would like to define a default manager for MyModel that always filters all records (when the model is accessed from anywhere in my application) based on data from the request: e.g. on the lines of: class MyModelManager(models.Manager): #override default def get_query_set(self, request): if request.foo == bar: return super(MyModelManager, self).get_query_set() return MyModel.objects.filter(spam = eggs) class MyModel(models.Model): ... objects = MyModelManager() However I get the error: Django Version: 1.2.1 Exception Type: TypeError Exception Value: Error when calling the metaclass bases get_query_set() takes exactly 2 arguments (1 given) So its clear that get_query_set() cannot take the request inserted there... but how else can I access the request inside the above model Manager class? (Note that I don't want to define an extra method that needs to be appended onto the MyModels.objects.zzz type of chained calls - such as the solution posted at http://osdir.com/ml/django-users/2010-02/msg00819.html - as I would then have to make these changes throughout the application, and also remember to add such a method to all future code.) Thanks Derek -- 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: Sorting objects according to a field from a foreign field
On Jun 22, 4:48 pm, Benedict Verheyen wrote: > On 22/06/2010 16:42, Daniel Roseman wrote: > > > > > As described in the documentation [1], you use the double-underscore > > syntax for sorting across relationships. > > Call.objects.all().order_by('-priority__weight') > > > [1]:http://docs.djangoproject.com/en/1.2/ref/models/querysets/#order- > > by-fields > > -- > > DR. > > Thanks for the quick response. > Hhhm, i searched the docs and didn't see it. Quote: "To order by a field in a different model, use the same syntax as when you are querying across model relations. That is, the name of the field, followed by a double underscore (__), followed by the name of the field in the new model, and so on for as many models as you want to join." (5th para under the "order_by" section) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to access the request inside a model manager's get_query_set?
On Jun 23, 8:28 pm, derek wrote: > I would like to define a default manager for MyModel that always > filters all records (when the model is accessed from anywhere in my > application) based on data from the request: > > e.g. on the lines of: > > class MyModelManager(models.Manager): > #override default > def get_query_set(self, request): > if request.foo == bar: > return super(MyModelManager, self).get_query_set() > return MyModel.objects.filter(spam = eggs) > > class MyModel(models.Model): > ... > objects = MyModelManager() > > However I get the error: > > Django Version: 1.2.1 > Exception Type: TypeError > Exception Value: > Error when calling the metaclass bases > get_query_set() takes exactly 2 arguments (1 given) > > So its clear that get_query_set() cannot take the request inserted > there... but how else can I access the request inside the above model > Manager class? > > (Note that I don't want to define an extra method that needs to be > appended onto the MyModels.objects.zzz type of chained calls - such > as the solution posted > athttp://osdir.com/ml/django-users/2010-02/msg00819.html > - as I would then have to make these changes throughout the > application, and also remember to add such a method to all future > code.) Well, I had to get something up-and-running, so I have fallen back on the "don't try this in your app" method of threads. I implemented this based on this blog entry: http://chewpichai.blogspot.com/2007/09/using-user-info-outside-request-in.html to get the "threadlocals" created. and then in "modelmanagers.py", I have: from myapp.middleware import threadlocals def get_user(): return threadlocals.get_current_user() class MyModelManager(models.Manager): def get_query_set(self): user = get_user() if user == None or user.is_superuser: return super(MyModelManager, self).get_query_set() return super(MyModelManager, self).get_query_set().filter(created_by = user) I _know_ this is not the "technically correct" way to do this, and would be very happy if someone pointed out how to rewrite the get_user() function to something more acceptable. Thanks Derek -- 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.
Rendering the Admin app list?
Working with Django 1.2.1 The default index page for Django admin contains: {% if app_list %} {% for app in app_list %} ... {% endfor %} {% else %} {% trans "You don't have permission to edit anything." %} {% endif %} I'd like to move this snippet to a separate page; however, when I do so, nothing shows up (well, the page template "wrapper" is there, but no listing of models etc.) What do I need to do to enable this? Thanks Derek -- 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: Rendering the Admin app list?
On Jun 25, 9:07 am, "euan.godd...@googlemail.com" wrote: > Do you mean that you want to include this code in your own app or want > to alter the structure of the admin app? > > Either of these actions will require the view that renders the page to > pass the variable app_list into the context as }% if app_list %} will > always be False as Django's templating system treats missing variable > as None effectively. > > On 25 June, 07:47, derek wrote: > > Working with Django 1.2.1 > > > The default index page for Django admin contains: > > > {% if app_list %} > > {% for app in app_list %} > > ... > > {% endfor %} > > {% else %} > > {% trans "You don't have permission to edit anything." %} > > {% endif %} > > > I'd like to move this snippet to a separate page; however, when I do > > so, nothing shows up (well, the page template "wrapper" is there, but > > no listing of models etc.) > > > What do I need to do to enable this? Before I "pass the variable app_list"; do I not need to create what is in this variable first? If so, how? Thanks Derek -- 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.
Error using inline displays with a user profile
I am having some problems with inline displays, since I upgraded to 1.2. The example here seems representative so I present as much information as seems relevant. I have set up the user & userprofile in a standard way - as per the "recipe" given by James Bennett here: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ and Matt's supplemental blog entry here: http://www.thenestedfloat.com/articles/displaying-custom-user-profile-fields-in-djangos-admin I have also checked that the userprofile table I use (basically the old user table from the previous system, with an extra field added to link it to the new auth_user) already contains all the data I want to display/edit. However, when I try and edit a user I get this error (which seems related to the inline display somehow): Request Method: GET Request URL: http://127.0.0.1:8000/admin/auth/user/1/ Django Version: 1.2.1 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'sorl.thumbnail', 'project.edit'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfResponseMiddleware', 'edit.middleware.threadlocals.ThreadLocals') Template error: In template /project/edit/templates/admin/edit_inline/stacked.html, error at line 8 Caught TypeError while rendering: coercing to Unicode: need string or buffer, NoneType found 1 : {% load i18n adminmedia %} 2 : 3 : {{ inline_admin_formset.opts.verbose_name_plural|title }} 4 : {{ inline_admin_formset.formset.management_form }} 5 : {{ inline_admin_formset.formset.non_form_errors }} 6 : 7 : {% for inline_admin_form in inline_admin_formset %} 8 : {{ inline_admin_formset.opts.verbose_name|title }}: {% if inline_admin_form.original %} {{ inline_admin_form.original }} {% else %}#{{ forloop.counter }}{% endif %} On the webpage, the {{ inline_admin_form.original }} is displayed in red. I have had this error in other places as well, but this seems the one that is most easily reproducible. Thanks Derek -- 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: Rendering the Admin app list?
On Jun 25, 8:45 pm, raj wrote: > > Before I "pass the variable app_list"; do I not need to create what is > > in this variable first? If so, how? > > That template is rendered by the view, AdminSite.index() found at > django.contrib.admin.sites. Please Check it to know how it's done. > > Rajeesh. Will do. I just find it very strange that, given I am working in_and_with the Admin app, this routine works *only* in the index page... Derek -- 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: Error using inline displays with a user profile
On Jun 26, 3:39 pm, Karen Tracey wrote: > On Sat, Jun 26, 2010 at 3:48 AM, derek wrote: > > Caught TypeError while rendering: coercing to Unicode: need string > > or buffer, NoneType found > > The typical reason for this message is a __unicode__ method for a model that > is not returning unicode. The traceback would help to reveal whether that is > what is going on in this case or if it is something else. > Sorry, I had thought the traceback I included above would be sufficient. I have since copied over the relevant UserProfile code, and a copy of the table that stores the data, to a minimal test app and was again able to reproduce the error. Here is the full traceback: Environment: Request Method: POST Request URL: http://127.0.0.1:8000/admin/auth/user/1/ Django Version: 1.2.1 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'vehicles.cars'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/ base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ options.py" in wrapper 239. return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/ cache.py" in _wrapped_view_func 69. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ sites.py" in inner 190. return view(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapper 21. return decorator(bound_func)(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in bound_func 17. return func(self, *args2, **kwargs2) File "/usr/local/lib/python2.6/dist-packages/django/db/transaction.py" in _commit_on_success 299. res = func(*args, **kw) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ options.py" in change_view 900. change_message = self.construct_change_message(request, form, formsets) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ options.py" in construct_change_message 566. 'object': force_unicode(added_object)}) File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py" in force_unicode 66. s = unicode(s) Exception Type: TypeError at /admin/auth/user/1/ Exception Value: coercing to Unicode: need string or buffer, NoneType found -- 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: Rendering the Admin app list?
On Jun 26, 6:14 pm, "euan.godd...@googlemail.com" wrote: > There is no reason why all views should pass that variable to the > template. It is more efficient to only pass the minimal variable > necessary to render the template Even the list is lazily evaluated > there is still unnecessary overhead in passing it when not needed. > > Euan > > On 26 June, 08:50, derek wrote: > > > > > On Jun 25, 8:45 pm, raj wrote: > > > > > Before I "pass the variable app_list"; do I not need to create what is > > > > in this variable first? If so, how? > > > > That template is rendered by the view, AdminSite.index() found at > > > django.contrib.admin.sites. Please Check it to know how it's done. > > > > Rajeesh. > > > Will do. I just find it very strange that, given I am working > > in_and_with the Admin app, this routine works *only* in the index > > page... > Thanks. That makes sense. For the record, I have found this snippet: http://djangosnippets.org/snippets/1921/ which generates the apps and models in a form usable in a template. The models are not sorted but seems like a minor issue. Derek -- 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: Error using inline displays with a user profile
On Jun 27, 8:06 pm, Karen Tracey wrote: > On Sun, Jun 27, 2010 at 1:54 PM, derek wrote: > > File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ > > options.py" in change_view > > 900. change_message = > > self.construct_change_message(request, form, formsets) > > File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ > > options.py" in construct_change_message > > 566. 'object': > > force_unicode(added_object)}) > > File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py" > > in force_unicode > > 66. s = unicode(s) > > > Exception Type: TypeError at /admin/auth/user/1/ > > Exception Value: coercing to Unicode: need string or buffer, NoneType > > found > > This traceback shows the admin attempting to create a change message for the > change history log. It's calling unicode() on the added object, but running > into trouble because the __unicode__ method for whatever object was added is > apparently returning None. Check the __unicode__ method for whatever type of > object you were adding here -- it appears to return None (at least in some > cases), which is not valid for a __unicode__ method. These methods must > return unicode or something that can be coerced to unicode (string or > buffer). > > Karen > --http://tracey.org/kmt/ It appears the error was on the def __unicode__(self) method for the UserProfile. Whatever I add there causes this error to be triggered; conversely, removing the method removes the problem. So that's the cause... I will try and figure out a solution. Thanks Derek -- 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.
Creating a many-to-many link for a UserProfile?
Django 1.2.1, with Python 2.6 I am trying to establish a many-to-many for a userprofile (working with a legacy database so some of the field names are a little strange...). The models I have are: class UserGrouping(models.Model): #many-to-many id = models.AutoField(primary_key=True, db_column='id') grouping = models.ForeignKey(Grouping, db_column='grouping_id') user = models.ForeignKey(User, db_column='user_id') class Meta: db_table = 'usergrouping' unique_together = (('grouping', 'user'), ) class UserProfile(models.Model): user = models.ForeignKey(User, db_column='user_id', unique=True, primary_key=True, blank=True, null=True, default=None) userid = models.CharField(verbose_name=_('ID'), unique=True, editable=False, max_length=6, blank=True, null=True) records = models.IntegerField(db_column='records', default=20, blank=True, null=True) groupings = models.ManyToManyField(UserGrouping, db_table="usergrouping") class Meta: db_table = 'user' The table structures are as follows: CREATE TABLE `usergrouping` ( `grouping_id` int(11) NOT NULL DEFAULT '0', `user_id` int(11) NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), UNIQUE KEY `usergrouping_combo` (`grouping_id`,`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 CREATE TABLE `user` ( `user_id` int(11) DEFAULT NULL, `userid` varchar(6) DEFAULT '', `records` int(11) NOT NULL DEFAULT '10', `LastChanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=MyISAM DEFAULT CHARSET=utf8 The error I get is: OperationalError at /admin/auth/user/895/ (1054, "Unknown column 'T2.userprofile_id' in 'where clause'") I am not sure why Django is looking for a "userprofile_id", and therefore how to go about creating the relationship? (If I remove the 'groupings' link, then the profile works as expected.) Thanks Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to develop cms on django
On Jun 29, 12:29 pm, samie wrote: > sir i am a beginner in python and django.. > > i want develop a content management system using django.. > > plz help me wht shld i do from where shld i start.. > > i am learning python from google videos and develop a application > which is available on django home website.. > > m using python 2.6 and django 1.2 If you don't want to build everything from scratch, you may want to look at: http://pinaxproject.com/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django admin - Edit parent model and related models on the same page
On Jun 28, 1:48 am, DoubleD wrote: > I want to be able to edit all data on one page. How can i achieve > this ? Should i modify my models? If so, then how should i modify > them? > > class TextStyle(models.Model): > color = models.CharField(_("color"), max_length=7) > style = models.CharField(_("style"), max_length=30) > typeface = models.CharField(_("typeface"), max_length=100) > > class GenericText(models.Model): > text = models.TextField(_("text")) > lines = models.IntegerField(_("number of lines")) > style = models.ForeignKey(TextStyle, verbose_name=_('text style'), > blank=False) > > class ExpirationDate(models.Model): > date = models.DateField(_("date")) > style = models.ForeignKey(TextStyle, verbose_name=_('text style'), > blank=False) > > class Coupon(models.Model): > name = models.CharField(_("name"), max_length=100) > slug = AutoSlugField(populate_from="title") > background = models.ImageField(upload_to="userbackgrounds") > layout = models.ForeignKey(Layout, verbose_name=("layout"), > blank=False) > logo = models.ImageField(upload_to="logos") > title = models.OneToOneField(GenericText, verbose_name=("title"), > blank=False, related_name="coupon_by_title") > body = models.OneToOneField(GenericText, verbose_name=("body"), > blank=False, related_name="coupon_by_body") > disclaimer = models.OneToOneField(GenericText, > verbose_name=("disclaimer"), blank=False, > related_name="coupon_by_disclaimer") > promo_code = models.OneToOneField(GenericText, > verbose_name=("promo code"), blank=False, > related_name="coupon_by_promo") > bar_code = models.OneToOneField(BarCode, verbose_name=("barcode"), > blank=False, related_name="coupon_by_barcode") > expiration = models.OneToOneField(ExpirationDate, > verbose_name=("expiration date"), blank=False, > related_name="coupon_by_expiration") > is_template = models.BooleanField( verbose_name=("is a > template"), ) > category = models.ForeignKey(Category, verbose_name=("category"), > blank=True,null=True, related_name="coupons") > user = models.ForeignKey(User, verbose_name=("user"), blank=False) Its not entirely clear what you want to achieve... have you looked at using inline model editing? http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: change displayed name of users object
On Jun 28, 7:54 pm, Jacob Fenwick wrote: > Is there a simple way to change the displayed name of the users object in > the auth package? > > I don't care about what it's called under the hood. I just want to change > what the user sees. > > I'd like to avoid changing the code directly in the Django library as that > will make upgrades difficult. > > I came across this article but it's quite old and I'm hoping there's a > better way: > > http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m... > > Jacob Have a look at: http://bradmontgomery.blogspot.com/2010/04/pretty-options-for-djangos-authuser.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: Creating and binding more than one model to a from
On Jun 28, 6:47 pm, thusjanthan wrote: > Hi, > > I have a Topic class I would like to create a form based on. BUT, I > want many of these objects so Topics. How do I obtain such a feature. > > Suppose my form object is as follows: > > class TopicForms(ModelForm): > class meta: > model = Topic > fields = ('topic_id','topic') > > I want to display more than one of the topics that is associated to a > particular object. Suppose its a topic about obama and there are 10 > topics. I want to display all 10 of these. and If they make a change > to one of them I would like to save that change on submission. I would > also like to provide additional blank topic fields for end users to > enter new topics about obama. Any help would be appreciated. I am a > little confused on the forms area of django. > > Nathan. Sounds a lot like "tagging". Have a look at this: http://showmedo.com/videotutorials/video?name=1100020&fromSeriesID=110 Even if its not exactly what you want, it may give you some ideas... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: change displayed name of users object
On Jun 29, 7:43 pm, Jacob Fenwick wrote: > Thanks for the link Derek. > > I don't think it quite does what I want. > > I guess I should have been more specific. > > I want to change how the Users object is displayed in the Django admin. > > This is a one line change in the Django code, but I would rather not change > Django if I can avoid it. > > Is there a way to do something like subclassing the Django Users object and > use that for authentication instead of the original Users object? > > Jacob > > On Tue, Jun 29, 2010 at 10:01 AM, derek wrote: > > On Jun 28, 7:54 pm, Jacob Fenwick wrote: > > > Is there a simple way to change the displayed name of the users object in > > > the auth package? > > > > I don't care about what it's called under the hood. I just want to change > > > what the user sees. > > > > I'd like to avoid changing the code directly in the Django library as > > that > > > will make upgrades difficult. > > > > I came across this article but it's quite old and I'm hoping there's a > > > better way: > > > >http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m... > > > > Jacob > > > Have a look at: > > >http://bradmontgomery.blogspot.com/2010/04/pretty-options-for-djangos... > "This is a one line change in the Django code" - no, there is no change to Django's code in this approach. The "subclassing" approach is probably best done with a UserProfile; there is lots written about that. For info related to your question, you could start with my original question here: http://groups.google.com/group/django-users/browse_thread/thread/d39e05a9b2d33e7b -- 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: Signal emitted after successful login?
On Jun 29, 9:51 pm, Daniel Hilton wrote: > On 29 June 2010 20:07, Andy McKay wrote:> On 2010-06-29, > at 10:48 AM, tiemonster wrote: > > >> Is a signal emitted after a successful login? I need to hook a > >> particular piece of code into that point in the application. > > One easy way is to wrap the login view function and execute your code > once a user has successfully been authorised. If you look at the > account app included in > Pinax, there is an example of how this could work. > > HTH, > Dan Dan - do you have URL for that "account app" module? Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Newbie Q: Is there a way to prevent Django from creating fields w. 'Not Null' by default?
On Jul 1, 10:16 pm, Barto wrote: > I've been following 'Writing Your First Django App. Pt. 1' > substituting my own object names in experiment. > > Noticed that when I told Django to create my tables, it did so giving > all (psycopg2/postgres) fields the 'notnull' setting. Easy to change > this via PgAdmin, but I'm wondering if it is possible to prevent 'notnull' > from being assumed as default. Also see: http://groups.google.com/group/django-users/browse_thread/thread/24b0f7fbcf58801e/d1cac0dba8dc993b -- 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: filtering admin data
On Jul 4, 3:06 pm, djnubbio wrote: > hi all; sorry for wasting your preciouse tume. > > I'm trouble with the following: > > class A(models.Model): > . > . > . > > class B(models.Model): > . > . > . > a= models.ForeignKey(A) > > class C(models.Model): > . > . > . > b= models.ForeignKey(B) > > How can i filter data that belongs to an A instance, while editing > class C instances, using django Admin? You have not given enough details to work out what you are actually trying to do. A filter can filter from a parent in the hierarchy, using a notation such as: C.objects.filter(b__a__name__icontains="spam") -- 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: Easiest way to pass variables between modelforms (genericforms)
On Jul 7, 12:44 am, Erich wrote: > I am using create_update.create_object to handle my forms (generic > forms both use modelforms). I have two forms. The second relies on the > pk of the first as a fk. I can't figure out what is the best practice > to A: save the pk as a variable or into the session, then B: pull that > variable either out of the session or another place, such as a global > variable. > > I could write the forms manually, but this does not seem to be the > most efficient way, unless create_object was meant for very simple > forms. I have tried using extra_context to call another function, but > I dont know if that is the best way either. Maybe have a look at: http://www.petersanchez.com/2008/09/26/django-formwizard-passing-data-between-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: list display based on logged-in user
On Jul 7, 11:40 pm, rahul jain wrote: > Hi there ! > > I would like to display model fields based on the logged-in user. > > If user is restricted user > > list_display = (field1, field2) > > else > > list_display = (field1, field2, field3, field4) > > How is it possible ? > Also see: http://stackoverflow.com/questions/2297377/how-do-i-prevent-permission-escalation-in-django-admin-when-granting-user-change -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is Django right for what I am trying to do
On Jul 9, 12:29 am, Martin Tiršel wrote: > On Thu, 08 Jul 2010 23:23:53 +0200, Bradley Hintze > > wrote: > > I guess I just don't like the model.py, views.py, templates, and > > url.py. In the tutorial you have to edit all of these and THEN you get > > something that you can send to the client. It's very confusing! How do > > they tie together? I probably need to do the tutorial again. It seems > > to me getting info from the user should be strait foreword but its not > > as displayed by the rather lengthy tutorial. But than I'm new to > > this... > > Hi, I am a Django beginner too. If you don't have experiences with MVC > programming pattern, it could be a lot harder, but as soon as you > understand it, you will not see many things so complicated. Django is a > framework which helps you to save time by not inventing a wheel again and > again, you don't need to know how Django's blackboxes works, you only need > to know how to use them to work for you. Forms are perfect example - you > specify what fields a form should have, what data should every field > contain and the boring part - displaying, validating and redisplaying you > can let to Django. If there is something you need to do differently as > default behaviour is, you can override it. Django is a little harder to > learn as I expected, but my advice is not to give up and try to read > documentation again and again until every part begins to fit together. > > What I am missing on Django, are high quality or complex tutorials. More complex or more detailed? (I would argue that The Django Book is about as high quality as you are ever going to get for a free tutorial) Try: http://www.hoboes.com/NetLife/pytown/django-beyond-sql/ or: http://opensourcebridge.org/2009/wiki/Django%3A_Thinking_Outside_The_Blog or: http://www.slideshare.net/jacobian/django-in-the-real-world-175 The real issue is that, because Django is a framework, designed to meet N number of possible needs, once you get "beyond the basics", the specifics start to diverge more and more from what _you_ actually need to do. My 2c Derek -- 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.
Paid support for Django?
Not sure if this is the right place to ask, but... how do I go about finding Django developers that offer support for development of Django apps. i.e. not do the development themselves, but be available to provide answers to key questions (the ones that typically are not answered on this mailing list), provide suggestions, code reviews and so on. (I assume that such support would be paid for, of course.) Thanks Derek -- 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.
Testing many-to-many models on a legacy database
Running Django 1.2.1 under Python 2.6. I am obviously missing something cruccial, but I am just not sure where this is... I have a setup which includes a number of many-to-many models in a legacy database. For example: class Grouping(models.Model): id = models.AutoField(primary_key=True, db_column='GroupingID') name = models.CharField(max_length=250, db_column='GroupingName', unique=True) class TaxAgreement(models.Model): id = models.AutoField(primary_key=True, db_column='TaxID') title = models.CharField(max_length=100, db_column='TaxTitle', unique=True) groupings = models.ManyToManyField(Grouping, db_table='taxagreementgrouping') class Meta: db_table = 'taxagreement' ... class TaxAgreementGrouping(models.Model): #many-to-many id = models.AutoField(primary_key=True, db_column='id') grouping = models.ForeignKey(Grouping, db_column='grouping_id') tax_agreement = models.ForeignKey(TaxAgreement, unique=True, db_column='taxagreement_id') class Meta: db_table = 'taxagreementgrouping' Now when I run the "python manage.py test", the run fails with this error: _mysql_exceptions.OperationalError: (1050, "Table 'taxagreementgrouping' already exists") and if I look through the table creation output statements, I see that 'taxagreementgrouping' table was created along with the 'taxagreement' one. Now if I change the TaxAgreement model to this: class TaxAgreement(models.Model): id = models.AutoField(primary_key=True, db_column='TaxID') title = models.CharField(max_length=100, db_column='TaxTitle', unique=True) groupings = models.ManyToManyField(Grouping) then the test runs just fine. However, when I now want to dump a copy of the database to serve a fixture, I run this: python manage.py dumpdata myapp > myapp/fixtures/myapp.json Error: Unable to serialize database: (1146, "Table 'taxagreement_grouping' doesn't exist") So now I go back to the database, and rename the TaxAgreementGrouping table: RENAME TABLE taxagreementgrouping TO taxagreement_grouping; and also update the model: class TaxAgreementGrouping(models.Model): #many-to-many id = models.AutoField(primary_key=True, db_column='id') grouping = models.ForeignKey(Grouping, db_column='grouping_id') tax_agreement = models.ForeignKey(TaxAgreement, unique=True, db_column='taxagreement_id') class Meta: db_table = 'taxagreement_grouping' Now the dump does not give me the above error anymore, but when I rerun the "python manage.py test", I get: _mysql_exceptions.OperationalError: (1050, "Table 'taxagreement_grouping' already exists") So obviously the problem - and I am not sure exactly what that is? - is not fixed... Any pointers or clues to resolve this? I really need to start testing sooner rather than later. Thanks Derek -- 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: Testing many-to-many models on a legacy database
On Jul 10, 4:40 pm, Rolando Espinoza La Fuente wrote: > On Sat, Jul 10, 2010 at 9:31 AM, Derek wrote: > > Running Django 1.2.1 under Python 2.6. > > I am obviously missing something cruccial, but I am just not sure where this > > is... > > I have a setup which includes a number of many-to-many models in a legacy > > database. For example: > > > class Grouping(models.Model): > > id = models.AutoField(primary_key=True, db_column='GroupingID') > > name = models.CharField(max_length=250, db_column='GroupingName', > > unique=True) > > class TaxAgreement(models.Model): > > id = models.AutoField(primary_key=True, db_column='TaxID') > > title = models.CharField(max_length=100, db_column='TaxTitle', > > unique=True) > > groupings = models.ManyToManyField(Grouping, > > db_table='taxagreementgrouping') > > Use through > keywordhttp://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > groupings = models.ManyToManyField(Grouping, through='TaxAgreementGrouping') > Thanks, this fixes those problems. Unfortunately, however, it also introduces a new error. When I try and start the app, I now get: ImproperlyConfigured at /admin/ 'TaxAgreementAdmin.fieldsets[6][1]['fields']' can't include the ManyToManyField field 'groupings' because 'groupings' manually specifies a 'through' model. I need to be able to use the "many to many" box in order to create the associations... Thanks Derek -- 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: Testing many-to-many models on a legacy database
On Jul 11, 4:23 pm, derek wrote: > On Jul 10, 4:40 pm, Rolando Espinoza La Fuente > wrote: > > > > > On Sat, Jul 10, 2010 at 9:31 AM, Derek wrote: > > > Running Django 1.2.1 under Python 2.6. > > > I am obviously missing something cruccial, but I am just not sure where > > > this > > > is... > > > I have a setup which includes a number of many-to-many models in a legacy > > > database. For example: > > > > class Grouping(models.Model): > > > id = models.AutoField(primary_key=True, db_column='GroupingID') > > > name = models.CharField(max_length=250, db_column='GroupingName', > > > unique=True) > > > class TaxAgreement(models.Model): > > > id = models.AutoField(primary_key=True, db_column='TaxID') > > > title = models.CharField(max_length=100, db_column='TaxTitle', > > > unique=True) > > > groupings = models.ManyToManyField(Grouping, > > > db_table='taxagreementgrouping') > > > Use through > > keywordhttp://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > > groupings = models.ManyToManyField(Grouping, through='TaxAgreementGrouping') > > Thanks, this fixes those problems. Unfortunately, however, it also > introduces a new error. When I try and start the app, I now get: > > ImproperlyConfigured at /admin/ > 'TaxAgreementAdmin.fieldsets[6][1]['fields']' can't include the > ManyToManyField field 'groupings' because 'groupings' manually > specifies a 'through' model. > > I need to be able to use the "many to many" box in order to create the > associations... > As a follow-up, I see from the docs that the many to many widget _cannot_ be used in a case where "through" is specified, because the assumption is that extra fields will be added to the join model. This is _not_ the case for me, so this implies I should not have to use the "through" option to solve my original problem. [Sidebar: Interestingly, it has been suggested that it _could_, in future, be possible to do this... (see http://www.mail-archive.com/django-upda...@googlegroups.com/msg45249.html): "The fancy solution would be to loosen this condition slightly and allow an m2m field to be in the fields list (and therefore allow an m2m widget be used) *iff* the through model is just 2 foreign keys with a unique_together pairing (i.e., if the through model is exactly the same as the m2m model that is be automatically generated for the non-explicit through case)."] -- 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: None field : Admin save setting it to empty value instead of NULL during save
On 15 July 2010 21:10, rahul jain wrote: > anyone on this ? > > On Tue, Jul 13, 2010 at 2:44 PM, rahul jain > wrote: > > Could it be generic ?. I mean i don't want to specify self.naughty_field. > > > > How to do it for self.any_field ? > > > > RJ > > > > On Tue, Jun 29, 2010 at 9:29 AM, euan.godd...@googlemail.com > > wrote: > >> Django admin can't differentiate between empty string and None and > >> picks empty string which makes sense in most cases. > >> > >> If you don't like the idea of empty string override the save method > >> and coerce empty string to None before calling the super classes save, > >> e.g. > >> > >> class YourModel(models.Model): > >>... > >> > >> def save(self, *args, **kwargs): > >>if self.naughty_field == '': > >>self.naughty_field = None > >>super(YourModel, self).save(*args, **kwargs) > >> > >> Euan > >> > >> On Jun 29, 4:15 pm, rahul jain wrote: > >>> Hi there ! > >>> > >>> One of my model fields attribute is set to null="true" to allow None > >>> values. But if I use admin to save those model objects and leave it > >>> blank, it saves blank value instead of None. > >>> How to fix this ? > >>> > >>> And Blank value is not None. Blank is "" (empty) but None is NULL in > databases. > >>> > >>> -RJ > Have a look at: http://www.mail-archive.com/django-users@googlegroups.com/msg16095.html some useful pointers on what fields are and how to access them. Also: http://stackoverflow.com/questions/3159614/iterating-through-model-fields-django -- 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: comment template tag not working
On Jul 17, 10:03 pm, Joel Klabo wrote: > I got it to work by adding: {% load comments %}. I had put the load > comments tag in my base.html but didn't work there for some reason. > > On Jul 17, 1:00 pm, Joel Klabo wrote: > > > I am trying to use the get_comment_list template tag and I keep > > getting errors. Any ideas?http://dpaste.org/nCx0/ The reason is in the documentation (http://docs.djangoproject.com/en/ dev/topics/templates/#custom-libraries-and-template-inheritance): "When you load a custom tag or filter library, the tags/filters are only made available to the *current* template - not any parent or child templates along the template-inheritance path." -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is Django right for what I am trying to do
On Jul 19, 1:19 am, Martin Tiršel wrote: > On Fri, 09 Jul 2010 16:50:14 +0200, derek wrote: > > More complex or more detailed? (I would argue that The Django Book is > > about as high quality as you are ever going to get for a free > > tutorial) > > > Try:http://www.hoboes.com/NetLife/pytown/django-beyond-sql/ > > > or: > >http://opensourcebridge.org/2009/wiki/Django%3A_Thinking_Outside_The_... > > > or:http://www.slideshare.net/jacobian/django-in-the-real-world-175 > > Thanks for links, as I have some time, I will go through :) > > I would appreciated if there are some tutorials how to use some advanced > things in real web applications and not how to display first 10 blog > entries and so on :) > > > The real issue is that, because Django is a framework, designed to > > meet N number of possible needs, once you get "beyond the basics", the > > specifics start to diverge more and more from what _you_ actually need > > to do. > > > My 2c > > Derek > > You are right. > Ok, you seem not to understand what I am saying, so I will try and explain some more. Building very complex apps is a very specific activity and that is why there are no tutorials on "advanced things" (as you call them, without being specific as to what it actually is you need). The point is that once you understand the basics and have been through the process to construct a "standard" website with Django - and, yes, you *can* do that with all the resources available to you on the web - you will find yourself able to envision and conceptualize building more complex ones. In that process you will ask more "advanced" questions and get "advanced" answers that will make more sense to you *because* you now understand the fundamentals. I don't believe there is a short- cut to that learning process. Hope this makes sense. Derek -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: about some ideas for our very largest project
On Jul 21, 11:07 am, RNGLAB wrote: > hi django peoples > > i m rıdvan from turkey and working in a web based big project for now > this project about web based healthcare and hospital systems. > and the project is realty big.. we have a team for this. > > we are searching a different tech. from .net or java. than we find and > develop some ideas about pyton and django. > i wanna ask you about that.. first i must say, i m not enough in > django and pyton. so i m asking in this level :) > > how is django and pyton about this project? this subjects? it can do > very institutional applications? > django tech. can support very big web based applications realty ? if > it supports what can we do with django and pyton? what is djangos > differents from .net or java? > > if you can share information about this very works for us.. > > thanks for your answers.. First off, your limitation is not likely to be Django or Python per se, both of which are capable of handing any web app development... but your own (you+team) knowledge about these domains. Even the best- of-the-best-of-the-best will take some time to get comfortable with these tools. For some discussions as to Django suitability and use in large apps: http://groups.google.com/group/django-users/browse_thread/thread/12c898ac406b906c/ddf0bc81fe2c117b?lnk=gst&q=suitable#ddf0bc81fe2c117b http://groups.google.com/group/django-users/browse_thread/thread/3c8a6b30696565ad/bef1ce2bda1b6fca?lnk=gst&q=scalable#bef1ce2bda1b6fca (e.g. see Dave Snider's remarks in the above thread). Finally, also have a look at: http://www.djangosites.org/ Hope this helps Derek -- 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: Help and Training
On Jul 22, 4:46 am, zero00 wrote: > Well Fred the enviorment where I live theres almost no programmers and > the ones that I do know that are experienced are Java developers. > Theres really no Programming community at all. > Much less a language that is new and also not studied on the > universities here. So I have that disadvantage. > Looking at : http://en.wikipedia.org/wiki/Timeline_of_programming_languages#1990s I see that Python was created in 1991, and Java in 1995... so I would not call it a "new" language. But fortunately there are _many_ good books available - for free! - online. I would also think that the basics of programming taught at universities will be applicable for you. A number of American universities are starting to switch to Python as their "first" language... maybe the ones where you are will start to follow. -- 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: Plese guide to solve this
On Jul 21, 7:38 pm, jaymzcd wrote: > I'm going to guess you have been following along with > thehttp://www.djangobook.com/ > site. It was great in the day but *do not use that* now-a-days as it > covers 0.96. There have been significant changes, one of which is the > maxlength to max_length on CharFields. Stick with the particular > version you are using from docs.djangoproject.com. Even changes from > 1.1 to 1.2 are significant enough that reading the wrong version's > docs can give you headaches. Actually, the new version of the Django Book is compatible with Django 1.0. I found it to be an _excellent_ introduction to the fundementals, and well worth the read. For the latest stuff, of course there is the official documentation which you must refer to. -- 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.
Simple Admin interface question - change header?
I'm sure this is simple... but, how do I change the header text that appears at the top of every change list? i.e. instead of "Select XXX to change", I'd like to have "List of XXX's" (where XXX's is the plural form of the object name) Is this in an admin template and, if so, which one? Thanks Derek -- 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: Filtering within a ModelForm
On Jul 26, 6:52 pm, "Casey S. Greene" wrote: > Does anyone have a hint for this (or an idea of where to get started in > the documentation)? This seems relatively simple so my best guess is > that there is something that I am just missing. > > Thanks! > -- Casey > > On 07/22/2010 10:16 AM, Casey S. Greene wrote: > > > I am trying to figure out a reasonable way to filter using a queryset > > within a ModelForm. > > > In a simple example, I have three models (A, B, and C). > > C has many A and B > > A and B have a many to many relationship. > > > Assume that some instances of C and instances of B already exist. > > > I am using the create_object generic view to allow users to create > > instances of A but not to select associated Bs. I'm then using > > update_object generic view to allow users to select the Bs associated > > with A. I've created a class that inherits from forms.ModelForm that > > defines the form. In that I have forms.ModelMultipleChoiceField() for > > selecting associated Bs. What I want to do is use the queryset to filter > > to only show those Bs that share C with this instance of A. > > > I am confused as to how to do this type of query while passing a > > form_class from the update_object generic view. > > > I have tried doing this in __init__() but I get a TypeError that the > > form is not callable when I try to pass arguments. > > > Thanks in advance for your help and time, > > -- Casey Well, I have never worked with "object generic view" items before, but a similar (I think?) question was raised on stackoverflow: http://stackoverflow.com/questions/738301/how-to-modify-choices-of-modelmultiplechoicefield Maybe the discussion (and links) there can help as a starting point? -- 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: Filtering within a ModelForm
On Jul 26, 6:52 pm, "Casey S. Greene" wrote: > Does anyone have a hint for this (or an idea of where to get started in > the documentation)? This seems relatively simple so my best guess is > that there is something that I am just missing. > > Thanks! > -- Casey > > On 07/22/2010 10:16 AM, Casey S. Greene wrote: > > > I am trying to figure out a reasonable way to filter using a queryset > > within a ModelForm. > > > In a simple example, I have three models (A, B, and C). > > C has many A and B > > A and B have a many to many relationship. > > > Assume that some instances of C and instances of B already exist. > > > I am using the create_object generic view to allow users to create > > instances of A but not to select associated Bs. I'm then using > > update_object generic view to allow users to select the Bs associated > > with A. I've created a class that inherits from forms.ModelForm that > > defines the form. In that I have forms.ModelMultipleChoiceField() for > > selecting associated Bs. What I want to do is use the queryset to filter > > to only show those Bs that share C with this instance of A. > > > I am confused as to how to do this type of query while passing a > > form_class from the update_object generic view. > > > I have tried doing this in __init__() but I get a TypeError that the > > form is not callable when I try to pass arguments. > > > Thanks in advance for your help and time, > > -- Casey And another one: http://code-blasphemies.blogspot.com/2009/04/dynamically-created-modelmultiplechoice.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: Manual schema migration
On Aug 2, 12:57 pm, Torsten Bronger wrote: > Hall chen! > > Does anybody know a tutorial for Django-related schema migration by > using the SQL console directly? (Preferably PostgreSQL.) We > evaluate South at the moment, but we'd like to have the low-level > knowledge as a fallback. Of course, general SQL knowledge can be > assumed. > > It needn't be an online resource. If this is discussed in one of > the published Django books, this would be great to know, too. > Not sure this is _quite_ what you want, but there are some generic guidelines here: http://blog.aplikacja.info/2009/10/migrate-database-schema-in-django/ and an interesting article here: http://wrongsideofmemphis.wordpress.com/2010/05/21/migrating-data-with-django-1-2/ -- 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.
Good practices for storing "constant" values?
I am currently using two files - constants.py and choices.py to store all the "fixed" (and also-to-be-translated) data that I use in my app. I am now wondering: (a) is this a good/worthwhile/common thing to do? (b) should I be doing the same for other fixed strings, even if they do not need to be translated e.g. custom SQL code that is used in other files (the idea being that there is one place to look to find everything - particularly useful if the models+database change in some way) Thanks Derek -- 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: Announces django-guardian: per object permissions for Django 1.2
On Aug 4, 1:20 am, lukaszb wrote: > Hi all, > > I'd like to announce django-guardian - very basic yet usable per > object permissions > implementation for Django 1.2, using new authorization backend > facilities. > > It was created during 2 days sprint, code have been released and may > be found athttp://github.com/lukaszb/django-guardian/. > Documentation is available athttp://packages.python.org/django-guardian/. > > Currently I think there should be better integration with admin app > and some shortcuts (permission assignment/removal) > should support table-level permissions as well. > > If you spot a bug or have an idea how to improve this little app, > please spare a minute at issue tracker, which is located > athttp://github.com/lukaszb/django-guardian/issues. > > Hope someone would find this useful. No doubt this will be extremely useful! For me, integration with the Django admin is a must, though, as permissions will need to be assigned by users themselves via the standard interface. One (maybe stupid) question: Can rights only be assigned to the pre- specified "Group", or can any model that handles user grouping (I have some custom ones in my app) be used? Thanks Derek -- 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: Announces django-guardian: per object permissions for Django 1.2
On Aug 4, 9:18 pm, lukaszb wrote: > Welll, at the django.contrib.auth there are only those (User and > Group) models for which one may define permission sets and I wanted > guardian to be as simply as possible - so it is not possible to assign > permission to other model even if it "groups users". At one point I > thought it could be nice to implement some kind of "roles" but I've > finally decided it would be better to stick to facilites provided by > new Django version. > > On the other hand, I'm not sure if it is needed to create new > "grouping models" - I often use intermediate models for this (i.e. > Team model with fk to Group among other fields). Let me know if you > have different experience. > > On 4 Sie, 15:26, derek wrote: > > > On Aug 4, 1:20 am, lukaszb wrote: > > > > Hi all, > > > > I'd like to announce django-guardian - very basic yet usable per > > > object permissions > > > implementation for Django 1.2, using new authorization backend > > > facilities. > > > > It was created during 2 days sprint, code have been released and may > > > be found athttp://github.com/lukaszb/django-guardian/. > > > Documentation is available athttp://packages.python.org/django-guardian/. > > > > Currently I think there should be better integration with admin app > > > and some shortcuts (permission assignment/removal) > > > should support table-level permissions as well. > > > > If you spot a bug or have an idea how to improve this little app, > > > please spare a minute at issue tracker, which is located > > > athttp://github.com/lukaszb/django-guardian/issues. > > > > Hope someone would find this useful. > > > No doubt this will be extremely useful! For me, integration with the > > Django admin is a must, though, as permissions will need to be > > assigned by users themselves via the standard interface. > > > One (maybe stupid) question: Can rights only be assigned to the pre- > > specified "Group", or can any model that handles user grouping (I have > > some custom ones in my app) be used? > > > Thanks > > Derek That's a pity; guess I will need to stick to my home-grown code in that case. -- 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: Documentation problems: Django at a glance
On Aug 24, 3:36 pm, Rodney Topor wrote: > OK, it seems I misunderstood the purpose of this page. I still think > some of the code is misleading, but I accept that the examples is > intended to be indicative rather than descriptive, and that it would > indeed take much more space to describe how to get this example > working. I'm sorry to have bothered you all. > Rodney >From the 2nd paragraph: "The goal of this document is to give you enough technical specifics to understand how Django works, but this isn’t intended to be a tutorial or reference..." At 6 pages long, its quite a detailed "overview", but then Django docs (in general) seem to err on the side of saying too much rather than too little. A shade different from most other OSS. I've said it before and I'll say it again: you'll be very hard pressed to find better written documentation for any other open source (and many many commercial) packages. -- 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: what to do instead of adding to Query.extra_where ?
On Sep 3, 2:10 am, Steve Holden wrote: > On 9/2/2010 1:44 AM, Paul Winkler wrote: > > > Hah. That was a pretty long message relative to how quickly I found > > the answer myself :-p > > Sorry for the noise. > > > For posterity, extra(where=...) is indeed the solution. I overlooked > > the obvious: > > the class I was trying to fix is itself a subclass of QuerySet. So > > given this line: > > > clone.query.extra_where += ('db_newsitem.id = > > db_attribute.news_item_id',) > > > the replacement is now: > > > clone = clone.extra(where=('db_newsitem.id = > > db_attribute.news_item_id',)) > > > Seems to work fine. > > [...] > > Once again this group proves itself at least as valuable as a stuffed > bear ;-) > > regards > Steve Steve - any chance you could translate that analogy into POE (Plain Old English)...?! Derek > DjangoCon US 2010 September 7-9http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Anyone using django-adminhelp?
Hi If anyone is using the app django-adminhelp ( http://github.com/semente/django-adminhelp) please contact me. Thanks Derek -- 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: Automatically loading data into Django
Reading CSV with Python, see: http://www.linuxjournal.com/content/handling-csv-files-python I'm not sure you need a dictionary view as well (?) - the above tutorial shows how tuples are created, which may be sufficient for your needs. Working through a Django tutorial, or the first part of The Django Book should allow you to undertake the steps, while using the Django shell: 1. create instances of your models, 2. populate them, and 3 save them. You will, in any case, need this knowledge when working with Django. On Sep 7, 8:14 pm, Duane Hilton wrote: > Thanks for the response. I think that is exactly what I'm looking for. > But, being a newb, this raises new questions that I will spare the > group. Could you point me toward a book or tutorial that would show me > how to do that? > > Thanks. > > On Tue, Sep 7, 2010 at 10:23 AM, Shawn Milochik wrote: > > It doesn't seem like converting your data into fixtures will provide > > any advantage. If it's pipe-delimited, then just write a Python script > > imports the CSV module (which can handle other delimiters) and your > > model(s). > > > Use it to read the data and convert it to dictionaries, then create > > instances of your models, populate them, and save them. > > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django - Multiple columns primary key
On Sep 10, 6:40 pm, Russell Keith-Magee wrote: > On Fri, Sep 10, 2010 at 7:47 PM, naoy.teruh wrote: > > Hello, > > > I would like to implement multicolumns primary keys in django. > ... > > Did I miss something ? > > Yes - Multicolumn primary keys aren't currently supported in Django. > It's a long-standing feature request, logged as ticket #373. > > Yours, > Russ Magee %-) See also: http://groups.google.com/group/django-users/browse_thread/thread/302a8b82dbc30090 -- 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: change ordering of objects/rows on change list view on admin
The admin column headers should be "clickable" for you to sort in ascending/descending order. On Sep 19, 11:31 pm, rahul jain wrote: > I mean graphically/directly on the UI itself. > > On Sun, Sep 19, 2010 at 2:29 PM, Sævar Öfjörð wrote: > > >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri... > > > On Sep 19, 10:56 pm, rahul jain wrote: > > > Hi there !, > > > > How to change ordering of objects/rows on change list view on admin ? > > > > --Rahul > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Possible to have dynamic drop down list in ModelForm?
If you search this list and /or the web, you'll see a number of examples on how to do this. On Sep 19, 8:42 am, Andy wrote: > I have a model FieldReport that has, among other fields, these two > fields: > > -country > -city > > Both "country" and "city" are lists of choices. > > I want to have a form FieldReportForm as a ModelfForm based on the > model FieldReport. I want to have "country" and "city" represented as > drop down lists. Moreover, "city" should be a dynamic list based on > the selected value of "country". > > For example, if someone selects the value "US" for "country", then > "city" should be a list of US cities only, all cities in other > countries shouldn't be loaded onto that list. > > Is this something that would work with Django's ModelForm? How would > you implement something like this? > > Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.