Re: [M-R] lookup like Article.objects.filter(id__in = []) will fail
Cheng Zhang wrote: >I tried lookup like Article.objects.filter(id__in = []), which will >have SQL statement whose where clause is something like 'WHERE >("poll_article"."id" IN ())'. Such SQL statement is ok with SQLite >but invalid for PostgreSQL. > >I work around this problem with code like: >if len(id_list) > 0: > Article.objects.filter(id__in = id_list) >else: > Article.objects.filter(id__isnull = True) > >Should this problem be deal with on the Django framework level, >instead of application level? > > It shouldn't. Because in defferent situations people need different things when the list in the condition is empty. Empty list can mean "don't filter, get everything" or "equals to nothing so get empty list". And with your workaround user can get some arbitrary set of records where the field value happens to be NULL. So this really should be handled manually. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
[M-R] lookup like Article.objects.filter(id__in = []) will fail
Hi, folks I tried lookup like Article.objects.filter(id__in = []), which will have SQL statement whose where clause is something like 'WHERE ("poll_article"."id" IN ())'. Such SQL statement is ok with SQLite but invalid for PostgreSQL. I work around this problem with code like: if len(id_list) > 0: Article.objects.filter(id__in = id_list) else: Article.objects.filter(id__isnull = True) Should this problem be deal with on the Django framework level, instead of application level? BR, - Cheng --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Custom manipulator - multiple records
Hi, I'm trying to set up a custom manipulator for a timesheet app. I don't have the code in front of me at the moment but I'll try to create a extremely simplified example (they'll be errors since I don't have Django on this computer to validate the code, but it's just to give you a better idea). The custom view will display 7 days (Mon->Sun) of timesheets for entry. The model is for individual days so the view consolidates the entries. It should also display the timesheet details for the week in a edit inline (InlineObjectCollection?) The problems lie in the following areas: * Manipulator - edit_inline/InlineObjectCollection * Template - {% for ts_detail in form.timesheetdetails %} Does anyone know how I can acomplish this? Should I be subclassing timesheets.AddManipulator instead in my custom manipulator? Model -=-=- class Timesheet(meta.Model): timesheet_date = meta.DateField() start_time = meta.TimeField() end_time = meta.TimeField() class TimesheetDetail(meta.Model): timesheet = meta.ForeignKey(Timesheet, edit_inline=meta.TABULAR, num_in_admin=3, num_extra_on_change=1) job = meta.CharField(maxlength=50, core=True) no_of_hours = meta.TimeField() Manipulator -=-=-=-=-=- class TimesheetWeekAddManipulator(formfields.Manipulator): def __init__(self): self.fields = ( formfields.HiddenField(field_name="date_mon", is_required=True) formfields.TimeField(field_name="start_time_mon", is_required=True), formfields.TimeField(field_name="end_time_mon", is_required=True), formfields.HiddenField(field_name="date_tue", is_required=True) formfields.TimeField(field_name="start_time_tue", is_required=True), formfields.TimeField(field_name="end_time_tue", is_required=True), . . formfields.HiddenField(field_name="date_sun", is_required=True) formfields.TimeField(field_name="start_time_sun", is_required=True), formfields.TimeField(field_name="end_time_sun", is_required=True), ) ##TODO: edit_inline/InlineObjectCollection def save(self, new_data): # My save code goes here pass View -=-= def add_timesheet(request): manipulator = TimesheetWeekAddManipulator() if request.POST: new_data = request.POST.copy() errors = manipulator.get_validation_errors(new_data) if not errors: manipulator.do_html2python(new_data) return HttpResponseRedirect("/timesheet/success") else: errors = new_data = {} # Set the values for the HiddenFields - can't remember the code but it would be here! form = formfields.FormWrapper(manipulator=manipulator, data=new_data, error_dict=errors, edit_inline=True) return render_to_response('timesheet/add', {'form': form}) Template -=-=-=-= I've removed most of the stuff including error reporting so that it's easier to read. MON TUE WED THU FRI SAT SUN Start {{ form.date_mon }}{{ form.start_time_mon }} {{ form.date_tue }}{{ form.start_time_tue }} {{ form.date_wed }}{{ form.start_time_wed }} {{ form.date_thu }}{{ form.start_time_thu }} {{ form.date_fri }}{{ form.start_time_fri }} {{ form.date_sat }}{{ form.start_time_sat }} {{ form.date_sun }}{{ form.start_time_sun }} End {{ form.end_time_mon }} {{ form.end_time_tue }} {{ form.end_time_wed }} {{ form.end_time_thu }} {{ form.end_time_fri }} {{ form.end_time_sat }} {{ form.end_time_sun }} job hours MON TUE WED THU FRI SAT SUN {% for ts_detail in form.timesheetdetails %} {{ ts_detail.job }} {{ ts_detail.no_of_hours_mon }} {{ ts_detail.no_of_hours_tue }} {{ ts_detail.no_of_hours_wed }} {{ ts_detail.no_of_hours_thu }} {{ ts_detail.no_of_hours_fri }} {{ ts_detail.no_of_hours_sat }} {{ ts_detail.no_of_hours_sun }} {% endfor %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: got unexpected keyword argument
On Sat, Apr 29, 2006 at 08:20:30PM -0500, James Bennett wrote: > In the tutorial, the field on the Choice model ('poll') is the same as > the name of the model it's being related to ('poll'), which is why it > looks that way. Whenever they're different, you want to use the name > of the field on your model. Which is why I said a few weeks ago that the choice of field and class names for the tutorial must be such that there can be no confusion (this is a learning example), and the way that field and class names are documented should be exceedingly clear too... -- Glenn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: got unexpected keyword argument
On 4/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > This is not what I understood from reading and practicing the tutorial > 1: In the tutorial, the field on the Choice model ('poll') is the same as the name of the model it's being related to ('poll'), which is why it looks that way. Whenever they're different, you want to use the name of the field on your model. -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: got unexpected keyword argument
On 4/28/06, Luis P. Mendes <[EMAIL PROTECTED]> wrote: > class Servico(meta.Model): > ~codigo = meta.TextField(maxlength=4) > ~nome = meta.CharField(maxlength=80) > > ~def __repr__(self): > ~return self.nome > > class Cadastro(meta.Model): > ~serv_clientes = meta.ForeignKey(Servico) > ~nome = meta.CharField(maxlength=200) > ~ (...) > ~def __repr__(self): > ~return self.nome > > when I try: > lista_sps = cadastros.get_list(servicos__id__exact=2) > from within a view, I get: > > TypeError at /cadastro/pesquisa/ > got unexpected keyword argument 'servicos__id__exact' Hi Luis, When using the Django database API, you use the field names, not the model names. So you want this: cadastros.get_list(serv_clientes__id__exact=2) Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
polls tutorial: How to delete choices and Images?
Hello list members! Since yesterday I am testing around with Django, and this GREAT tool impresses me a lot! So, I still play with the poll tutorial. I trying to make some improvements to it's code, to learn techniques I will use in future work. I.e. I added image-upload. Adding works perfectly, but I wonder how to delete an added image. The same question appears for choices. Here is my polls.py how it looks now: #polls.py from django.core import meta # Create your models here. from django.core import meta class Poll(meta.Model): question = meta.CharField(maxlength=200) pub_date = meta.DateTimeField('date published', auto_now_add=True) image = meta.ImageField( 'Attach Image', upload_to='.', blank=True ) def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' def __repr__(self): return self.question class META: admin = meta.Admin( list_filter = ['pub_date'], date_hierarchy = 'pub_date', list_display = ('question', 'pub_date', 'was_published_today'), fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}), ('Images',{'fields':('image',)}), ), ) class Choice(meta.Model): poll = meta.ForeignKey(Poll, edit_inline=meta. TABULAR, num_in_admin=3) choice = meta.CharField(maxlength=200, core=True,blank=True) votes = meta.IntegerField(default=10, core=True) def __repr__(self): return self.choice --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: magic-removal on Windows XP Pro
Malcolm, Thanks for the explanation. Richard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: got unexpected keyword argument
This is not what I understood from reading and practicing the tutorial 1: # The API automatically follows relationships as far as you need. # Use double underscores to separate relationships. # This works as many levels deep as you want. There's no limit. # Find all Choices for any poll whose pub_date is in 2005. >>> choices.get_list(poll__pub_date__year=2005) [Not much, The sky, Just hacking again] Luis P. Mendes --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: [M-R] __repr__ or __str__?
On Sat, 2006-04-29 at 14:49 +0200, Petar Marić wrote: > Looking through some recent changes I noticed that some M-R code uses > __repr__ and some new checkins use __str__ > > Is there anything we need to know? Short answer: You need to know that Django is coming around to the Pythonic way of doing things. :-) Use __str__ where you want a friendly string to appear. Don't use __repr__ where you should be using __str__. Longer answer: (you probably know all this, but let's get it in the archives anyway)... In general (in Python), __str__ is a method that returns a user-friendly, human-readable string representing the class. __repr__ returns something that is lower-level, more machine processable (the Python docs recommend that __repr__ either returns a string that can be used as a Python expression to recreate the class, or a string of the form "<...some useful description...>"). In Django terms, this means that the useful string you see in Admin classes and elsewhere should really be the thing returned by __str__ and that __repr__ should be left alone to return something like "". A while back now, changes were checked into the admin component and elsewhere to ensure that __str__ was used wherever necessary (note that __str__ falls back to using __repr__ if the former is not defined, so the change was backwards compatible). If anything remains that should be presenting a user readable string and it is using a %r formatter or calling repr() explicitly, that is a bug. However, it was not deemed high priority to go back and retrofit all the existing code to implement __str__ instead of __repr__, since there is so much else to do. You will notice, however, that some of Adrian's recent checkins as he is proofreading the documentation change the suggestion so that people are encouraged to use __str__ where appropriate. Cheers, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
[M-R] __repr__ or __str__?
Looking through some recent changes I noticed that some M-R code uses __repr__ and some new checkins use __str__ Is there anything we need to know? -- Petar Marić *e-mail: [EMAIL PROTECTED] *mobile: +381 (64) 6122467 *icq: 224720322 *skype: petar_maric *web: http://www.petarmaric.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django Admin CSS Problems in Safari
Matthew Flanagan schrieb: > I can confirm that i'm seeing this padding issue in safari and the > webkit inspector shows: > padding-top:10px; > padding-right:20px; > padding-bottom:10px; > padding-left:20px; > > I've been seeing it since wilson did the split of all the css files a > while back but I thought it was something i had done. I just removed > all my css customizations and i'm still seeing it. Add "padding:0px;" > to #container in layout.css fixed it for me. > That works, thank you Matthew. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: magic-removal on Windows XP Pro
On Sat, 2006-04-29 at 03:20 -0700, RichardH wrote: > Hello. I am new to django but have had 0.91 working on Windows XP. Just > tried the 0.92 svn version of magic-removal (reports 0.91), but it > comes up with an IndexError on one of the examples. I note that all of > the code/documentation for magic-removal seems to be Linux based. Am I > pushing too far with it on Windows or have I missed something? > Interpreter output below: > > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from django.db import models > >>> class Person(models.Model): > ... first_name = models.CharField(maxlength=30) > ... last_name = models.CharField(maxlength=30) > ... > Traceback (most recent call last): > File "", line 1, in ? > File > "c:\python24\lib\site-packages\Django-0.91-py2.4.egg\django\db\models\base.py", > line 45, in __new__ > new_class._meta.app_label = model_module.__name__.split('.')[-2] > IndexError: list index out of range > >>> It's more that it is not designed to be used from the interactive prompt like this. The above example does not work on Linux either (although the error message is slightly different). Django does some inspection of the module name when creating a class and since the interactive prompt is not in any well-defined module namespace, things go awry. Try creating your classes inside files, as per normal, and you will find this isn't a problem. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
magic-removal on Windows XP Pro
Hello. I am new to django but have had 0.91 working on Windows XP. Just tried the 0.92 svn version of magic-removal (reports 0.91), but it comes up with an IndexError on one of the examples. I note that all of the code/documentation for magic-removal seems to be Linux based. Am I pushing too far with it on Windows or have I missed something? Interpreter output below: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from django.db import models >>> class Person(models.Model): ... first_name = models.CharField(maxlength=30) ... last_name = models.CharField(maxlength=30) ... Traceback (most recent call last): File "", line 1, in ? File "c:\python24\lib\site-packages\Django-0.91-py2.4.egg\django\db\models\base.py", line 45, in __new__ new_class._meta.app_label = model_module.__name__.split('.')[-2] IndexError: list index out of range >>> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---