Re: sample app for beginner
Chuck, The Django tutorial should get you going: http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01 And an app. published earlier on this list: http://code.google.com/p/django-todo/ Happy coding. Gerard. Chuck Bai wrote: > Does anyone know a sample Django 1.0 application with complete source > code that is good for beginner to explore? > > Thanks, > > > -- urls = { 'fun': 'www.zonderbroodje.nl', 'tech': 'www.gp-net.nl' } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelMultipleChoiceField and initial values
Wow this is really screwing me royal. Doesn't work with any form of select, best I can tell initial doesn't work with ChoiceFields at all. I've tried going into the source and logging out the value param to the widget and it is always just []. Am I on crack, can somebody verify, so I can file a bug report if I'm not. ( by default these days I just assume I'm an idiot. ) Vance On Sat, Sep 20, 2008 at 8:24 PM, Vance Dubberly <[EMAIL PROTECTED]> wrote: > Ok hopefully this will be the last stupid question I ask for a long > time... been struggling with this for several hours: > > I've got a ModelMultipleChoiceField in a form as such > > class ApplicationCriteraForm(forms.Form): > pay_hourly = forms.CharField() > pay_yearly = forms.CharField() > locations = > forms.ModelMultipleChoiceField(Location.objects.all(),widget=forms.CheckboxSelectMultiple()) > transportation_method = > forms.ModelMultipleChoiceField(TransportMethod.objects.all(), > widget=forms.CheckboxSelectMultiple()) > driving_violations = forms.ChoiceField(BOOLEAN_CHOICE, > widget=forms.CheckboxSelectMultiple()) > > Now when I use this form I may have preset data for it, as in the form > is being used to update info instead of create it so I do something > like this: > > criteria_form = ApplicationCriteraForm(initial={ >'pay_hourly' : application.pay_hourly, >'pay_yearly' : application.pay_yearly, >'locations ' : application.locations, >'transportation_method' : application.transportation_method, >'driving_violations' : application.driving_violations > }) > > None of the multiple choice fields pre-popluate with data. I've tried > a number of different methods as it looks like what the various > SelectMultiple widgets expect is a list of the id's but none of the > following work: > > > 'locations ' : application.locations, > 'locations ' : application.locations.all(), > 'locations ' : [ int(location.id) for location in application.locations.all()] > 'locations ' : application.locations.values() > > Also it doesn't matter whether it's the CheckboxSelectMultiple or another. > > Not real sure where what else to try... digging through django source > cause I'm sure I'm doing something amazingly stupid. > > Vance > > > > > > -- > To pretend, I actually do the thing: I have therefore only pretended to > pretend. > - Jacques Derrida > -- To pretend, I actually do the thing: I have therefore only pretended to pretend. - Jacques Derrida --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: filter queryset in admin
Assuming you're using Django v1.0 ... you could override the queryset method in your class that defines the admin properties for your class. For example: class MyAdminClass(admin.ModelAdmin): def queryset(self, request): # Limit the queryset to some subset based on the value of request.user To see how queryset behaves by default, look at django.contrib.admin.options.py Hope that helps. On Sep 21, 9:04 am, Alessandro <[EMAIL PROTECTED]> wrote: > I want staff users to be able to see and edit only their objects. > With newforms admin I managed to avoid cross user editings with > > def has_change_permission(self, request, obj=None): > if obj and request.user == obj.referente: > return super(SchedaOptions, > self).has_change_permission(request, obj) > elif obj is None: > return True > else: > return False > > but I want the admin to show only the user objects in the object list. > is it possible? > > thanks in advance. > -- > Alessandro Ronchi > Skype: aronchihttp://www.alessandroronchi.net > > SOASI Soc.Coop. -www.soasi.com > Sviluppo Software e Sistemi Open Source > Sede: Via Poggiali 2/bis, 47100 Forlì (FC) > Tel.: +39 0543 798985 - Fax: +39 0543 579928 > > Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
sample app for beginner
Does anyone know a sample Django 1.0 application with complete source code that is good for beginner to explore? 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sorting list of objets in Python/Django
You could, but a key function is generally better, and the larger the list the better (in the general case) it is likely to be. The problem is that using __cmp__ requires the sort algorithm to make Python callbacks from a C function for each object-pair comparison. Using the key function, that function is called once to decorate each object in the list, and the C sort function compares the decorated list items without the need to call out to Python functions at all. As with all general solutions, specific circumstances can alter this general conclusion. regards Steve Rodolfo wrote: > You could also achieve that using the __cmp__ magic method[1]: > > > > class a: > def __init__(self, name, number): > self.name = name > self.number = number > > def __cmp__(self, other): > return cmp(self.name, other.name) > > def __repr__(self): > return "a(%s, %s)" % (repr(self.name), self.number) > > b = [] > b.append( a('Smith', 1) ) > b.append( a('Dave', 456) ) > b.append( a('Guran', 9432) ) > b.append( a('Asdf', 12) ) > > b.sort() > > print b > > # [a('Asdf', 12), a('Dave', 456), a('Guran', 9432), a('Smith', 1)] > > > > > The __cmp__ method does the magic, it's used when you call b.sort(). > I added __repr__ just to see legible output... > > > [1] http://docs.python.org/ref/customization.html > > []'s > > Rodolfo > > > On Sep 21, 5:54 pm, Nianbig <[EMAIL PROTECTED]> wrote: > >> Ah, thanks! >> >> /Nianbig >> >> On 21 Sep, 19:45, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >> >> >>> Nianbig wrote: >>> I have a people-list like this: >>> class a: >>> ... def __init__(self, name, number): ... self.name = name ... self.number = number ... >>> b = [] >>> b.append( a('Smith', 1) ) >>> b.append( a('Dave', 456) ) >>> b.append( a('Guran', 9432) ) >>> b.append( a('Asdf', 12) ) >>> How do I sort this on their names e.g. ascending? I have tried b.sort() and so on in all sorts of ways but I can´t figure this one out.. >>> this might get you going: >>> >>> def mysortkey(x): >>> return x.name >>> >>> b.sort(key=mysortkey) >>> >>> >>> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: _get_next_or_previous_ usage
On Sun, Sep 21, 2008 at 9:23 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > On Sun, 2008-09-21 at 17:36 -0300, Rafael Beccar Barca wrote: >> Hi, >> >> I didn't find documentation for _get_next_or_previous_by_FIELD and >> _get_next_or_previous_in_order > > The fact that they start with underscores and aren't documented in the > Model API is a big that they are internal methods, not intended to be > used by any user-level code. > >> What parameters should I pass when calling them from shell ? >> >> How should I use them on my templates ? > > You shouldn't use them directly. What is the problem you are actually > trying to solve? I was trying to implement previous and next buttons and I found this tutorial: http://www.webmonkey.com/tutorial/Install_Django_and_Build_Your_First_App#Tweak_the_links_and_tags where teach a very interesting way of implement them for date fields but I need to use them for a class that doesn't have any date time fields but is ordered by an integer field. Then, I used ipython to check what methods were available for the object and got curious about _get_next_or_previous_by_FIELD and _get_next_or_previous_in_order But I think I would change my question to a clearer one: How can I easily implement next and previous buttons in my template for a class that does not have any date fields? I'm not expecting a full explanation, just some tips so I can start investigating myself. Regards, Rafael > > 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?hl=en -~--~~~~--~~--~--~---
Re: _get_next_or_previous_ usage
On Sun, 2008-09-21 at 17:36 -0300, Rafael Beccar Barca wrote: > Hi, > > I didn't find documentation for _get_next_or_previous_by_FIELD and > _get_next_or_previous_in_order The fact that they start with underscores and aren't documented in the Model API is a big that they are internal methods, not intended to be used by any user-level code. > What parameters should I pass when calling them from shell ? > > How should I use them on my templates ? You shouldn't use them directly. What is the problem you are actually trying to solve? 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?hl=en -~--~~~~--~~--~--~---
Impact of a CustomManager on the RelatedManager
Hi everyone, I apologise for the verbosity of this message - for my first post it's quite long. I am currently working on my first project employing the Sites framework, and have been moving along quite well with the documentation until I hit a snag last night. I have overloaded the default manager in my model to use a slight variant of the CurrentSiteManager, shown below. class MyCurrentSiteManager(models.Manager): def __init__(self, field_name='site'): super(MyCurrentSiteManager, self).__init__() self.__field_name = field_name def get_query_set(self): return super(MyCurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) The reason I've trimmed it down, is because I want field_name to be a site reference on a related model. such as: class Venue(models.Model): name = models.CharField(max_length=50) site = models.ForeignKey(Site) objects = MyCurrentSiteManager() systemwide = models.Manager() class Conference(models.Model): title = models.CharField(max_length=50) venue = models.ForeignKey(Venue, related_name='conferences') objects = MyCurrentSiteManager('venue__site') systemwide = models.Manager() What I am seeing is that the following queries work and present only the objects which are on the site (Venue) or objects which are related to a Venue on the site (Conference): Venue.objects.all() Conference.objects.all() However, if I try to get the related objects of a Venue object, I get an error as below: >>> v = Venue.objects.get(pk=1) >>> v.conferences.all() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 78, in all return self.get_query_set() File "/usr/lib/python2.5/site-packages/django/db/models/fields/ related.py", line 300, in get_query_set return superclass.get_query_set(self).filter(**(self.core_filters)) File "/path/munged/managers.py", line 14, in get_query_set return super(MyCurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 483, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 501, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1224, in add_q can_reuse=used_aliases) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1099, in add_filter negate=negate, process_extras=process_extras) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1287, in setup_joins "Choices are: %s" % (name, ", ".join(names))) FieldError: Cannot resolve keyword 'site' into field. Choices are: venue, id, title I added a print line to my manager's get_query_set method, so it now reads: def get_query_set(self): print self.model._meta.object_name, self.__field_name return super(MyCurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID}) When I redo the query above, I now get: >>> v.conferences.all() Venue site Conference site Traceback (most recent call last): ... as before ... I was expecting it to be: >>> v.conferences.all() Venue site Conference venue__site So my analysis is that the RelatedManager (v.conferences) is not completely partnering up with my MyCurrentSiteManager because, although the print statements are firing off, they are not actually using the field_name parameter I supplied when instantiating the manager on the model. And here we are, finally at my question! Is it possible to have the related manager use the field_name that was passed in to my custom manager? Again, sorry for the long post but I thought it best to lay it all out there first! Regards, Gary --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding www. prefix to get_absolute_url
You should instead use named URLs and the django.core.urlresolvers.reverse function in your get_absolute_url methods. That way you'll leave it to the URL system to handle. I believe you shouldn't use absolute URLs (with http:// and domain) at all. Just make sure in your web server config that all requests to domain.com are redirected to www.domain.com while keeping the request path (although I'd rather redirect from www.domain.com to domain.com because it's cleaner and makes sense). You should consult the docs about the URL system (reverse, permalink and the {% url %} template tag). Erik On 22.09.2008, at 1:30, Catalyst wrote: > > I'm using Django .96 and I'm having trouble getting get_absolute_url > to add a www. prefix on to my URLs. > > For the most part everything on my site keeps people on my www. URL, > which is my goal, but my sitemap and RSS feeds point to URLs without a > www. on them. > > Does anyone know a good way to fix this? > > Here's an example of how my get_absolute_url statement looks. > >def get_absolute_url(self): >return "/appname/%s/%s/" % (self.creation_date.strftime("%Y/%b/ > %d").lower(), self.slug ) > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Adding www. prefix to get_absolute_url
I'm using Django .96 and I'm having trouble getting get_absolute_url to add a www. prefix on to my URLs. For the most part everything on my site keeps people on my www. URL, which is my goal, but my sitemap and RSS feeds point to URLs without a www. on them. Does anyone know a good way to fix this? Here's an example of how my get_absolute_url statement looks. def get_absolute_url(self): return "/appname/%s/%s/" % (self.creation_date.strftime("%Y/%b/ %d").lower(), self.slug ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Passing in a value from a url
On Sun, Sep 21, 2008 at 5:29 PM, djandrow <[EMAIL PROTECTED]> wrote: > > Here is my model for entry; > > class Entry(models.Model): > >entry_id = models.AutoField(primary_key=True) >entry_date = models.DateField(auto_now_add=True) >entry_title = models.CharField(max_length=70) >entry_content = models.TextField(max_length=5000) >entry_cat = models.ManyToManyField(Category) > >def __unicode__(self): >return self.entry_title > > So entry_cat is not a character field, meaning you cannot directly filter on it with a text value like you were trying to. Instead of: current_entries = Entry.objects.filter(entry_cat=category).order_by("-entry_date") you probably want something more like: current_entries = Entry.objects.filter(entry_cat__category_name=category).order_by("-entry_date") (Here I'm guessing your Category model has a character-type field named 'category_name' that is what you really want to be matching -- you'll need to fill in the actual field name from your Category model that you want to match against.) Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: _get_next_or_previous_ usage
You can find the definition of those methods at: /django/django/db/models/base.py:def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs): /django/django/db/models/base.py:def _get_next_or_previous_in_order(self, is_next): So, check on your django installation to see what they do. However, note that methods starting with an underscore mean you shouldn't be using them, they're for internal use. See the source and use at you own will. BTW - I don't know why those methods are for, and never used them nor see their code (just grep`ed to find where they're defined). []'s Rodolfo On Sep 21, 5:36 pm, "Rafael Beccar Barca" <[EMAIL PROTECTED]> wrote: > Hi, > > I didn't find documentation for _get_next_or_previous_by_FIELD and > _get_next_or_previous_in_order > > What parameters should I pass when calling them from shell ? > > How should I use them on my templates ? > > Gracias, > Rafael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Comments
Bobby Roberts wrote: > What would I attach to using this form statement as a > starting point: > > {% render_comment_form for [object] %} > > ie what should the object be? Semantically comments application is not intended for creating new first-class data on your site, so the fact that you have no obvious object to attach your comments to indicates that you're going to do something wrong. Just write a Testimonial model and create a view with form to edit it (you may make use of generic views which reside in `django.views.generic.create_update`). -- Happy Hacking. http://sphinx.net.ru む --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sorting list of objets in Python/Django
You could also achieve that using the __cmp__ magic method[1]: class a: def __init__(self, name, number): self.name = name self.number = number def __cmp__(self, other): return cmp(self.name, other.name) def __repr__(self): return "a(%s, %s)" % (repr(self.name), self.number) b = [] b.append( a('Smith', 1) ) b.append( a('Dave', 456) ) b.append( a('Guran', 9432) ) b.append( a('Asdf', 12) ) b.sort() print b # [a('Asdf', 12), a('Dave', 456), a('Guran', 9432), a('Smith', 1)] The __cmp__ method does the magic, it's used when you call b.sort(). I added __repr__ just to see legible output... [1] http://docs.python.org/ref/customization.html []'s Rodolfo On Sep 21, 5:54 pm, Nianbig <[EMAIL PROTECTED]> wrote: > Ah, thanks! > > /Nianbig > > On 21 Sep, 19:45, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > > Nianbig wrote: > > > I have a people-list like this: > > class a: > > > ... def __init__(self, name, number): > > > ... self.name = name > > > ... self.number = number > > > ... > > b = [] > > b.append( a('Smith', 1) ) > > b.append( a('Dave', 456) ) > > b.append( a('Guran', 9432) ) > > b.append( a('Asdf', 12) ) > > > > How do I sort this on their names e.g. ascending? I have tried > > > b.sort() and so on in all sorts of ways but I can´t figure this one > > > out.. > > > this might get you going: > > > def mysortkey(x): > > return x.name > > > b.sort(key=mysortkey) > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Passing in a value from a url
Here is my model for entry; class Entry(models.Model): entry_id = models.AutoField(primary_key=True) entry_date = models.DateField(auto_now_add=True) entry_title = models.CharField(max_length=70) entry_content = models.TextField(max_length=5000) entry_cat = models.ManyToManyField(Category) def __unicode__(self): return self.entry_title regards, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sorting list of objets in Python/Django
Ah, thanks! /Nianbig On 21 Sep, 19:45, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nianbig wrote: > > I have a people-list like this: > class a: > > ... def __init__(self, name, number): > > ... self.name = name > > ... self.number = number > > ... > b = [] > b.append( a('Smith', 1) ) > b.append( a('Dave', 456) ) > b.append( a('Guran', 9432) ) > b.append( a('Asdf', 12) ) > > > How do I sort this on their names e.g. ascending? I have tried > > b.sort() and so on in all sorts of ways but I can´t figure this one > > out.. > > this might get you going: > > def mysortkey(x): > return x.name > > b.sort(key=mysortkey) > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Passing in a value from a url
On Sun, Sep 21, 2008 at 4:36 PM, djandrow <[EMAIL PROTECTED]> wrote: > > Hi, I am currently trying to pass in a value from a url and the > perform a query based on that, i've tried this: > > def category_view(request, category): >current_entries = > Entry.objects.filter(entry_cat=category).order_by("- > entry_date") >return render_to_response('blog/base.html', locals()) > > but I get this: > > Caught an exception while rendering: Truncated incorrect DOUBLE value: > 'general' > > Is this because the value isn't a string, and how can I get it > working, I know the value is being passed into the view correctly. > What is the definition for your Entry model? Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ultra-n00b models.Model syntax error
On Sun, Sep 21, 2008 at 4:21 PM, notatoad <[EMAIL PROTECTED]> wrote: > > i just set up django and started on the tutorial. i get this after > calling 'python manage.py sql polls' > > [snip] > File "/usr/local/django-apps/mysite/../mysite/polls/models.py", line 3 > >class Poll(models.Model) > > ^SyntaxError: invalid syntax > > i'm working with the tutorial code here: > http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3 > > any ideas what's gone wrong? > > Assuming the caret is actually pointing at the last character in the identified line, then you're missing a ':' on the end of that line. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Passing in a value from a url
Hi, I am currently trying to pass in a value from a url and the perform a query based on that, i've tried this: def category_view(request, category): current_entries = Entry.objects.filter(entry_cat=category).order_by("- entry_date") return render_to_response('blog/base.html', locals()) but I get this: Caught an exception while rendering: Truncated incorrect DOUBLE value: 'general' Is this because the value isn't a string, and how can I get it working, I know the value is being passed into the view correctly. Thanks, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
_get_next_or_previous_ usage
Hi, I didn't find documentation for _get_next_or_previous_by_FIELD and _get_next_or_previous_in_order What parameters should I pass when calling them from shell ? How should I use them on my templates ? Gracias, Rafael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ultra-n00b models.Model syntax error
i just set up django and started on the tutorial. i get this after calling 'python manage.py sql polls' ceback (most recent call last): File "manage.py", line 11, in ? execute_manager(settings) File "/usr/lib/python2.4/site-packages/django/core/management/ __init__.py", line 340, in execute_manager utility.execute() File "/usr/lib/python2.4/site-packages/django/core/management/ __init__.py", line 295, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.4/site-packages/django/core/management/ base.py", line 77, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.4/site-packages/django/core/management/ base.py", line 95, in execute self.validate() File "/usr/lib/python2.4/site-packages/django/core/management/ base.py", line 122, in validate num_errors = get_validation_errors(s, app) File "/usr/lib/python2.4/site-packages/django/core/management/ validation.py", line 28, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/usr/lib/python2.4/site-packages/django/db/models/loading.py", line 128, in get_app_errors self._populate() File "/usr/lib/python2.4/site-packages/django/db/models/loading.py", line 57, in _populate self.load_app(app_name, True) File "/usr/lib/python2.4/site-packages/django/db/models/loading.py", line 72, in load_app mod = __import__(app_name, {}, {}, ['models']) File "/usr/local/django-apps/mysite/../mysite/polls/models.py", line 3 class Poll(models.Model) ^SyntaxError: invalid syntax i'm working with the tutorial code here: http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3 any ideas what's gone wrong? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django -- very very basic query !
I would suggest taking a couple of hours to do the tutorial, and it basically runs through most of what django can do. Since 1.0 is out, you just need to download, install and run through the tutorial. It runs on any platform. Have fun. John On Sep 21, 7:20 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > I am basically c/c++/Unix dev, and knowing little python stuff. And > little bit about xhtml. > I just wanted to know to learn/develop site using Django, Do i have to > master of Python, Xhtml , Javascript ? > > What kind of stuff, i can do using Django ? > > Thanks > Raxitwww.m4mum.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Comments
the Django docs state that "Django's comments are all "attached" to some parent object"... I'm building a very simple django powered website with auth, flatpages, and comments currently installed. I want to use the comments so people can post testimonials which can then be displayed on the site. What would I attach to using this form statement as a starting point: {% render_comment_form for [object] %} ie what should the object be? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: webfaction django installation
> The "Getting started with Django at WebFaction" article should solve > Bobby's > problem:https://help.webfaction.com/index.php?_m=knowledgebase&_a=viewarticle... > Setting up a static application was easy and worked perfectly. 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django 1.0 - Form documentation
Does this help ? http://docs.djangoproject.com/en/dev/ref/forms/validation/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django 1.0 - Form documentation
Hi, Do you know where can I find documentation about forms in django 1.0 specially for validations? Luis. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin field custom validation
Hello Daniel, Thank you for your reply. I guess then that I cannot test image heights and widths on a form pre- save, because that is the only reason I can think of for this error after forum submissal (if I use clean_logo) 'NoneType' object is unsubscriptable. Does that make sense ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin field custom validation
On Sep 21, 6:01 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Having done a bit more research I see this often used as: > > clean_fieldname(self) rather than clean(self) > > which I guess would eleviate my problem, as my clean(self) function > doesn't appear to remember or pass on the rest of the submitted field > information. However when I try the above I get: 'NoneType' object is > unsubscriptable There are two types of clean methods on forms. clean_FIELDNAME() is called on validation of each field. Note that the actual name of the method is clean_ plus the name of your field - in your case clean_logo. You must return the validated value if it passes. clean() is called on validation of the whole form. This is useful if you want to check dependencies between fields. You must return the full cleaned_data dictionary. The reason why you were getting a blank row is you didn't return anything, so there was nothing to enter into the database. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sorting list of objets in Python/Django
Nianbig wrote: > I have a people-list like this: class a: > ... def __init__(self, name, number): > ... self.name = name > ... self.number = number > ... b = [] b.append( a('Smith', 1) ) b.append( a('Dave', 456) ) b.append( a('Guran', 9432) ) b.append( a('Asdf', 12) ) > > How do I sort this on their names e.g. ascending? I have tried > b.sort() and so on in all sorts of ways but I can´t figure this one > out.. this might get you going: def mysortkey(x): return x.name b.sort(key=mysortkey) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Sorting list of objets in Python/Django
Hi, I have a people-list like this: >>> class a: ... def __init__(self, name, number): ... self.name = name ... self.number = number ... >>> b = [] >>> b.append( a('Smith', 1) ) >>> b.append( a('Dave', 456) ) >>> b.append( a('Guran', 9432) ) >>> b.append( a('Asdf', 12) ) How do I sort this on their names e.g. ascending? I have tried b.sort() and so on in all sorts of ways but I can´t figure this one out.. Would be thankful for help. /Nianbig --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin field custom validation
Having done a bit more research I see this often used as: clean_fieldname(self) rather than clean(self) which I guess would eleviate my problem, as my clean(self) function doesn't appear to remember or pass on the rest of the submitted field information. However when I try the above I get: 'NoneType' object is unsubscriptable --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form get with special characters
On Sep 21, 4:01 pm, "Alessandro Ronchi" <[EMAIL PROTECTED]> wrote: > It seems now It works, becausehttp://www.animalisenzacasa.org/ricerca/?s=forlì > is converted to:http://www.animalisenzacasa.org/ricerca/?s=forl%C3%AC > > I don't know what's changed, because this morning the result was an > empty page (with source code white, and a correct http header). I once discovered that you will get a blank page if a string like "forlì" is not first encoded to UTF-8 and then percent-encoded by the browser, but just percent-encoded from e.g. latin-1 directly... maybe that's the problem here, could happen with older browsers. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin field custom validation
Sorry I was wrong, if I try to submit a NEW logo that is too large it fails correctly. But when I try to add a new logo that is the right size it enters a fully blank row into the database. 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Admin field custom validation
Hi, This is my code: class LogoAdminForm(forms.ModelForm): class Meta: model = Logo def clean(self): from django.core.files.images import get_image_dimensions logo = self.cleaned_data['logo'] w, h = get_image_dimensions(logo) if w > 150 or h > 150: raise forms.ValidationError(u'That logo is too big. Please resize it so that it is 32x32 pixels or less, although 150x150 pixels is optimal for display purposes.') return logo class LogoAdmin(admin.ModelAdmin): exclude = ['height','width',] form = LogoAdminForm search_fields = ('name','logo','altText',) list_display = ('name','logo',) admin.site.register(Logo,LogoAdmin) This works when editting a logo, but when I try to add a logo it enters a fully blank row into the database. Can anyone give me a hint as to why this is the case please ? Thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django -- very very basic query !
Hi, I am basically c/c++/Unix dev, and knowing little python stuff. And little bit about xhtml. I just wanted to know to learn/develop site using Django, Do i have to master of Python, Xhtml , Javascript ? What kind of stuff, i can do using Django ? Thanks Raxit www.m4mum.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form get with special characters
2008/9/21 Malcolm Tredinnick <[EMAIL PROTECTED]>: > > > On Sun, 2008-09-21 at 12:44 +0200, Alessandro wrote: >> I have a search form. >> When a user inserts a string like "Forlì", django returns a blank page. >> I need to convert ì to a url encoded string, but I don't know how to do. > > You haven't explained where the problem is occurring. Is the correct > data getting to your view function and then you aren't sending back the > right information? If so, look at django.utils.http. I can't see how > that would be resulting in a completely blank page, however. Also "a > blank page" could be more accurate: is no data at all being sent back? > Or is the user receiving an HTML page, but there's not visible data? It seems now It works, because http://www.animalisenzacasa.org/ricerca/?s=forlì is converted to: http://www.animalisenzacasa.org/ricerca/?s=forl%C3%AC I don't know what's changed, because this morning the result was an empty page (with source code white, and a correct http header). -- Alessandro Ronchi Skype: aronchi http://www.alessandroronchi.net SOASI Soc.Coop. - www.soasi.com Sviluppo Software e Sistemi Open Source Sede: Via Poggiali 2/bis, 47100 Forlì (FC) Tel.: +39 0543 798985 - Fax: +39 0543 579928 Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
filter queryset in admin
I want staff users to be able to see and edit only their objects. With newforms admin I managed to avoid cross user editings with def has_change_permission(self, request, obj=None): if obj and request.user == obj.referente: return super(SchedaOptions, self).has_change_permission(request, obj) elif obj is None: return True else: return False but I want the admin to show only the user objects in the object list. is it possible? thanks in advance. -- Alessandro Ronchi Skype: aronchi http://www.alessandroronchi.net SOASI Soc.Coop. - www.soasi.com Sviluppo Software e Sistemi Open Source Sede: Via Poggiali 2/bis, 47100 Forlì (FC) Tel.: +39 0543 798985 - Fax: +39 0543 579928 Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form get with special characters
On Sun, 2008-09-21 at 12:44 +0200, Alessandro wrote: > I have a search form. > When a user inserts a string like "Forlì", django returns a blank page. > I need to convert ì to a url encoded string, but I don't know how to do. You haven't explained where the problem is occurring. Is the correct data getting to your view function and then you aren't sending back the right information? If so, look at django.utils.http. I can't see how that would be resulting in a completely blank page, however. Also "a blank page" could be more accurate: is no data at all being sent back? Or is the user receiving an HTML page, but there's not visible data? Is Django crashing? Or is your view function completing, but not generating any data? You are saying that when a user does something, Django doesn't return something. But there are a lot of steps in the middle there. It sounds like you've done some debugging already, but it isn't clear to me, at least, where things are going wrong. 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?hl=en -~--~~~~--~~--~--~---
Re: DJANGO 1.0 : How to avoid converting to entities
Malcolm Tredinnick wrote: >> Better yet, the thing that creates colorizedCode should mark it as >> "safe" (i.e. not requiring escaping) in this fashion: >> >> from django.utils.safestring import mark_safe >> def colorize(): >> # ... >> return mark_safe(result) > > Although if you ever write anything like that you are also responsible > for escaping the existing code. Good point, thanks. I've took a liberty to suppose that if it's about "colorizing" then it's probably some tool that generates HTML from a language source and probably is indeed safe. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
form get with special characters
I have a search form. When a user inserts a string like "Forlì", django returns a blank page. I need to convert ì to a url encoded string, but I don't know how to do. Thanks in advance. -- Alessandro Ronchi Skype: aronchi http://www.alessandroronchi.net SOASI Soc.Coop. - www.soasi.com Sviluppo Software e Sistemi Open Source Sede: Via Poggiali 2/bis, 47100 Forlì (FC) Tel.: +39 0543 798985 - Fax: +39 0543 579928 Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: webfaction django installation
> I had also similar problems, because instead of documentation they have a > screencast(?!) and the forum. Did you at least spend 30 seconds looking for docs before writing that? They have a Django category in their knowledge base with quite a few articles: https://help.webfaction.com/index.php?_m=knowledgebase&_a=view&parentcategoryid=24&pcid=0&nav=0 (btw, that link is included in their welcome e-mail). The "Getting started with Django at WebFaction" article should solve Bobby's problem: https://help.webfaction.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=122&nav=0,24 Kevin. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ANN: Updated Django Cheat Sheet
Shouldn't ForeignKeyField to be just ForeignKey? Am I missing something? 2008/9/10 Fraser Nevett <[EMAIL PROTECTED]> > > Just letting everyone know that we've released a new edition which > removes the PhoneNumberField and USStateField fields as discussed -- > thanks to all those who contacted us about this. > > The other common request we received was to have a version that worked > better with black and white printers. To this end, there's now a > grayscale PDF also available for download from our site: > > http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/ > > Regards, > > Fraser > > > On Sep 10, 11:30 am, Andrew Durdin <[EMAIL PROTECTED]> wrote: > > On Sep 9, 11:32 am, Vinay Sajip <[EMAIL PROTECTED]> wrote: > > > > > > > > > Nicecheatsheet. Hope it's not too late to offer a suggestion - it > > > would be useful to have the forloop special variables in thecheatsheet. > Not sure where you'll find room, though ;-) > > > > We had them there in an earlier draft, but there just wasn't room. > > They're not too hard to remember, though, hopefully? Off the top of > > my head: counter, counter0, revcounter, revcounter0, parentloop, > > first, last. > > > > You could write them all on a single post-it note and stick them to > > your monitor ;) > > > > Cheers, > > > > Andrew Durdin. > > > -- Nikos Delibaltadakis --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---