Strange 404 error in admin
Hi, This is a strange case. I have a simple blog entry model which can be edited in the admin, from the URL that looks like: http://www.example.com.au/admin/blog/entry/52/ Now, what is strange is that the link above returns a 404. Same with the entry id=51. Yet, entries with id=51,52 do exist. - All other entries (with id < 51) work fine in the admin. - All entries (including id=51,52) work fine on the front end. - Everything works fine when I test it locally on my computer with a replica of the online database. I've never come across something like that, and I'm not sure where to look to debug this. Would you have some hints to suggest? Thanks a lot for your help, Julien PS: It is using a quite old version of Django, a trunk revision between 0.96 and 1.0. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
form invalid
hi i have one form inside the form {% for name in eventname %} {{ name.title }} {{ name.address }} {{ name.summary }} {{ name.title }} {{ name.summary }} {{ name.start_date }} to {{ name.end_date }} {{ name.start_time }} to {{ name.end_time }} {{ name.venue }} {{ name.contact }} {{ name.description }} {{ forms.name }} Friend's Name {{ forms.email }} Friend's Email {{ forms.comment}} Submit {% endfor %} forms.py - class MailForm(forms.Form): #topic = forms.ChoiceField(choices=TOPIC_CHOICES) name = forms.CharField(label=_("Name"), max_length=50) email = forms.EmailField(label=_("Email address")) comment = forms.CharField(label=_("Comment"), widget=forms.Textarea) eventview.py def event(request): difference1 = datetime.timedelta(days=-3) today=datetime.date.today() print "Today date : ", today l=range(1,5) forms = MailForm(request.POST)# Creating MAIL FORM interface in side event template print "Mail Form : ", forms eventobj=events.objects.all().filter (start_date__lte=today,end_date__gte=today) eventname=events.objects.all().filter (start_date__lte=today,end_date__gte=today) #eventobj=events.objects.all().filter(start_date__gte=today- datetime.timedelta(days=3), end_date__lte=today+datetime.timedelta (days=10), highlighted='true',visibility='true') paginator = Paginator(eventobj, 2) try: page = int(request.GET.get('page','1')) print "page : ", page except ValueError: page = 1 try: eventobj = paginator.page(page) print " Event object : ", eventobj except(EmptyPage, InvalidPage): eventobj = paginator.page(paginator.num_pages) return render_to_response("event.html", {'eventobj':eventobj,'l':l,'eventname':eventname,'today':today.strftime ("%B %d %Y %A"),'forms':forms}) #View for send mail# --- def mail(request): if request.method == 'POST': # If the form has been submitted... form = MailForm(request.POST) # A form bound to the POST data if form.is_valid(): print "Form valid" comment = form.cleaned_data['comment'] email = ['i...@example.com'] from django.core.mail import send_mail send_mail(comment, email) print "Send mail : ", send_mail(comment, email) return HttpResponseRedirect('/pro/Thanks/') else: print "Invalid form" form = MailForm() # An unbound form return render_to_response('contact.html', {'form': form}) urls.py -- (r'^foodies/events/$', 'foodies.foodapp.eventview.event'), (r'^foodies/sendmail/$','foodies.foodapp.eventview.mail'), i am displaying eventdetails in light box where i have one submit and name and email field. if some one click on submit then mail should send page should closed. but when i am clicking on submit button form is closing but it shows me "Invalid Form" which i wrote in else part of mail view. i think some thing wrong in get or post. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
protect from brute force attacks on login
Hi all, I'm using django-registration to handle logins, registrations etc. It is very handy and easy to set up, but allows unlimited login attempts, and thus people can brute-force any django-application! So far I've been using fail2ban to ban users that brute force passwords. I would be interested to hear how you handle this from within django! Are you aware of some patch/code or blog entry where I can find more information? (Obviously this affects all django projects, not only django-registration ) Best regards, Markos -- Under the paving stones, the beach --~--~-~--~~~---~--~~ 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: Upload ZIP-File into Database
Hi Karen, I didn't mind to start a quiz... The problem is that in the code above django seems to control if the ZIP-File contains Images. I'm not sure but when I take a ZIP-File which contains Images there is no problem, but when I take my ZIP-File I always get the error: BadZipfile - File is not a ZIP-File. I've also looked at the code from django-photologue, but there is the same problem. I don't figure out where this 'Image-Check' is defined... As I told before my ZIP-File contains five .lst-Files which contains the data for my database. How I can I tell django to expand these files, read them one by one and fill my database with the values? On Feb 8, 3:34 pm, Karen Tracey wrote: > On Sun, Feb 8, 2009 at 7:24 AM, Robert wrote: > > > Dear Community, > > > I have a ZIP-File which contains five .lst-Files. I want to fill with > > these five files a mysql-database. Is there a possibility to handle > > this via the admin interface? I tried the following but it doesn't > > work: > > This sort of thing can certainly be done, the django-photologue application > (http://code.google.com/p/django-photologue/), for example, has a > GalleryUpload model that lets you upload a zip file of images and the zip > file is automatically expanded to its constituent images when you save a new > GalleryUpload object in the admin. I have not looked at how exactly it is > implemented, but looking at its code might point you in the right direction. > > If you want more specific help with the code you've got, giving people a > clue what "it doesn't work" looks like would probably help. I like puzzles, > but I don't much like ones that are missing pieces, and leaving out the > details of what is going wrong: what you do, what you expect the outcome to > be, and what the outcome is instead, including any error messages and > tracebacks -- is leaving out a few too many pieces for me to have any > interest in looking at your puzzle. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: protect from brute force attacks on login
On Mon, Feb 9, 2009 at 6:21 PM, Markos Gogoulos wrote: > Hi all, > > I'm using django-registration to handle logins, registrations etc. It is > very handy and easy to set up, but allows unlimited login attempts, and thus > people can brute-force any django-application! > > So far I've been using fail2ban to ban users that brute force passwords. I > would be interested to hear how you handle this from within django! Are you > aware of some patch/code or blog entry where I can find more information? Simon Willison published an interesting blog on this exact topic just after the successful dictionary attack on Twitter. He includes some references to other approaches, as well as a fully worked example based on using memcached. http://simonwillison.net/2009/Jan/7/ratelimitcache/ Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: Troubles with unicode in django-trunk
On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > > Hello, > > I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and > began the tutorial. I got as far as adding the unicode print > definitions for poll and choice, and then saw no difference between > afterward : > > In [2]: Poll.objects.all() > Out[2]: [] > > is still what I saw. What were you expecting to see? This output indicates that you are using the default __unicode__ method for the Poll object, which won't be printing any detail of the object itself - just the fact that it is a Poll object. If you retrieve an individual object from the list that has been returned, you will be able to interrogate the individual fields of that object, and you should find that they hold unicode data. Alternatively, you can provide a definition for the __unicode__() method for the Poll class, and it will print whatever you desire (for example the poll title, not just "Poll object") > Can you imagine what they problem might be? No problem here - just a misunderstanding of usage. I'm guessing you're new to Python - by way of guidance, this isn't a Django-specific feature. It's a part of the way the Python shell tells you what objects you are working with. You may find it illuminating to dig into the Python documentation around the __unicode__, __str__ and __repr__ methods. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
mod_python vs. Django?
Hello I'd like to write a Web 2.0-type web application. I find Python a lot more pleasurable than PHP. I'd like to have information about the pro's and con's of using Apache's mod_python vs. an application server like Django, Turbogears, etc. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Troubles with unicode in django-trunk
Hello, I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and began the tutorial. I got as far as adding the unicode print definitions for poll and choice, and then saw no difference between afterward : In [2]: Poll.objects.all() Out[2]: [] is still what I saw. So I scrubbed the 1.0.2 and got the svn version, but there is still no difference. I removed and relinked the /usr/lib/python2.5/site-packages/django directory and /usr/lib/django-admin.py file as recommended. I really need unicode to work. Can you imagine what they problem might 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Form wizard back button
It seems to me like a quite simple requirement for a form wizard ... but I'm still unable to find a simple way to do it ... --~--~-~--~~~---~--~~ 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: mod_python vs. Django?
On Mon, Feb 9, 2009 at 6:54 PM, Vincent wrote: > > Hello > > I'd like to write a Web 2.0-type web application. I find Python a lot > more pleasurable than PHP. > > I'd like to have information about the pro's and con's of using > Apache's mod_python vs. an application server like Django, Turbogears, > etc. You appear to be a little bit confused with either your terminology or your expectations. Django isn't an application server - it's a set of libraries that lets you write web applications. Those applications are then served using a mod_python interface (as well as mod_wsgi interfaces). I can't speak with absolute authority on Turbogears, but I'm fairly certain the same is true there. In order to deploy a Django application, you're still going to use mod_python (or mod_wsgi). You obviously have some concerns about Django compared to something else you are familiar with (PHP?). Perhaps if you explain your specific concerns, we may be able to address them. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: mod_python vs. Django?
Think about Django as Cake PHP, Symfony, Code Igniter, etc from the PHP scene. You still need mod_php to run them =) Obviously, Django has a damn big cool factor added, for not being PHP =) Yours, Chris On 09/02/2009, at 10:26, Russell Keith-Magee wrote: > > On Mon, Feb 9, 2009 at 6:54 PM, Vincent > wrote: >> >> Hello >> >> I'd like to write a Web 2.0-type web application. I find Python a lot >> more pleasurable than PHP. >> >> I'd like to have information about the pro's and con's of using >> Apache's mod_python vs. an application server like Django, >> Turbogears, >> etc. > > You appear to be a little bit confused with either your terminology or > your expectations. > > Django isn't an application server - it's a set of libraries that lets > you write web applications. Those applications are then served using a > mod_python interface (as well as mod_wsgi interfaces). I can't speak > with absolute authority on Turbogears, but I'm fairly certain the same > is true there. > > In order to deploy a Django application, you're still going to use > mod_python (or mod_wsgi). > > You obviously have some concerns about Django compared to something > else you are familiar with (PHP?). Perhaps if you explain your > specific concerns, we may be able to address them. > > Yours, > Russ Magee %-) > > --~--~-~--~~~---~--~~ 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: mod_python vs. Django?
On Feb 9, 9:26 pm, Russell Keith-Magee wrote: > On Mon, Feb 9, 2009 at 6:54 PM, Vincent wrote: > > > Hello > > > I'd like to write a Web 2.0-type web application. I find Python a lot > > more pleasurable than PHP. > > > I'd like to have information about the pro's and con's of using > > Apache's mod_python vs. an application server like Django, Turbogears, > > etc. > > You appear to be a little bit confused with either your terminology or > your expectations. > > Django isn't an application server - it's a set of libraries that lets > you write web applications. Those applications are then served using a > mod_python interface (as well as mod_wsgi interfaces). I can't speak > with absolute authority on Turbogears, but I'm fairly certain the same > is true there. > > In order to deploy a Django application, you're still going to use > mod_python (or mod_wsgi). > > You obviously have some concerns about Django compared to something > else you are familiar with (PHP?). Perhaps if you explain your > specific concerns, we may be able to address them. The mod_python module also supplied higher level handlers which incorporate a URL dispatcher and templating mechanisms. Thus for simple stuff it can be used to construct applications in its own right and isn't just a jumping off point for larger self contained systems such as Django. For new applications, anyone would be well advised though to use these distinct systems rather than welding themselves to the mod_python specific handlers. By using a separate system they ensure there application is portable to different hosting mechanisms, which will be good protection given that mod_python is dying a slow death and is unlikely to be ported to Python 3.0. Graham --~--~-~--~~~---~--~~ 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: Best practice question: subclassing external app components
in my own setup I have a few apps where it might go: globalapp - a collection of misc snippets, classes and utilities that I use on every project I work on {website} - the specific website if this code will not be reused accountz - views, forms related to my own styles of login utils, registration etc. things from here are used on every site I work on 3 would be the best choice I think. for capitalizing the labels on fields you should try just doing css felix :crucial-systems.com On Mon, Feb 9, 2009 at 12:35 AM, zinckiwi wrote: > > Hi folks, > > I'm just starting to play with django-registration and I want to > subclass the RegistrationForm for a couple of cosmetic tweaks > (capitalising the labels on the fields -- there may be a simpler way > to do this, but indulge me for the purposes of this question). I > understand that subclassing RegistrationForm and reassigning the label > strings is the way to do this -- no problem. > > My question is where to *put* that subclass. I can think of a few > places: > > - the project itself > - an "overrides" app dedicated to holding overrides for external apps > - a "registration_overrides" app dedicated to holding overrides for > just that one external app > > Perhaps there are other ways. Of these, I'm favouring #2. While #3 has > the virtue of being more portable, it seems like a lot of (logical) > overhead to perform a simple modification to another app. > > So I guess I'd like to hear if there's an accepted way to do this, or > failing that, what anyone has found to work well (or what to avoid). > > Thanks all, > Scott > > > > --~--~-~--~~~---~--~~ 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: Subclass/Inline Problem - should I be able to do this?
All inline models need to have a ForeignKey pointing back to the base model. In your case you need to declare a ForeignKey field from Gallery model to Business model, what you've did instead is you've created foreign key to parent class (Directory). Try this: class Directory(models.Model): name = models.CharField(max_length=60) class Business(Directory): anyfield = models.CharField(max_length=60) class Gallery(models.Model): directory = models.ForeignKey(Business), pic = models.ImageField(upload_to='pics') On Feb 6, 9:56 pm, phoebebright wrote: > Here is my model: > > class Directory(models.Model): > name = models.CharField(max_length=60) > > class Business(Directory): > anyfield = models.CharField(max_length=60) > > class Gallery(models.Model): > directory = models.ForeignKey(Directory), > pic = models.ImageField(upload_to='pics') > > This is admin.py > > class Galleries(admin.TabularInline): > model = Gallery > > class DirectoryAdmin(admin.ModelAdmin): > > inlines = [ > Galleries, > ] > > admin.site.register(Business,DirectoryAdmin) > > This is the error I get in admin. > > Request Method: GET > Request URL: http://127.0.0.1:8000/admin/town/business/add/ > Exception Type: Exception > Exception Value: > > has no ForeignKey to 'towns.town.models.Business'> > > If I take out the inlines bit in admin.py and just have > > admin.site.register(Business) > admin.site.register(Gallery) > > Then it works as expected. --~--~-~--~~~---~--~~ 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: Troubles with unicode in django-trunk
On Feb 9, 5:21 pm, Russell Keith-Magee wrote: > On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > > > Hello, > > > I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and > > began the tutorial. I got as far as adding the unicode print > > definitions for poll and choice, and then saw no difference between > > afterward : > > > In [2]: Poll.objects.all() > > Out[2]: [] > > > is still what I saw. > > What were you expecting to see? This output indicates that you are > using the default __unicode__ method for the Poll object, which won't > be printing any detail of the object itself - just the fact that it is > a Poll object. Sorry, I am new to python and I guess you hadn't bothered to read the elementary tutorial that I was following. I should have been more specific: http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs about 7/8s' of the way down the page : Wait a minute. is, utterly, an unhelpful representation of this object. Let's fix that by editing the polls model (in the polls/models.py file) and adding a __unicode__() method to both Poll and Choice: class Poll(models.Model): # ... def __unicode__(self): return self.question class Choice(models.Model): # ... def __unicode__(self): return self.choice If __unicode__() doesn't seem to work If you add the __unicode__() method to your models and don't see any change in how they're represented, you're most likely using an old version of Django. (This version of the tutorial is written for the latest development version of Django.) If you're using a Subversion checkout of Django's development version (see the installation docs for more information), you shouldn't have any problems. If you want to stick with an older version of Django, you'll want to switch to the Django 0.96 tutorial, because this tutorial covers several features that only exist in the Django development version. It's important to add __unicode__() methods to your models, not only for your own sanity when dealing with the interactive prompt, but also because objects' representations are used throughout Django's automatically-generated admin. So it was in response to that advice that I "saw he installation docs for more information" and didn't find the relief spoken of and so wrote here. Thanks for your help, but I still am having a problem. > > If you retrieve an individual object from the list that has been > returned, you will be able to interrogate the individual fields of > that object, and you should find that they hold unicode data. > > Alternatively, you can provide a definition for the __unicode__() > method for the Poll class, and it will print whatever you desire (for > example the poll title, not just "Poll object") > > > Can you imagine what they problem might be? > > No problem here - just a misunderstanding of usage. I'm guessing > you're new to Python - by way of guidance, this isn't a > Django-specific feature. It's a part of the way the Python shell tells > you what objects you are working with. You may find it illuminating to > dig into the Python documentation around the __unicode__, __str__ and > __repr__ methods. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ 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: Troubles with unicode in django-trunk
On Mon, Feb 9, 2009 at 8:43 PM, jfmxl wrote: > > On Feb 9, 5:21 pm, Russell Keith-Magee wrote: >> On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > Sorry, I am new to python and I guess you hadn't bothered to read the > elementary tutorial that I was following. I should have been more > specific: Specifics always help. And FYI: I have read the tutorial. I'm one of the core developers of Django, so I'm well aware of what the tutorial says. > So it was in response to that advice that I "saw he installation docs > for more information" and didn't find the relief spoken of and so > wrote here. > > Thanks for your help, but I still am having a problem. Without seeing your code, its almost impossible to determine the cause of your problem. My initial guess would be that one of three things has happened: 1) You haven't actually saved the models.py file where you have defined the __unicode__() methods. An obvious error, but a surprisingly common one. 2) You haven't restarted your python shell - you've just continued working with an old shell. You need to start a new Python shell session to force the models.py file to be reloaded. 3) You've misspelled __unicode__ in your models.py file. Most likely culprit here - using single underscores rather than double underscores in the method name. The method needs to be called _ _ unicode _ _ (self). If you have used a different name, you won't see an error (since the alternate name will be a valid Python method name) but it won't generate the output you expect. If you post your example code as it currently stands, we may be able to provide more assistance. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Changing Image in admin deletes the rest - expected behaviour?
Model: class Car(models.Model): ... lots of fields ... pic1 = models.ImageField(blank=True, upload_to='pics') pic2 = models.ImageField(blank=True, upload_to='pics') pic3 = models.ImageField(blank=True, upload_to='pics') pic4 = models.ImageField(blank=True, upload_to='pics') In admin, if I change the content of one pic it blanks the rest. Is this expected behaviour? Be great to add a bit more file handling to the admin side. The ability to delete a pic for example. When I get more skills I will try writing a custom field class for where there is only one file/ image per database entry and in this case it will handle automatic deletion of files when the record is deleted or changed. --~--~-~--~~~---~--~~ 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: default value for foreign key and CharField
Thanks, My Media_biz is edited inline in another class. So I have: class MetadataInline(admin.StackedInline) and class MetadataAdmin(admin.ModelAdmin) Can you tell what method I should override and in which class in order to set the initial value while editing inline? Regards, Alex Arshavski. On Feb 5, 11:21 pm, Rajesh Dhawan wrote: > > > > I have the following classes in my models.py: > > > > > class Default(models.Model): > > > > name = models.CharField(max_length=50, choices = > > > > (('rental_period', 'rental_period'), ('currency', 'currency')), > > > > unique=True) > > > > value = models.CharField(max_length=50) > > > > > class Media_biz(models.Model): > > > > name = models.CharField(max_length=50) > > > > currency = models.ForeignKey(Currency) > > > > rental_period = models.CharField(max_length=5, blank=True, > > > > null=True) > > > > > What I want is: > > > > When I add new Media_biz in my admin page, I want to check if there is > > > > a Default object with the name "currency" or "rental_period" and take > > > > it's value as default. > > > > You want to take its value as default for what field of Media_biz? And > > > if you have two Default instances (one for currency and another for > > > rental_period), which one provides the default value? > > Each Default instance provide default value for one of the fields: > > I want to take the default value of rental_period to rental_period and > > default value of currency to currency. > > The value of the currency should be the name of Currency object for > > foreign key. > > You can override your Media_biz admin model's get_form method and > inject your initial values. It would be something like this: > > def get_form(self, request, obj=None, **kwargs): > form = super(YourMedia_bizAdmin, self).get_form(request, obj, > **kwargs) > try: > currency_default = Default.objects.get(name='currency') > currency = Currency.objects.get(name=currency_default.value) > form.fields['currency'].initial = currency.pk > except Default.DoesNotExist: > pass > try: > rental_default = Default.objects.get(name='rental_period') > form.fields['rental_period'].initial = rental_default.value > except Default.DoesNotExist: > pass > return form > > -RD --~--~-~--~~~---~--~~ 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 do I add a Custom ID Field that increments?
Thanks Guys, Will, your snippet was exactly what I was looking for - thanks for that. Alas Rama, the client has specified that these custom Invoice IDs get saved in the db alongside the primary key, otherwise I'd go with your suggestion (simpler!) On Feb 5, 8:27 am, Rama Vadakattu wrote: > CUSTOM_ID---ID > ~ > INV1 -- 1 > INV2 ---2 > INV33 > . > . > . > i think you need INV1 for display purposes and also i hope it does > not matter much whether you store 1 or INV1 in the db. > > in such cases why can't you follow the below approach? > -- > store as 1 but display it as INV1 (by appending 1 to 'INV') > when you want to search 'INV2' strip out the INV and convert the > other part to 2 and search for this 2 in the database. > > ~~ > I don't know whether this is feasible to you or not but just a thought > adding to suggestion of "Will Hardy". > > On Feb 3, 4:47 am, Will Hardy wrote: > > > There's no easy solution without saving the object to the database. > > Auto incrementing fields (AutoField or just id) get their value from > > the database, so they wont have one until you save. This is good > > because it prevents multiple objects ever having the same value. One > > way to do what you want is to save a new invoice to the database > > straight away when the user clicks "add new invoice" and allow them to > > edit it, but if you're using the admin site, this might not be > > straightforward. > > > You wont need to create a new field by the way, you could simply make > > a property that uses the ID field of a model: > > > @property > > def invoice_id(self): > > if self.id: > > return 'INV%d' % self.id > > > But you wouldn't be able to search for the full INV001 string, you > > would have to strip the INV beforehand or create a new charfield and > > populate that on save (sounds like what you're doing) > > > If you don't want to have such obvious incrementing values for your > > invoice numbers, you could use a perfect hash function to convert it > > to a more obscure value, > > likehttp://www.djangosnippets.org/snippets/1249/(Iwrote this snippet, > > don't worry that two people voted against it, they didn't say why... I > > have no idea... it's just a simple perfect hash function and base > > converter, and it certainly does the job it was designed to do) > > > Cheers, > > > Will --~--~-~--~~~---~--~~ 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: Testing Django and HTTP Request
Thank you Alex for you help I will look in to this. Vitaly Babiy On Mon, Feb 9, 2009 at 12:32 AM, Alex Gaynor wrote: > > > On Mon, Feb 9, 2009 at 12:28 AM, Vitaly Babiy wrote: > >> Yeah, it does. I am going to have to look to see if can find a better >> stand alone server to do this instead of patching django. >> >> Vitaly Babiy >> >> >> On Mon, Feb 9, 2009 at 12:22 AM, Alex Gaynor wrote: >> >>> >>> >>> On Mon, Feb 9, 2009 at 12:18 AM, Vitaly Babiy wrote: >>> Yea, but I see a few problems whit that solution: - Hacky - Still not guaranteed to work( it could take more time) - Would really slow down the tests Vitaly Babiy On Mon, Feb 9, 2009 at 12:15 AM, Alex Gaynor wrote: > > > On Mon, Feb 9, 2009 at 12:13 AM, Vitaly Babiy wrote: > >> Right the problem is if I reload the server on ever test, there is not >> enough time for the thread to kill the server. So when the next setUp >> comes >> around the port is still in use. >> I think I need to find a way to start a HTTP server at the beginning >> of the test and keep it around till all test are done. And have a way to >> tell the server what to return on the request. >> >> Vitaly Babiy >> >> >> On Mon, Feb 9, 2009 at 12:08 AM, Alex Gaynor >> wrote: >> >>> >>> >>> On Mon, Feb 9, 2009 at 12:06 AM, Vitaly Babiy wrote: >>> Hello everyone, I am working on a project that will need to make a request out to the web and pull down some data, For testing purpose I was wonder what would be the best way to test this. I don't want to make the actual request during the test, because for one if I am off-line all those tests will fail. I have tried to implement a HTTPServer in python. The problem I am having is once I have it thread, If I put it in the setUp method and tearDown I get port in use exception. Due to the nature of the thread it is not guaranteed to be killed in time. Vitaly Babiy >>> You should be able to save the thread on the Test object during >>> setup() and then kill it on teardown() shouldn't you? >>> >>> Alex >>> >>> -- >>> "I disapprove of what you say, but I will defend to the death your >>> right to say it." --Voltaire >>> "The people's good is the highest law."--Cicero >>> >>> >>> >> >> >> > What if you just put a time.sleep(2) at the end of tearDown() that > should give the thread enough time to close before the next test starts. > > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your > right to say it." --Voltaire > "The people's good is the highest law."--Cicero > > > >>> Is what you are ultimately searching for similar to this: >>> http://code.djangoproject.com/ticket/2879 >>> >>> >>> Alex >>> >>> -- >>> "I disapprove of what you say, but I will defend to the death your right >>> to say it." --Voltaire >>> "The people's good is the highest law."--Cicero >>> >>> >>> >> >> >> > The CherryPy WSGI server is usually a good choice for these things. > > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
date error
Hi, I am new in django world and i am a french speaker but i will try to speak english in this mailling list. I have buy the book, Pratical Django projects of James Bennett and i have a problem somewhere. this is the error archive_index() got an unexpected keyword argument 'day' this is my urls.py entry_info_dict ={ 'queryset':Entry.objects.all(), 'date_field':'pub_date', } urlpatterns = patterns('django.views.generic.date_based', (r'^$','archive_index',entry_info_dict,'dibongo_entry_archive_index'), #dibongo is my application's name (r'^$','object_detail', entry_info_dict,'dibongo_entry_detail'), my models.py @models.permalink def get_absolute_url(self): return ('dibongo_entry_detail',(),{'year':self.pub_date.strftime("%Y"), 'month':self.pub_date.strftime("%b").lower(), 'day':self.pub_date.strftime("%d"), 'slug':self.slug}) could you help me and explain why i have this error? Thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Troubles with unicode in django-trunk
On Feb 9, 7:05 pm, Russell Keith-Magee wrote: > On Mon, Feb 9, 2009 at 8:43 PM, jfmxl wrote: > > > On Feb 9, 5:21 pm, Russell Keith-Magee wrote: > >> On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > > Sorry, I am new to python and I guess you hadn't bothered to read the > > elementary tutorial that I was following. I should have been more > > specific: > > Specifics always help. And FYI: I have read the tutorial. I'm one of > the core developers of Django, so I'm well aware of what the tutorial > says. I'm sorry. I didn't mean to accuse you of negligence at all! I just meant that as an experienced python programmer you might have had a different entry point to django than I did. I was unaware that you are of the core. My apologies in any case. > > So it was in response to that advice that I "saw he installation docs > > for more information" and didn't find the relief spoken of and so > > wrote here. > > > Thanks for your help, but I still am having a problem. > > Without seeing your code, its almost impossible to determine the cause > of your problem. My initial guess would be that one of three things > has happened: > > 1) You haven't actually saved the models.py file where you have > defined the __unicode__() methods. An obvious error, but a > surprisingly common one. Yes. Just the sort of mistake I'm prone to make too. But not this time. > 2) You haven't restarted your python shell - you've just continued > working with an old shell. You need to start a new Python shell > session to force the models.py file to be reloaded. I actually thought of that one myself after the first or second run. > 3) You've misspelled __unicode__ in your models.py file. Most likely > culprit here - using single underscores rather than double underscores > in the method name. The method needs to be called _ _ unicode _ _ > (self). If you have used a different name, you won't see an error > (since the alternate name will be a valid Python method name) but it > won't generate the output you expect. I've double-checked and that's not the case. I had cut and pasted the code in question. > If you post your example code as it currently stands, we may be able > to provide more assistance. I'm sorry it's so lengthy: j...@ws0:~/src/python/django/mysite$ django-admin.py --version 1.1 pre-alpha SVN-9820 j...@ws0:~/src/python/django/mysite$ cat polls/models.py from django.db import models import datetime # ... # Create your models here. class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() class Poll(models.Model): # ... def __unicode__(self): return self.question class Choice(models.Model): # ... def __unicode__(self): return self.choice class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.date.today() j...@ws0:~/src/python/django/mysite$ ./manage.py shell Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) Type "copyright", "credits" or "license" for more information. IPython 0.8.4 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: from mysite.polls.models import Poll, Choice In [2]: Poll.objects.all() Out[2]: [] In [3]: Poll.objects.filter(id=1) Out[3]: [] In [4]: Poll.objects.filter(question__startswith='What') Out[4]: [] In [5]: Poll.objects.get(pub_date__year=2009) Out[5]: In [6]: Poll.objects.get(id=2) --- DoesNotExist Traceback (most recent call last) /home/jfl/src/python/django/mysite/ in () /usr/lib/python2.5/site-packages/django/db/models/manager.py in get (self, *args, **kwargs) 91 92 def get(self, *args, **kwargs): ---> 93 return self.get_query_set().get(*args, **kwargs) 94 95 def get_or_create(self, **kwargs): /usr/lib/python2.5/site-packages/django/db/models/query.py in get (self, *args, **kwargs) 340 if not num: 341 raise self.model.DoesNotExist("%s matching query does not exist." --> 342 % self.model._meta.object_name) 343 raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s" 344 % (self.model._meta.object_name, num, kwargs)) DoesNotExist: Poll matching query does not exist. In [7]: Poll.objects.get(pk=1) Out[7]: In [8]: p = Poll.objects.get(pk=1) In [9]: p.was_published_today() --- AttributeErrorTracebac
Re: Troubles with unicode in django-trunk
On Mon, Feb 9, 2009 at 8:07 AM, jfmxl wrote: > > # Create your models here. > > class Poll(models.Model): >question = models.CharField(max_length=200) >pub_date = models.DateTimeField('date published') > > class Choice(models.Model): >poll = models.ForeignKey(Poll) >choice = models.CharField(max_length=200) >votes = models.IntegerField() > > class Poll(models.Model): ># ... >def __unicode__(self): >return self.question > > class Choice(models.Model): ># ... >def __unicode__(self): >return self.choice > > class Poll(models.Model): ># ... > def was_published_today(self): >return self.pub_date.date() == datetime.date.today() > You're only supposed to have one class Poll(...), class Choice(...), etc. line. When you add a method like __unicode__ or was_published_today, simply append it (properly indented) to the existing class Poll(...) you already have. Do not add another class Poll(...) 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Looking to give presentation on Django at work
Is there a presentation available that I can use? Would like to skip the whole building of the presentation myself if possible. If there isn't one, I may create an "open-source" presentation myself and make it available for others to build on. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
FreeBSD 6.2 trouble using postgresql_psycopg2
Hi there! I have py25-django-1.0.2 port installed on FreeBSD. While following this tutorial: http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01 I've reached the line that says DATABASE_ENGINE -- Either 'postgresql_psycopg2', 'mysql' or 'sqlite3'. Other backends are also available. So I set DATABASE_ENGINE = 'postgresql_psycopg2' in my settings.py, but alas, manage.py runserver spits this: Validating models... Unhandled exception in thread started by Traceback (most recent call last): File "/usr/local/lib/python2.5/site-packages/django/core/management/ commands/runserver.py", line 48, in inner_run self.validate(display_num_errors=True) File "/usr/local/lib/python2.5/site-packages/django/core/management/ base.py", line 246, in validate num_errors = get_validation_errors(s, app) File "/usr/local/lib/python2.5/site-packages/django/core/management/ validation.py", line 22, in get_validation_errors from django.db import models, connection File "/usr/local/lib/python2.5/site-packages/django/db/__init__.py", line 16, in backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['']) File "/usr/local/lib/python2.5/site-packages/django/db/backends/ postgresql_psycopg2/base.py", line 20, in raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2 This is no surprise, as django always attempts to install databases/py- psycopg, and not databases/py-psycopg2, since the former is hardcoded in its port Makefile. Any ideas? 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: FreeBSD 6.2 trouble using postgresql_psycopg2
On Mon, Feb 9, 2009 at 7:38 AM, rihad wrote: > This is no surprise, as django always attempts to install databases/py- > psycopg, and not databases/py-psycopg2, since the former is hardcoded > in its port Makefile. Any ideas? Django's documentation lists all available values for the DATABASE_ENGINE setting: http://docs.djangoproject.com/en/dev/ref/settings/#database-engine It also covers the difference between the two PostgreSQL options, and tells you what to specify to use psycopg version 1 instead of psycopg version 2: http://docs.djangoproject.com/en/dev/topics/install/#database-installation Or, you could install the psycopg2 port and then use that. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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: Looking to give presentation on Django at work
have you looked on djangosnippets.org? 2009/2/9 jeffself : > > Is there a presentation available that I can use? Would like to skip > the whole building of the presentation myself if possible. If there > isn't one, I may create an "open-source" presentation myself and make > it available for others to build on. > > > --~--~-~--~~~---~--~~ 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: Changing Image in admin deletes the rest - expected behaviour?
On Mon, Feb 9, 2009 at 6:39 AM, phoebebright wrote: > In admin, if I change the content of one pic it blanks the rest. Is > this expected behaviour? Generally, when you think you've found a bug, searching the Django bug tracker will turn up useful information, as in this case: http://code.djangoproject.com/ticket/10121 -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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: mod_python vs. Django?
On 9 fév, 12:25, Graham Dumpleton wrote: > By using a separate system they ensure there application is portable > to different hosting mechanisms, which will be good protection given > that mod_python is dying a slow death and is unlikely to be ported to > Python 3.0. So I was correct that Django/Turbogears/etc. don't rely on mod_python? Good to know that mod_python is losing momentum. --~--~-~--~~~---~--~~ 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: FreeBSD 6.2 trouble using postgresql_psycopg2
Thanks, as 'postgresql' was one of the types listed in the comment, I tried that and it worked. I understand this is a wrong place to post issues with Django FreeBSD port, so I might try doing it somewhere else. --~--~-~--~~~---~--~~ 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: Upload ZIP-File into Database
I did that once and had no problem customizing GalleryUpload for my needs. Try start writing some code and get back to us if it fails. http://code.google.com/p/django-photologue/source/browse/trunk/photologue/models.py#194 Ariel. --~--~-~--~~~---~--~~ 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: date error
On Mon, Feb 9, 2009 at 7:42 AM, Séno Hervé Edorh wrote: > Hi, > I am new in django world and i am a french speaker but i will try to speak > english in this mailling list. I have buy the book, Pratical Django projects > of James Bennett and i have a problem somewhere. this is the error > > archive_index() got an unexpected keyword argument 'day' > > > this is my urls.py > > entry_info_dict ={ > 'queryset':Entry.objects.all(), > 'date_field':'pub_date', > } > > urlpatterns = patterns('django.views.generic.date_based', > > (r'^$','archive_index',entry_info_dict,'dibongo_entry_archive_index'), > #dibongo is my application's name > (r'^$','object_detail', entry_info_dict,'dibongo_entry_detail'), > > my models.py > > @models.permalink > def get_absolute_url(self): > return > ('dibongo_entry_detail',(),{'year':self.pub_date.strftime("%Y"), >'month':self.pub_date.strftime("%b").lower(), >'day':self.pub_date.strftime("%d"), >'slug':self.slug}) > > could you help me and explain why i have this error? > > Thank you > > > > I don't have my copy of Practical Django Projects handy but it looks like you wired up the URL incorrectly, specifically the URL you are reversing to doesn't have a regex that actually captures any of those fields, I would take a look at the URL conf James shows and see how it differs from yours. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: problem with simple shopping cart
I'm also getting an Index Error, "list index out of range" for the "request.session['cart'][1] += 1" line. I can't figure out what's wrong. On Feb 9, 3:02 am, lnysrogh wrote: > Thank you so much. That helped a lot. Such a simple mistake. > > I've got some other questions now. My "add to cart" code: > > def add(request, product_id): > added = (Product.objects.get(id=product_id), 1) # '1' is quantity > request.session.set_test_cookie() > if request.session.test_cookie_worked(): > request.session.delete_test_cookie() > if 'cart' in request.session: > if added in request.session['cart']: > request.session['cart'][1] += 1 > else: > request.session['cart'].append(added) > else: > request.session['cart'] = [] > request.session['cart'].append(added) > return HttpResponseRedirect('/cart/') > else: > return HttpResponse('You need to enable cookies') > > The code worked until I tried to check if the product is already > stored in the cart and to add 1 to the quantity instead of storing it > again. I'm getting this error: "can only concatenate tuple (not "int") > to tuple". What am I doing 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Looking to give presentation on Django at work
On Mon, Feb 9, 2009 at 9:01 AM, Andrew Ingram wrote: > > have you looked on djangosnippets.org? > > 2009/2/9 jeffself : > > > > Is there a presentation available that I can use? Would like to skip > > the whole building of the presentation myself if possible. If there > > isn't one, I may create an "open-source" presentation myself and make > > it available for others to build on. > > > > > > > > > Justin Lilly wrote on article for Python Magazine and has put slides on line for convincing your boss to use Django: http://www.justinlilly.com/blog/2009/jan/17/django-3ft-presentation/ Perhaps this would be helpful. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Apache, Django configuration
Hi All, I use mod_python to run Django on Apache. But, I notice all of the urls that Django received are not correct. In deed, the "/" after the domain name is truncated. e.g. http://localhost/admin/ , Django receives "http://localhostadmin"; Why this happen? Thanks, Xian --~--~-~--~~~---~--~~ 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: mod_python vs. Django?
On Mon, Feb 9, 2009 at 9:05 AM, Vincent wrote: > > On 9 fév, 12:25, Graham Dumpleton wrote: > > By using a separate system they ensure there application is portable > > to different hosting mechanisms, which will be good protection given > > that mod_python is dying a slow death and is unlikely to be ported to > > Python 3.0. > > So I was correct that Django/Turbogears/etc. don't rely on mod_python? > > Good to know that mod_python is losing momentum. > > > Django doesn't require mod_python specifically, but it does need some webserver and a way to interact with it, so you are welcome to use mod_wsgi, or fastcgi or whatever else you can hook up, but you need something. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: FreeBSD 6.2 trouble using postgresql_psycopg2
On Feb 9, 6:23 pm, rihad wrote: > I understand this is a wrong place to post > issues with Django FreeBSD port, so I might try doing it somewhere > else. The "issue" being that www/py-django port unconditionally installs py- psycopg if WITH_POSTGRESQL is selected before building the port, without letting you choose the version. --~--~-~--~~~---~--~~ 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: date error
i forgot, the first ulrs.py (in the project directory) is like this (r'^weblog/$',include('dibongo.urls')), (r'^weblog/(?P\d{4})/(?P\w{3})/(?P\d{2})/(? P\w+)/$',include('dibongo.urls')), this is the second that i put before. It for the chapiter decoupling the URLs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem reopening files
Hi, I've written a form ImageField that is cropable with the help of a javascript cropper. In the course of saving the cropped image, I have to reopen the image file a couple of times in different modes in the "clean"-method of the ImageField. Unfortunately, despite the docs saying something different[1], the file isn't reopened with a different mode: In [1]: from django.core.files import File In [2]: f = open('test.txt', 'r') In [3]: df = File(f) In [4]: df.mode Out[4]: 'r' In [5]: df.open(mode='w') In [6]: df.mode Out[6]: 'r' Am I doing something wrong here? Regards, Benjamin [1] http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.open --~--~-~--~~~---~--~~ 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: Extending the User model
On Sun, Feb 8, 2009 at 7:51 PM, Patricio Palma wrote: > [snip] > --- > models.py > from django.contrib.auth.models import User > class MyUser(User): >chilean_rut = CLRutField(_('RUT'),primary_key=True) > some_field = models.CharField(max_length=50) > > admin.py > class MyUserAdmin(admin.ModelAdmin): >list_display = ('chilean_rut', 'email','some_field') > admin.site.register(MyUser,MyUserAdmin) > > - > > And my list_display is EMPTY ( on the > http://127.0.0.1:8000/admin/myapp/myuser/) > The problem here seems to be caused by setting primary_key=True on one of the fields in the model that inherits from another. You can see it using just these simple models: class BaseM(models.Model): base_name = models.CharField(max_length=100) def __unicode__(self): return self.base_name class DerivedM(BaseM): customPK = models.IntegerField(primary_key=True) derived_name = models.CharField(max_length=100) def __unicode__(self): return "PK = %d, base_name = %s, derived_name = %s" % \ (self.customPK, self.base_name, self.derived_name) and manage.py shell (output reformatted for readability): Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from ttt.models import DerivedM >>> from django.db import connection >>> DerivedM.objects.create(customPK=44, base_name="b1", derived_name="d1") >>> DerivedM.objects.all() [] >>> connection.queries[-1] {'time': '0.006', 'sql': u'SELECT `ttt_basem`.`id`, `ttt_basem`.`base_name`, `ttt_derivedm`.`basem_ptr_id`, `ttt_derivedm`.`customPK`, `ttt_derivedm`.`derived_name` FROM `ttt_derivedm` INNER JOIN `ttt_basem` ON (`ttt_derivedm`.`customPK` = `ttt_basem`.`id`) LIMIT 21'} >>> The ORM is joining the two tables and attempting to match the manually-specified custom PK from the child table to the auto-generated id in the parent table, which results in finding nothing. I do not know if specifying primary_key=True on a field in a child table is just not allowed (in which case it should probably be flagged as an error during validation) or if the ORM should be handling this properly. I do not see any ticket open that describes this case; you might want to open one since it seems something ought to be changed here to either report an invalid model definition or handle this case properly. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Troubles with unicode in django-trunk
On Feb 9, 8:22 pm, Karen Tracey wrote: > On Mon, Feb 9, 2009 at 8:07 AM, jfmxl wrote: > > > # Create your models here. > > > class Poll(models.Model): > > question = models.CharField(max_length=200) > > pub_date = models.DateTimeField('date published') > > > class Choice(models.Model): > > poll = models.ForeignKey(Poll) > > choice = models.CharField(max_length=200) > > votes = models.IntegerField() > > > class Poll(models.Model): > > # ... > > def __unicode__(self): > > return self.question > > > class Choice(models.Model): > > # ... > > def __unicode__(self): > > return self.choice > > > class Poll(models.Model): > > # ... > > def was_published_today(self): > > return self.pub_date.date() == datetime.date.today() > > You're only supposed to have one class Poll(...), class Choice(...), etc. > line. When you add a method like __unicode__ or was_published_today, simply > append it (properly indented) to the existing class Poll(...) you already > have. Do not add another class Poll(...) line. Well... thank you very much Karen! > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Question about INNER JOIN vs LEFT JOIN and some strange issue when model binds to in self through many-to-many relationship.
At first step I will describe my models: class Meter(models.Model): id = models.IntegerField(primary_key=True) some stuff here... collector = models.ManyToManyField("self", through='MeterCollector', symmetrical=False) class MeterCollector(models.Model): meter = models.ForeignKey(Meter, related_name='meter_id') collector_node = models.ForeignKey(Meter, related_name='collecotor_node_id') def __unicode__(self): return u'meter id: %s; collector node id: %s;' % ( self.meter_id, self.collector_node_id) class Meta: db_table = 'meter_to_collector' class MeterSspec(models.Model): id = models.IntegerField(primary_key=True) meter = models.ForeignKey(Meter) sspec = models.ForeignKey(Sspec) ..some stuff... Everything works fine until I use filter like this in view.py: meter_list = Meter.objects.all().filter(meter__metersspec__sspec = sspec_id) I expect something like "Give me all meters that have sspec_id = 1", so my custom query will be: SELECT `meter`.`id`, `meter`.`description` FROM `meter` LEFT JOIN `meter_to_collector` ON (`meter`.`id` = `meter_to_collector`.`collector_node_id`) LEFT JOIN `meter` T3 ON (`meter_to_collector`.`meter_id` = T3.`id`) INNER JOIN `meter_sspec` ON (`meter`.`id` = `meter_sspec`.`meter_id`) WHERE `meter_sspec`.`sspec_id` = '1' But django gives me something like this: SELECT `meter`.`id`, `meter`.`description` FROM `meter` INNER JOIN `meter_to_collector` ON (`meter`.`id` = `meter_to_collector`.`collector_node_id`) INNER JOIN `meter` T3 ON (`meter_to_collector`.`meter_id` = T3.`id`) INNER JOIN `meter_sspec` ON (T3.`id` = `meter_sspec`.`meter_id`) WHERE `meter_sspec`.`sspec_id` = '1' There are 2 common problems: 1) How can I force django to use LEFT JOIN ??? 2) Genreal problem: Im wondering why django joins meter_sspec with meter_to_collector (T3) and not with meter??? So, is there any way to do it without custom sql query ? Alex M Vdovin. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form invalid
On Feb 9, 3:54 am, Praveen wrote: > hi i have one form inside the form > > method="POST" onSubmit="javascript:self.close();"> > {% for name in eventname %} > > {{ name.title }} > > {{ name.address }} > {{ name.summary }} > style='display:none'> > {{ name.title }} > style="width: > 25%;height:25%"/> > > > {{ name.summary }} > {{ name.start_date }} to {{ > name.end_date }} > {{ name.start_time }} to {{ > name.end_time }} > {{ name.venue }} > {{ name.contact }} > {{ name.description }} > > > {{ forms.name }} Friend's > Name > {{ forms.email }} Friend's > Email > {{ > forms.comment}} > > onClick="javascript:self.close();">Submit a> > class="submit-post" > value="Send" /> > > > > {% endfor %} > > > forms.py > - > class MailForm(forms.Form): > #topic = forms.ChoiceField(choices=TOPIC_CHOICES) > name = forms.CharField(label=_("Name"), max_length=50) > email = forms.EmailField(label=_("Email address")) > comment = forms.CharField(label=_("Comment"), > widget=forms.Textarea) > > eventview.py > > def event(request): > difference1 = datetime.timedelta(days=-3) > today=datetime.date.today() > print "Today date : ", today > l=range(1,5) > forms = MailForm(request.POST)# Creating MAIL FORM interface in side > event template > print "Mail Form : ", forms > eventobj=events.objects.all().filter > (start_date__lte=today,end_date__gte=today) > eventname=events.objects.all().filter > (start_date__lte=today,end_date__gte=today) > #eventobj=events.objects.all().filter(start_date__gte=today- > datetime.timedelta(days=3), end_date__lte=today+datetime.timedelta > (days=10), highlighted='true',visibility='true') > paginator = Paginator(eventobj, 2) > try: > page = int(request.GET.get('page','1')) > print "page : ", page > except ValueError: > page = 1 > try: > eventobj = paginator.page(page) > print " Event object : ", eventobj > except(EmptyPage, InvalidPage): > eventobj = paginator.page(paginator.num_pages) > return render_to_response("event.html", > {'eventobj':eventobj,'l':l,'eventname':eventname,'today':today.strftime > ("%B %d %Y %A"),'forms':forms}) > > #View for send mail# > --- > def mail(request): > if request.method == 'POST': # If the form has been submitted... > form = MailForm(request.POST) # A form bound to the POST data > if form.is_valid(): > print "Form valid" > comment = form.cleaned_data['comment'] > email = ['i...@example.com'] > from django.core.mail import send_mail > send_mail(comment, email) > print "Send mail : ", send_mail(comment, email) > return HttpResponseRedirect('/pro/Thanks/') > else: > print "Invalid form" > form = MailForm() # An unbound form > return render_to_response('contact.html', {'form': form}) > > urls.py > -- > > (r'^foodies/events/$', 'foodies.foodapp.eventview.event'), > (r'^foodies/sendmail/$','foodies.foodapp.eventview.mail'), > > i am displaying eventdetails in light box where i have one submit and > name and email field. if some one click on submit then mail should > send page should closed. but when i am clicking on submit button form > is closing but it shows me "Invalid Form" which i wrote in else part > of mail view. i think some thing wrong in get or post. This is really difficult to read like this. Next time if you post post, please put it on a pastebin site like dpaste.com . This will make my life a lot easier. My bet is when you look at the post information coming across the wire you aren't going to see any of the information you expect. First off, where does the 'forms' variable come from? The best way to check the post/get requests is with a product like Firebug or Fiddler. You can see what is going with your post and make sure that it matches what you think it should be. Take a look at that information, hopefully it will become clear what is wrong when you look at it like that. Michael --~--~-
urlize
Hi, I have written a django app that manages 'change requests' (and approvals) for IT infrastructure changes in our company, and I am using the urlize filter when displaying certain fields (like description of change, test plan etc). This is so that if a user puts a link to documentation for a system / change then it shows up as a link. This works reasonably well - in fact too well in some cases. As you can imagine some of the descriptions contain lists of domains, and these are all getting changed to links. I have logged a feature request for my next release of my app to sort the problem out (probably by wrapping lists of domain's in tags, then writing a custom filter to urlize stuff that is not surrounded by these tags), but I was wondering if this might be something that other django users would want, and if so, is it worth me raising a feature request to get the functionality put in to the django urlize filter? Or perhaps someone has a better suggestion for how to get around this problem? Em --~--~-~--~~~---~--~~ 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: Upload ZIP-File into Database
On Mon, Feb 9, 2009 at 4:37 AM, Robert wrote: > > Hi Karen, > > I didn't mind to start a quiz... > The problem is that in the code above django seems to control if the > ZIP-File contains Images. I'm not sure but when I take a ZIP-File > which contains Images there is no problem, but when I take my ZIP-File > I always get the error: BadZipfile - File is not a ZIP-File. I've also > looked at the code from django-photologue, but there is the same > problem. I don't figure out where this 'Image-Check' is defined... > As I told before my ZIP-File contains five .lst-Files which contains > the data for my database. How I can I tell django to expand these > files, read them one by one and fill my database with the values? > This really doesn't clarify much. "BadZipfile - File is not a ZIP-File" is not a string contained anywhere in the code you posted so doesn't help pinpoint where the code you posted is running into trouble. Furthermore, from a brief look at your code I don't see where you are doing anything to even try to iterate through the files contained in the zip file and do something with them (your code rather seems to be trying five different ways to 'test' whether it's gotten a valid zipfile?). I've not used the python ZipFile support myself, but looking a this: http://code.google.com/p/django-photologue/source/browse/trunk/photologue/models.py#194 I can see there is a loop 'for filename in zip.namelist():' that then extracts the data for individual files via 'data = zip.read(filename)', and does stuff with the data. I don't see anything like that in what you have -- Django is not going to do this sort of processing automatically for you, you have to write the code to do it. And if your problem is you do not know how to manipulate zip files in Python, the right place to ask about that would be someplace like comp.lang.python, not here. There is nothing Django-specific about manipulating zip files in your application; ZipFile is provided by Python, not Django. Perhaps you just haven't gotten that far, though, since the message you report sounds like the basic testing of "is this a valid zipfile" is failing. In which case one thing that would be nice to know is can you test/validate the zip file read from the file system (perhaps using the python shell) using code similar to what you have? If that too is failing, then you've got a problem with your zipfile being acceptable to Python's zip file support and Django can do nothing about that -- again the right place to look for guidance on that would by a Python forum, not a Django one. Karen > > On Feb 8, 3:34 pm, Karen Tracey wrote: > > On Sun, Feb 8, 2009 at 7:24 AM, Robert wrote: > > > > > Dear Community, > > > > > I have a ZIP-File which contains five .lst-Files. I want to fill with > > > these five files a mysql-database. Is there a possibility to handle > > > this via the admin interface? I tried the following but it doesn't > > > work: > > > > This sort of thing can certainly be done, the django-photologue > application > > (http://code.google.com/p/django-photologue/), for example, has a > > GalleryUpload model that lets you upload a zip file of images and the zip > > file is automatically expanded to its constituent images when you save a > new > > GalleryUpload object in the admin. I have not looked at how exactly it > is > > implemented, but looking at its code might point you in the right > direction. > > > > If you want more specific help with the code you've got, giving people a > > clue what "it doesn't work" looks like would probably help. I like > puzzles, > > but I don't much like ones that are missing pieces, and leaving out the > > details of what is going wrong: what you do, what you expect the outcome > to > > be, and what the outcome is instead, including any error messages and > > tracebacks -- is leaving out a few too many pieces for me to have any > > interest in looking at your puzzle. > > > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Apache Conf Problem
Hi, I am creating dynamically a web sit, from my django project. To achieve that i have to append the site url details in the apache conf. I have tried by having as a septate python script to set the setting, for that file I have given changed the owner as root and tried by event i am getting as permission denied to open the file. Thanks, Veera --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Dynamic Apache Conf Problem
Hi, I am creating dynamically a web sit, from my django project. To achieve that i have to append the site url details in the apache conf. I have tried by having as a septate python script to set the setting, for that file I have given changed the owner as root and tried by event i am getting as permission denied to open the file. Thanks, Veera --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
on delete cascade - best way to do override this behaviour?
Dear community, On some of our models we'd like to override Django's default "on delete cascade". (Customers that use our modified version of the Django-admin have proven to pay no attention at all to the messages that warn them for the deletion of multiple objects. It seems that a solution on the software side is more appropriate here than trying to educate our clients.) I've found that this subject has come up every now and then on this list, but it's unclear to me what's our best option. Via an old "restrict delete"-patch (http://code.djangoproject.com/ ticket/1007) through ticket 2288 I've found an interesting patch that sends out "all_objects_to_be_deleted in the pre_delete signal (http:// code.djangoproject.com/ticket/6108). A solution through signals seems very interesting to me, but there's no activity on this ticket since August last year. An other interesting option is a patch that allows to override the cascading behaviour by using an attribute on foreignkeys that can be set to "SET_NULL" or "RESTRICT" (http://code.djangoproject.com/ticket/ 7539). For this ticket there hasn't been much activity since last year either. I currently don't know what my best options are... Any input would be greatly appreciated. Thanks, Erwin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
User Auth... is_group in a template?
I'm wondering, I can easily add a if statement to detect whether a user is staff in a template - {% if user.is_staff %} blah {% endif %} but is there a similar syntax for displaying HTML blocks depending on the user group? A kind of {% if user.is_group(customer) %} blah for customer {% endif %} I'm thinking not but any help much appreciated! --~--~-~--~~~---~--~~ 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: User Auth... is_group in a template?
Just an idea, but what about using a user profile and then using the get_profile function? ex. {% if user.get_profile.customer %} customer block {% endif %} R. On Feb 9, 11:01 am, Alfonso wrote: > I'm wondering, I can easily add a if statement to detect whether a > user is staff in a template - {% if user.is_staff %} blah {% endif %} > but is there a similar syntax for displaying HTML blocks depending on > the user group? > > A kind of {% if user.is_group(customer) %} blah for customer {% endif > %} > > I'm thinking not but any help much appreciated! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Keep getting NameError at /admin/
Hi I am new to django and have just started to play. I have a working (small) app but wanted to turn on the admin console for the project. I edited the settings.py to include the admin module and now get the following errors NameError at /admin/ name 'admin' is not defined Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Exception Type: NameError Exception Value: name 'admin' is not defined although I first saw the error using django 1.0.2, I can re-create it using 0.96. I have come to the conclusion that I am doing something wrong but can anyone tell me what? the relevant part of my settings.py looks like; INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', ) and URLS looks like # Uncomment the next line to enable the admin: (r'^admin/(.*)', admin.site.root), ) i have removed evrything else from the project and app and still get the errror, at the top of the urls.py it makes no difference whether I have the line admin.autodiscover() or not as I still get the error Regards K --~--~-~--~~~---~--~~ 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: Keep getting NameError at /admin/
On Mon, Feb 9, 2009 at 11:11 AM, claudio.br...@googlemail.com < claudio.br...@googlemail.com> wrote: > > Hi > > I am new to django and have just started to play. I have a working > (small) app but wanted to turn on the admin console for the project. I > edited the settings.py to include the admin module and now get the > following errors > > NameError at /admin/ > > name 'admin' is not defined > > Request Method: GET > Request URL: http://127.0.0.1:8000/admin/ > Exception Type: NameError > Exception Value: > > name 'admin' is not defined > > although I first saw the error using django 1.0.2, I can re-create it > using 0.96. I have come to the conclusion that I am doing something > wrong but can anyone tell me what? > > the relevant part of my settings.py looks like; > > INSTALLED_APPS = ( >'django.contrib.auth', >'django.contrib.contenttypes', >'django.contrib.sessions', >'django.contrib.sites', >'django.contrib.admin', > ) > > and URLS looks like > > ># Uncomment the next line to enable the admin: > (r'^admin/(.*)', admin.site.root), > ) > > i have removed evrything else from the project and app and still get > the errror, at the top of the urls.py it makes no difference whether I > have the line admin.autodiscover() or not as I still get the error > > Regards > > K > > > > Do you have the line "from django.contrib import admin" in your urls.py? Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Testing Django and HTTP Request
Hey Alex I got cherrypy to work great I am going to post a blog as soon as my blog is done :) If anyone cares just ask here and I will post a write up here. Vitaly Babiy On Mon, Feb 9, 2009 at 7:52 AM, Vitaly Babiy wrote: > Thank you Alex for you help I will look in to this. > > Vitaly Babiy > > > > On Mon, Feb 9, 2009 at 12:32 AM, Alex Gaynor wrote: > >> >> >> On Mon, Feb 9, 2009 at 12:28 AM, Vitaly Babiy wrote: >> >>> Yeah, it does. I am going to have to look to see if can find a better >>> stand alone server to do this instead of patching django. >>> >>> Vitaly Babiy >>> >>> >>> On Mon, Feb 9, 2009 at 12:22 AM, Alex Gaynor wrote: >>> On Mon, Feb 9, 2009 at 12:18 AM, Vitaly Babiy wrote: > Yea, but I see a few problems whit that solution: > >- Hacky >- Still not guaranteed to work( it could take more time) >- Would really slow down the tests > > Vitaly Babiy > > > On Mon, Feb 9, 2009 at 12:15 AM, Alex Gaynor wrote: > >> >> >> On Mon, Feb 9, 2009 at 12:13 AM, Vitaly Babiy wrote: >> >>> Right the problem is if I reload the server on ever test, there is >>> not enough time for the thread to kill the server. So when the next >>> setUp >>> comes around the port is still in use. >>> I think I need to find a way to start a HTTP server at the beginning >>> of the test and keep it around till all test are done. And have a way to >>> tell the server what to return on the request. >>> >>> Vitaly Babiy >>> >>> >>> On Mon, Feb 9, 2009 at 12:08 AM, Alex Gaynor >>> wrote: >>> On Mon, Feb 9, 2009 at 12:06 AM, Vitaly Babiy wrote: > Hello everyone, > > I am working on a project that will need to make a request out to > the web and pull down some data, For testing purpose I was wonder > what would > be the best way to test this. I don't want to make the actual request > during > the test, because for one if I am off-line all those tests will fail. > > I have tried to implement a HTTPServer in python. The problem I am > having is once I have it thread, If I put it in the setUp method and > tearDown I get port in use exception. Due to the nature of the thread > it is > not guaranteed to be killed in time. > > Vitaly Babiy > > > You should be able to save the thread on the Test object during setup() and then kill it on teardown() shouldn't you? Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero >>> >>> >>> >> What if you just put a time.sleep(2) at the end of tearDown() that >> should give the thread enough time to close before the next test starts. >> >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your >> right to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> > > > Is what you are ultimately searching for similar to this: http://code.djangoproject.com/ticket/2879 Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero >>> >>> >>> >> The CherryPy WSGI server is usually a good choice for these things. >> >> >> Alex >> >> -- >> "I disapprove of what you say, but I will defend to the death your right >> to say it." --Voltaire >> "The people's good is the highest law."--Cicero >> >> >> >> > --~--~-~--~~~---~--~~ 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: User Auth... is_group in a template?
On Feb 9, 9:01 am, Alfonso wrote: > but is there a similar syntax for displaying HTML blocks depending on > the user group? Not builtin, no. But easy to add with a filter: http://www.djangosnippets.org/snippets/847/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
UnicodeEncodeError with gettext
Hello, I'm receiving the following error while running Django 0.96 with Google App Engine: UnicodeDecodeError at / 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128) GET Request URL:http://localhost:8080/ Exception Type: UnicodeDecodeError Exception Value:'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128) Exception Location: C:\Python25\lib\gettext.py in gettext, line 352 Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\lib\django\django \template\__init__.py" in render_node 723. result = node.render(context) File "C:\Program Files\Google\google_appengine\lib\django\django \templatetags\i18n.py" in render 43. return translation.gettext(value) File "C:\Program Files\Google\google_appengine\lib\django\django\utils \translation\trans_real.py" in gettext 265. return t.gettext(message) File "C:\Python25\lib\gettext.py" in gettext 352. return tmsg.encode(self._output_charset) UnicodeDecodeError at / 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128) I have the following parameters set: DEFAULT_CHARSET = 'utf-8' FILE_CHARSET = 'utf-8' Also, I have the following meta tag included in the page: >From what I understand, Django will always use Unicode, so I'm a little confused as to why it's trying to use an ASCII codec to display the UTF-8 characters for the translations. Any ideas? The translation files are working for the non-unicode languages, but failing for all UTF-8 based languages. Could it be something with the .po files being created incorrectly? --~--~-~--~~~---~--~~ 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: UnicodeEncodeError with gettext
On Mon, Feb 9, 2009 at 11:27 AM, Scott wrote: > > Hello, > > I'm receiving the following error while running Django 0.96 with > Google App Engine: > > UnicodeDecodeError at / > 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in > range(128) > > GET > Request URL:http://localhost:8080/ > Exception Type: UnicodeDecodeError > Exception Value:'ascii' codec can't decode byte 0xe3 in position 0: > ordinal not in range(128) > Exception Location: C:\Python25\lib\gettext.py in gettext, line 352 > > Traceback (most recent call last): > File "C:\Program Files\Google\google_appengine\lib\django\django > \template\__init__.py" in render_node > 723. result = node.render(context) > File "C:\Program Files\Google\google_appengine\lib\django\django > \templatetags\i18n.py" in render > 43. return translation.gettext(value) > File "C:\Program Files\Google\google_appengine\lib\django\django\utils > \translation\trans_real.py" in gettext > 265. return t.gettext(message) > File "C:\Python25\lib\gettext.py" in gettext > 352. return tmsg.encode(self._output_charset) > > UnicodeDecodeError at / > 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in > range(128) > > I have the following parameters set: > > DEFAULT_CHARSET = 'utf-8' > FILE_CHARSET = 'utf-8' > > Also, I have the following meta tag included in the page: > > > > From what I understand, Django will always use Unicode, so I'm a > little confused as to why it's trying to use an ASCII codec to display > the UTF-8 characters for the translations. > > Any ideas? The translation files are working for the non-unicode > languages, but failing for all UTF-8 based languages. Could it be > something with the .po files being created incorrectly? > > > Django only handles everything as unicode post the unicode branch merge, this happened between .96-1.0. That is to say on .96 Django doesn't handle things as unicode. I'm not entirely sure what that entailed, but it occured for a reason so I wouldn't expect that to work. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: UnicodeEncodeError with gettext
Quick edit, I meant to ask if it could be a problem with the '.mo' files being created incorrectly...the '.po' files that contain the unicode translations are UTF-8. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
A quick question about slug fields
I believe these days a statment like this has been depreciated: post_slug = models.SlugField(prepopulate_from=('post_title',)) I had a look through the docs but couldn't find the answer. How can you now specify which field the slug is created from? 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: A quick question about slug fields
On Mon, Feb 9, 2009 at 11:50 AM, djandrow wrote: > > I believe these days a statment like this has been depreciated: > > post_slug = models.SlugField(prepopulate_from=('post_title',)) > > I had a look through the docs but couldn't find the answer. > How can you now specify which field the slug is created from? > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#prepopulated-fields 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Exception in Django's Exception Handling
I'll see if I can extract some small subset and post the details. In the meantime, more info: the problem only occurs when an error is encountered during a call in which the server will return a HttpResponse('', mimetype='text/xml; charset=utf-8') object in response to some AJAX request; things apparently work when the server will return a render_to_response, which shows a page in the browser. Before I switched to Django, and just used webapp (a simplified version of Django in Google App Engine), the first type of problem would dump the stack trace to the console. Now, the trace does not go to the console, and it is here that the exception within the exception is thrown. Could this be a setting or path issue? On Feb 8, 3:00 pm, Karen Tracey wrote: > On Sun, Feb 8, 2009 at 2:20 PM, Devel63 wrote: > > > Django is raising an exception while trying to process an exception, > > resulting in no stack traces ... for many different types of errors. > > > It has the problem in debug.py, at this line under > > technical_500_response: > > return HttpResponseServerError(t.render(c), mimetype='text/html') > > > I have DEBUG=True, and TEMPLATE_DEBUG = DEBUG. The situation arises > > for almost any error (undefined var, missing func arg, call to > > undefined member func, etc.), but in some cases it does actually > > generate a stack trace! > > Ditto what Russ said: I've not seen this. Your earlier note, which I had in > my list of things to go back to and try to answer when I had more time if no > one else responded, mentions you are using Google App Engine...does that > apply to what you are talking about here? I've not done a lot with GAE, but > some,and I haven't seen this behavior there either -- I get regular Django > debug pages under GAE, though actually I'm only 100% sure of that when > running in the development environment, I don't know that I've tested it on > a deployed project. So specifics of a small test case that demonstrates the > problem you are seeing would help track this down -- it doesn't seem to be > behavior people are seeing generally. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Question about media in outside forms
Hello, I have been working on some forms which has some ajax behaivour, and I use some css and javascripts. This can be used inside a form with {{ form.media }}, which outputs the html tags necessary to import all the javascript and css to get all the fields working, and without duplicates if the field appears more than one time in the page. But when I use the {{ form.media }} more than once (imagine a for is generated for each element of a list and using includes or template tags) I don't know how to get just one tag for each media. Or when I need this behaivour to happen outside a form (with a template tag), don't know if this is possible. I mean, the declaration of the media and this is automatically included just when needed. thanks, Robert Ramírez Vique Computer Science Engineer --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Bizarre sqlite3 / apache2 behaviour
Hello, I installed yesterday Django 1.0.2 (current downloadable version) on a new Ubuntu 8.10 machine with python 2.5.2. I wrote a toy application and it works and shows fine with both the built-in development server and Apache 2 (2.2.9). The database is sqlite3, it came with python (btw, how do I get the sqlite3 version from python/the Linux command line?). Anyways, yesterday everything was working fine, including the admin application served by Apache. Today I only worked on templates, restarting apache frequently (I know about setting MaxRequestsPerChild 1 but anyways) but after a while I went to the admin application (served by apache) and I got an error: "OperationalError: attempt to write a readonly database", which is strange since it was working before and I haven't made today any changes to file or directory permissions or fiddled with the settings file. I looked up this error and I only see tips regarding permissions problems, bad path in the setting file or perhaps a sqlite version issue. I think none of that applies to me (since it was working yesterday) but I double-checked just in case. I tried different things for troubleshooting, including dropping the data with "manage.py sqlclear" and renaming the db file and re- creating it with "manage.py reset" and "manage.py syncdb" (I suspected perhaps the file was corrupted), but nothing I tried worked. I also checked the server (it wasn't rebooted recently etc). Here's a twist: if I start the development server and I log in, then the admin app in apache works fine (!), I can edit & save records etc. As soon as I log out of the development server, then apache gives me the readonly error. I'm ruling out client-side issues (cookies etc) since I tried with different browsers and computers, deleting session and cookies etc. Any ideas? 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: A quick question about slug fields
Thanks Karen On Feb 9, 4:53 pm, Karen Tracey wrote: > On Mon, Feb 9, 2009 at 11:50 AM, djandrow wrote: > > > I believe these days a statment like this has been depreciated: > > > post_slug = models.SlugField(prepopulate_from=('post_title',)) > > > I had a look through the docs but couldn't find the answer. > > How can you now specify which field the slug is created from? > > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#prepopulated-... > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Looking to give presentation on Django at work
Hi, it can be very powerful if as part of the presentation you add a little hands-on demo, like in: http://www.showmedo.com/videos/video?name=110&fromSeriesID=110 --~--~-~--~~~---~--~~ 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: UnicodeEncodeError with gettext
Thanks for the quick reply - does anyone know if Django 1.0 is patched into the Google App Engine Django Helper? --~--~-~--~~~---~--~~ 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: UnicodeEncodeError with gettext
On Mon, Feb 9, 2009 at 12:21 PM, Scott wrote: > > Thanks for the quick reply - does anyone know if Django 1.0 is patched > into the Google App Engine Django Helper? > Per http://code.google.com/p/google-app-engine-django/source/browse/trunk/CHANGES any reasonably current level of the app engine helper requires at least Django 1.0 beta1. So far as I know, though, it doesn't provide it, rather you have to include it as part of your app. Which is a bit of a pain since Django as shipped contains more than 1,000 files and a GAE app is limited to no more than 1,000 files. This page: http://code.google.com/appengine/articles/django10_zipimport.html under "Archiving Django 1.0" provides some details on bits of the django tree you can omit from your django.zip file (e.g. translations you won't need) so that you can keep within GAE limits and still use Django 1.0. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Extending the User model
Thanks, I owe you a chocolate bar I fix it class MyUser(User): chilean_rut = CLRutField(_('RUT'),unique=True) some_field = models.CharField(max_length=50) voalá I don't really need a PK, my mistake Thanks again. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
signals in 1.0 problem: nesh django utils & django 1.0
Hello, I've recently been porting many projects to 1.0, but have hit a snag with the current one. I'm looking at an old project that uses nesh's django utils (mainly just the thumbnail image field model), and have been slowly porting the project (and by extension nesh's code) to 1.0. Now i have read the documentation on signals, as well as the porting to 1.0 guide's signals section, but because i have not really used signals in my projects, i'm a little unsure what exactly is being called for by this error, and thought someone here may be of some help. The original code looked like: def contribute_to_class(self, cls, name): super(ImageWithThumbnailField, self).contribute_to_class(cls, name) dispatcher.connect(_delete, signals.post_delete, sender=cls) dispatcher.connect(self._save, signals.pre_save, sender=cls) My poor attempt at porting: def contribute_to_class(self, cls, name): super(ImageWithThumbnailField, self).contribute_to_class(cls, name) signals.post_delete.connect(_delete, sender=cls) signals.pre_save.connect(self._save, sender=cls) and the resultant error: line 45, in contribute_to_class signals.post_delete.connect(_delete, sender=cls) File "/usr/lib/python2.4/site-packages/django/dispatch/ dispatcher.py", line 84, in connect assert argspec[2] is not None, \ AssertionError: Signal receivers must accept keyword arguments (**kwargs). now my understanding of the syntax is that _delete and self._save would be keyword arguments, but apparently i am incorrect. Any help or suggestions would be greatly appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
user defined model
Hi, I need to update the model.py file at run-time. Where can I find the file on disk from the views.py please? What I'm trying to do is : Open model.py , append a new class , invoke syncdb. Thx Dids, --~--~-~--~~~---~--~~ 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: signals in 1.0 problem: nesh django utils & django 1.0
hi robocop - is it enough to add the '**kwargs' syntax to your receiver function? or is that already present? like: def _save(self, **kwargs): ... and def delete(**kwargs): ... -jake On Mon, Feb 9, 2009 at 12:15 PM, Robocop wrote: > > Hello, > I've recently been porting many projects to 1.0, but have hit a snag > with the current one. I'm looking at an old project that uses nesh's > django utils (mainly just the thumbnail image field model), and have > been slowly porting the project (and by extension nesh's code) to > 1.0. Now i have read the documentation on signals, as well as the > porting to 1.0 guide's signals section, but because i have not really > used signals in my projects, i'm a little unsure what exactly is being > called for by this error, and thought someone here may be of some > help. > > The original code looked like: > >def contribute_to_class(self, cls, name): >super(ImageWithThumbnailField, self).contribute_to_class(cls, > name) >dispatcher.connect(_delete, signals.post_delete, sender=cls) >dispatcher.connect(self._save, signals.pre_save, sender=cls) > > My poor attempt at porting: > > def contribute_to_class(self, cls, name): >super(ImageWithThumbnailField, self).contribute_to_class(cls, > name) >signals.post_delete.connect(_delete, sender=cls) >signals.pre_save.connect(self._save, sender=cls) > > and the resultant error: > > line 45, in contribute_to_class >signals.post_delete.connect(_delete, sender=cls) > File "/usr/lib/python2.4/site-packages/django/dispatch/ > dispatcher.py", line 84, in connect >assert argspec[2] is not None, \ > AssertionError: Signal receivers must accept keyword arguments > (**kwargs). > > > now my understanding of the syntax is that _delete and self._save > would be keyword arguments, but apparently i am incorrect. Any help > or suggestions would be greatly appreciated. > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
checkboxInput values
If i use the multiple Checkbox Input, It results in list of the items which were selected. My question is can you do the same thing for a single checkbox? As an old ASP guy I'd do this: I'm trying to do this in django by the following: #...snip forms.py el1_Choices = ( ('EN', 'ENGLISH'), ) el1=forms.ChoiceField (required=False, choices=el1_Choices, widget=forms.CheckboxInput(attrs={'class':'multibox'}) ) The resulting HTML is: As you can see there is no value. It is returning the following error: Select a valid choice. That choice is not one of the available choices. Even though I've got the form field setup to required=False. What is the proper way to assign a value to a single checkbox? Am I just stuck with boolean and true/false? That seems like a lot of extra work on the back end. --~--~-~--~~~---~--~~ 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: Looking to give presentation on Django at work
I already have the demo in place. I just wanted to spruce it up with a presentation and wanted to know if something already existed that I could work from. 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: signals in 1.0 problem: nesh django utils & django 1.0
Holy crap it is! Thanks for the idea, i'm going to do a lil testing and verify everything works. Thanks again! On Feb 9, 10:21 am, Jake Elliott wrote: > hi robocop - > > is it enough to add the '**kwargs' syntax to your receiver function? > or is that already present? > > like: > > def _save(self, **kwargs): > ... > > and > > def delete(**kwargs): > ... > > -jake > > On Mon, Feb 9, 2009 at 12:15 PM, Robocop wrote: > > > Hello, > > I've recently been porting many projects to 1.0, but have hit a snag > > with the current one. I'm looking at an old project that uses nesh's > > django utils (mainly just the thumbnail image field model), and have > > been slowly porting the project (and by extension nesh's code) to > > 1.0. Now i have read the documentation on signals, as well as the > > porting to 1.0 guide's signals section, but because i have not really > > used signals in my projects, i'm a little unsure what exactly is being > > called for by this error, and thought someone here may be of some > > help. > > > The original code looked like: > > > def contribute_to_class(self, cls, name): > > super(ImageWithThumbnailField, self).contribute_to_class(cls, > > name) > > dispatcher.connect(_delete, signals.post_delete, sender=cls) > > dispatcher.connect(self._save, signals.pre_save, sender=cls) > > > My poor attempt at porting: > > > def contribute_to_class(self, cls, name): > > super(ImageWithThumbnailField, self).contribute_to_class(cls, > > name) > > signals.post_delete.connect(_delete, sender=cls) > > signals.pre_save.connect(self._save, sender=cls) > > > and the resultant error: > > > line 45, in contribute_to_class > > signals.post_delete.connect(_delete, sender=cls) > > File "/usr/lib/python2.4/site-packages/django/dispatch/ > > dispatcher.py", line 84, in connect > > assert argspec[2] is not None, \ > > AssertionError: Signal receivers must accept keyword arguments > > (**kwargs). > > > now my understanding of the syntax is that _delete and self._save > > would be keyword arguments, but apparently i am incorrect. Any help > > or suggestions would be greatly appreciated. --~--~-~--~~~---~--~~ 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: checkboxInput values
> What is the proper way to assign a value to a single checkbox? Am I > just stuck with boolean and true/false? That seems like a lot of > extra work on the back end. nevermind i just figured out to use a value attribute --~--~-~--~~~---~--~~ 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: Keep getting NameError at /admin/
Hi Alex Yes I have the line from django.contrib import admin" in urls.py On 9 Feb, 16:20, Alex Gaynor wrote: > On Mon, Feb 9, 2009 at 11:11 AM, claudio.br...@googlemail.com < > > > > claudio.br...@googlemail.com> wrote: > > > Hi > > > I am new to django and have just started to play. I have a working > > (small) app but wanted to turn on the admin console for the project. I > > edited the settings.py to include the admin module and now get the > > following errors > > > NameError at /admin/ > > > name 'admin' is not defined > > > Request Method: GET > > Request URL:http://127.0.0.1:8000/admin/ > > Exception Type: NameError > > Exception Value: > > > name 'admin' is not defined > > > although I first saw the error using django 1.0.2, I can re-create it > > using 0.96. I have come to the conclusion that I am doing something > > wrong but can anyone tell me what? > > > the relevant part of my settings.py looks like; > > > INSTALLED_APPS = ( > >'django.contrib.auth', > >'django.contrib.contenttypes', > >'django.contrib.sessions', > >'django.contrib.sites', > >'django.contrib.admin', > > ) > > > and URLS looks like > > ># Uncomment the next line to enable the admin: > > (r'^admin/(.*)', admin.site.root), > > ) > > > i have removed evrything else from the project and app and still get > > the errror, at the top of the urls.py it makes no difference whether I > > have the line admin.autodiscover() or not as I still get the error > > > Regards > > > K > > Do you have the line "from django.contrib import admin" in your urls.py? > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Keep getting NameError at /admin/
On Feb 9, 6:57 pm, "claudio.br...@googlemail.com" wrote: > Hi Alex > > Yes I have the line from django.contrib import admin" in urls.py > You're going to need to post the whole urls.py. It's a bit hard to understand why you're getting that error if you do have that line, and it's not commented out. Please show us the whole file, preferably by posting it somewhere like dpaste.com. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: user defined model
On Feb 9, 6:13 pm, Dids wrote: > Hi, > > I need to update the model.py file at run-time. > > Where can I find the file on disk from the views.py please? > > What I'm trying to do is : Open model.py , append a new class , invoke > syncdb. > > Thx > Dids, This is extremely unlikely to work, not to mention very inefficient. Can you let us know why you want to do this - what's your use case? We might be able to suggest a better way of doing it. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Subclass conflict with admin widgets
I have implemented this solution successfully with a standard model, but when I try to use it on one which is subclassed I get an error because it is trying to validate the model before it knows about the subclass. I can work around this by defining an Admin class for each of the subclasses, but it seems to me this should work? Model.py class Directory(models.Model): name = models.CharField(max_length=60) pic1 = models.ImageField(upload_to='pics', blank=True, null=True) class Business(Directory): cat = models.ForeignKey(Subcategory) Admin.py AdminImageWidget defined class DirectoryAdminForm(forms.ModelForm): pic1 = forms.ImageField(widget=AdminImageWidget()) class Meta: model = Directory class DirectoryAdmin(admin.ModelAdmin): form = DirectoryAdminForm fieldsets = [ (None, {'fields': ['cat','name','is_live']}),< CAT FIELD IS PART OF BUSINESS NOT DIRECTORY SO CAUSES ERROR ('Contact', {'fields': ['phone','mobile','fax','email','web','address']}), ('Details', {'fields': ['description','pic1','pic2','pic3','pic4']}), ] admin.site.register(Business,DirectoryAdmin) Error ImproperlyConfigured at /admin/town/business/14/ 'DirectoryAdmin.fieldsets[2][1]['fields']' refers to field 'cat' that is missing from the form. Request Method: POST Request URL:http://dunmanway.pighaswings.com/admin/town/business/14/ Exception Type: ImproperlyConfigured Exception Value: 'DirectoryAdmin.fieldsets[2][1]['fields']' refers to field 'cat' that is missing from the form. Exception Location: /usr/lib/python2.4/site-packages/django/contrib/ admin/validation.py in check_formfield, line 255 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Admin Image Handling - ability to display thumb and delete an image - one solution
In case this helps anyone, here is one implementation I have 4 pictures attached to each record but would work the same if only one. Uses sorl-thumbnails and based on snippet here: http://www.djangosnippets.org/snippets/934/ written by baumer1122 In models.py - used standard models.ImageField class Car(models.Model): short_desc = models.CharField(max_length=40) ... pic1 = models.ImageField("Picture 1", blank=True, upload_to='pics') pic2 = models.ImageField("Picture 2", blank=True, upload_to='pics') pic3 = models.ImageField("Picture 3", blank=True, upload_to='pics') pic4 = models.ImageField("Picture 4", blank=True, upload_to='pics') In admin.py --- from django.contrib.admin.widgets import AdminFileWidget from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe from django.conf import settings from PIL import Image import os from sorl.thumbnail.main import DjangoThumbnail try: from sorl.thumbnail.main import DjangoThumbnail def thumbnail(image_path): t = DjangoThumbnail(relative_source=image_path, requested_size= (200,200)) return u'' % (t.absolute_url, image_path) except ImportError: def thumbnail(image_path): absolute_url = os.path.join(settings.MEDIA_ROOT, image_path) return u'' % (absolute_url, image_path) class AdminImageWidget(AdminFileWidget): """ A FileField Widget that displays an image instead of a file path if the current file is an image. """ def render(self, name, value, attrs=None): output = [] file_name = str(value) if file_name: file_path = '%s%s' % (settings.MEDIA_URL, file_name) try:# is image Image.open(os.path.join(settings.MEDIA_ROOT, file_name)) output.append('%s %s%s%s' % \ (file_path, thumbnail(file_name), file_path, file_name,_('Delete:'), name, _('Change:'))) except IOError: # not image output.append('%s %s %s ' % \ (_('Currently:'), file_path, file_name, _ ('Change:'))) output.append(super(AdminFileWidget, self).render(name, value, attrs)) return mark_safe(u''.join(output)) class CarAdminForm(forms.ModelForm): pic1 = forms.ImageField(widget=AdminImageWidget()) pic2 = forms.ImageField(widget=AdminImageWidget()) pic3 = forms.ImageField(widget=AdminImageWidget()) pic4 = forms.ImageField(widget=AdminImageWidget()) class Meta: model = Car class CarAdmin(admin.ModelAdmin): form = CarAdminForm def save_model(self, request, obj, form, change): #handle delete checkbox for pics if request.POST.get('delete_pic1','off')=='on': obj.pic1='' if request.POST.get('delete_pic2','off')=='on': obj.pic2='' if request.POST.get('delete_pic3','off')=='on': obj.pic3='' if request.POST.get('delete_pic4','off')=='on': obj.pic4='' obj.save() --~--~-~--~~~---~--~~ 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: Best practice question: subclassing external app components
On 9 fév, 00:35, zinckiwi wrote: > Hi folks, > > I'm just starting to play with django-registration and I want to > subclass the RegistrationForm for a couple of cosmetic tweaks > (capitalising the labels on the fields -- there may be a simpler way > to do this, but indulge me for the purposes of this question). I > understand that subclassing RegistrationForm and reassigning the label > strings is the way to do this -- no problem. > > My question is where to *put* that subclass. I can think of a few > places: > > - the project itself > - an "overrides" app dedicated to holding overrides for external apps > - a "registration_overrides" app dedicated to holding overrides for > just that one external app > > Perhaps there are other ways. I usually have a special 'project' app that I use for all this kind of project-specific stuff. --~--~-~--~~~---~--~~ 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: Question about media in outside forms
On Mon, Feb 9, 2009 at 12:00 PM, Robert Ramírez Vique wrote: > Hello, > > I have been working on some forms which has some ajax behaivour, and I use > some css and javascripts. This can be used inside a form with {{ form.media > }}, which outputs the html tags necessary to import all the javascript and > css to get all the fields working, and without duplicates if the field > appears more than one time in the page. > > But when I use the {{ form.media }} more than once (imagine a for is > generated for each element of a list and using includes or template tags) I > don't know how to get just one tag for each media. > > Or when I need this behaivour to happen outside a form (with a template > tag), don't know if this is possible. I mean, the declaration of the media > and this is automatically included just when needed. > > thanks, > Robert Ramírez Vique > Computer Science Engineer > > > > The best way to do this would be to make a templatetag that took multiple form.media instances, added them together(which can be done with media instances) and then output the response. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
writing a urlpattern for a form submission
I'm sure this will come across as basic to many django users but it has got me stuck so any helpful pointers would be appreciated. I've scoured the docs and come up empty. Upfront apologies done now, here's what I got: Using django forms, i create a form which results in a submission string like this: http://127.0.0.1:8000/shiftcalendar/?year=2010&group=1&submit=Get+calendar So in my urls.py I set up a urlpattern like this: urlpatterns = patterns('local1042.shiftcalendar.views', (r'^$', 'index'), (r'^(?P\w+)/(?P\w+)$', 'showcal'),) I thought that that would do it, and I've tried every variation you could think of, but I'm missing something. I know I should use POST but for debugging I've been using GET. The index page works just fine. I just can't get it to call the showcal function. Any thoughts would be appreciated. Thanks. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: user defined model
> This is extremely unlikely to work, not to mention very inefficient. > Can you let us know why you want to do this - what's your use case? We > might be able to suggest a better way of doing it. > -- > DR. Users define a set of data they're interested in. Give a mean to get the data (script, sql ...). The system goes and get the data at regular interval (save by date) The user can then review the data (table, charts , trends etc...) See it as a basic monitoring system where I currently have no idea what data the users will be interested in. I guess I can skip the table cration for each entity but I'm worried the code for data retrieval might get messy. Not to mention the templates ... Thanks for your input. Dids, --~--~-~--~~~---~--~~ 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: Strange 404 error in admin
On Feb 9, 7:20 pm, Julien Phalip wrote: > Hi, > > This is a strange case. I have a simple blog entry model which can be > edited in the admin, from the URL that looks > like:http://www.example.com.au/admin/blog/entry/52/ > > Now, what is strange is that the link above returns a 404. Same with > the entry id=51. Yet, entries with id=51,52 do exist. > > - All other entries (with id < 51) work fine in the admin. > - All entries (including id=51,52) work fine on the front end. > - Everything works fine when I test it locally on my computer with a > replica of the online database. > > I've never come across something like that, and I'm not sure where to > look to debug this. Would you have some hints to suggest? > > Thanks a lot for your help, > > Julien > > PS: It is using a quite old version of Django, a trunk revision > between 0.96 and 1.0. Hi, I've narrowed down the issue a bit. First, it's using revision 7901, that is before newforms-admin. The problem is in the 'change_stage' view: def change_stage(request, app_label, model_name, object_id): ... try: manipulator = model.ChangeManipulator(object_id) except model.DoesNotExist: raise Http404('%s object with primary key %r does not exist' % (model_name, escape(object_id))) ... When retrieving the manipulator it raises a 'DoesNotExist' exception: str: Traceback (most recent call last): File "", line 1, in File "C:\Djangos\catalyst\django\db\models\manipulators.py", line 260, in __init__ self.original_object = self.manager.get(pk=obj_key) File "C:\Djangos\catalyst\django\db\models\manager.py", line 82, in get return self.get_query_set().get(*args, **kwargs) File "C:\Djangos\catalyst\django\db\models\query.py", line 294, in get % self.model._meta.object_name) DoesNotExist: Entry matching query does not exist. But I only get that with those two Entry items (id=51,52). Why don't I get it for the other items (id < 51)? I'm really lost here. There must be some kind of corruption in the data meaning it cannot find those particular items, but what could it be? Again, those 2 blog entries work fine when displayed in the frontend. Do you think it could be a bug in that particular revision of Django I'm using? Any help would be appreciated. Julien --~--~-~--~~~---~--~~ 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: Strange 404 error in admin
On Mon, Feb 9, 2009 at 3:40 PM, Julien Phalip wrote: > > On Feb 9, 7:20 pm, Julien Phalip wrote: > > Hi, > > > > This is a strange case. I have a simple blog entry model which can be > > edited in the admin, from the URL that looks like: > http://www.example.com.au/admin/blog/entry/52/ > > > > Now, what is strange is that the link above returns a 404. Same with > > the entry id=51. Yet, entries with id=51,52 do exist. > > > > - All other entries (with id < 51) work fine in the admin. > > - All entries (including id=51,52) work fine on the front end. > > - Everything works fine when I test it locally on my computer with a > > replica of the online database. > > > > I've never come across something like that, and I'm not sure where to > > look to debug this. Would you have some hints to suggest? > > > > Thanks a lot for your help, > > > > Julien > > > > PS: It is using a quite old version of Django, a trunk revision > > between 0.96 and 1.0. > > Hi, > > I've narrowed down the issue a bit. First, it's using revision 7901, > that is before newforms-admin. > The problem is in the 'change_stage' view: > > def change_stage(request, app_label, model_name, object_id): >... >try: >manipulator = model.ChangeManipulator(object_id) >except model.DoesNotExist: >raise Http404('%s object with primary key %r does not exist' % > (model_name, escape(object_id))) >... > > When retrieving the manipulator it raises a 'DoesNotExist' exception: > > str: Traceback (most recent call last): > File "", line 1, in > File "C:\Djangos\catalyst\django\db\models\manipulators.py", line > 260, in __init__ >self.original_object = self.manager.get(pk=obj_key) > File "C:\Djangos\catalyst\django\db\models\manager.py", line 82, in > get >return self.get_query_set().get(*args, **kwargs) > File "C:\Djangos\catalyst\django\db\models\query.py", line 294, in > get >% self.model._meta.object_name) > DoesNotExist: Entry matching query does not exist. > > But I only get that with those two Entry items (id=51,52). Why don't I > get it for the other items (id < 51)? > > I'm really lost here. There must be some kind of corruption in the > data meaning it cannot find those particular items, but what could it > be? Again, those 2 blog entries work fine when displayed in the > frontend. > > Do you think it could be a bug in that particular revision of Django > I'm using? > > Any help would be appreciated. > > Julien > > > I don't know what manager old forms admin used, but do you have a custom manager that blocks access to some objects. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 detect inactivity session time out?
Any one with a clue on How do I detect time out in my app and give user a page that they have been timed out due to inactivity. I am usingrequest.session.set_expiry(900) , SESSION_COOKIE_AGE = 900 and django standard authentication using autheticate(), login() and logout(). On Feb 8, 12:07 pm, ydjango wrote: > I am setting inactivity session time out using - > a) request.session.set_expiry(900) and > b) SESSION_COOKIE_AGE = 900 > > I believe both work exactly the same way. Please correct me if they > have any different behavior. > > How do I detect this time out in my app and give user a page that they > have been timed out due to inactivity. > I am using django standard authentication using autheticate(), login() > and logout() --~--~-~--~~~---~--~~ 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: writing a urlpattern for a form submission
On Feb 9, 8:16 pm, kosuke wrote: > I'm sure this will come across as basic to many django users but it > has got me stuck so any helpful pointers would be appreciated. I've > scoured the docs and come up empty. Upfront apologies done now, > here's what I got: > > Using django forms, i create a form which results in a submission > string like this: > > http://127.0.0.1:8000/shiftcalendar/?year=2010&group=1&submit=Get+cal... > > So in my urls.py I set up a urlpattern like this: > > urlpatterns = patterns('local1042.shiftcalendar.views', > (r'^$', 'index'), > (r'^(?P\w+)/(?P\w+)$', 'showcal'),) > > I thought that that would do it, and I've tried every variation you > could think of, but I'm missing something. I know I should use POST > but for debugging I've been using GET. The index page works just > fine. I just can't get it to call the showcal function. > > Any thoughts would be appreciated. > > Thanks. Kevin URL patterns don't match GET variables - ie anything after the ?. You just need to match on /shiftcalendar/, and everything else will be passed as keys in the request.GET dictionary. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Strange 404 error in admin
On Feb 10, 7:41 am, Alex Gaynor wrote: > I don't know what manager old forms admin used, but do you have a custom > manager that blocks access to some objects. Thanks Alex for your reply. You've made a really good point which helped me track this down. Here are the model and manager: class PublishedEntryManager(models.Manager): def get_query_set(self): return super(PublishedEntryManager, self).get_query_set().filter (pub_date__lte=datetime.now) class Entry(models.Model): ... some fields ... pub_date = models.DateTimeField() published = PublishedEntryManager() In fact, if an entry has a pub_date set in the future, then it is not accessible in the admin. Somehow the admin seems to be using the PublishedEntryManager as default manager. Is there a way to force the admin to use the default manager? Thanks again, Julien --~--~-~--~~~---~--~~ 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: Subclass conflict with admin widgets
On Feb 9, 7:28 pm, phoebebright wrote: > I have implemented this solution successfully with a standard model, > but when I try to use it on one which is subclassed I get an error > because it is trying to validate the model before it knows about the > subclass. I can work around this by defining an Admin class for each > of the subclasses, but it seems to me this should work? > > Model.py > > class Directory(models.Model): > name = models.CharField(max_length=60) > pic1 = models.ImageField(upload_to='pics', blank=True, > null=True) > > class Business(Directory): > cat = models.ForeignKey(Subcategory) > > Admin.py > > AdminImageWidget defined > > class DirectoryAdminForm(forms.ModelForm): > pic1 = forms.ImageField(widget=AdminImageWidget()) > > class Meta: > model = Directory > > class DirectoryAdmin(admin.ModelAdmin): > > form = DirectoryAdminForm > > fieldsets = [ > (None, {'fields': ['cat','name','is_live']}), < > CAT FIELD IS PART OF BUSINESS NOT DIRECTORY SO CAUSES ERROR > ('Contact', {'fields': > ['phone','mobile','fax','email','web','address']}), > ('Details', {'fields': > ['description','pic1','pic2','pic3','pic4']}), > ] > > admin.site.register(Business,DirectoryAdmin) > > Error > > ImproperlyConfigured at /admin/town/business/14/ > > 'DirectoryAdmin.fieldsets[2][1]['fields']' refers to field 'cat' that > is missing from the form. The error message tells you what is going on. Your form definition has model=Directory in its Meta class, so it only contains fields from the Directory model. If you want it to contain the fields from the subclassed Business model, you'll need to change that Meta declaration. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FormSet with non input-element data possible?
Hi -- I'm creating a FormSet and want to include some data in the form output that is not an html input element. Some of the data I pass to the FormSet, which gets passed to the form, I just want to display, I don't want to put it into an HTML input element. I want it to be available in the template. Here is what I tried, which doesn't work: class SectionForm(forms.Form): section_id = forms.IntegerField(label='Section ID:', required=False, widget=forms.HiddenInput()) section_title = forms.CharField(label='Title', required=True) section_text = forms.CharField(label='', widget=forms.Textarea, required=True) def __init__(self, data=None, auto_id='id_%s', prefix=None, initial=None, empty_permitted=False): super (SectionForm, self).__init__(data, auto_id, prefix, initial, empty_permitted) # This is what I want to do, more or less, but it won't work (TypeError: unscriptable object) #self.s3_audio_file = initial['s3_audio_file'] In the template, I want to display s3_audio_file, but I don't need or want it to be editable. It's for information only. Just text, or html-formatted text. {{ form.s3_audio_file }} Is there some way to have the form contain arbitrary data that I pass to it with the "initial" dictionary? Perhaps, I have to create a faux Widget and Custom field? That seems like a long way around for something that should be simple. Thanks in advance for any help. Best, Liam Also, I was unsure about what to do with empty_permitted -- I got an error before I added it to the super() call. --~--~-~--~~~---~--~~ 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: Strange 404 error in admin
On Feb 10, 7:52 am, Julien Phalip wrote: > On Feb 10, 7:41 am, Alex Gaynor wrote: > > > I don't know what manager old forms admin used, but do you have a custom > > manager that blocks access to some objects. > > Thanks Alex for your reply. You've made a really good point which > helped me track this down. Here are the model and manager: > > class PublishedEntryManager(models.Manager): > def get_query_set(self): > return super(PublishedEntryManager, > self).get_query_set().filter > (pub_date__lte=datetime.now) > > class Entry(models.Model): > ... some fields ... > pub_date = models.DateTimeField() > > published = PublishedEntryManager() > > In fact, if an entry has a pub_date set in the future, then it is not > accessible in the admin. Somehow the admin seems to be using the > PublishedEntryManager as default manager. Is there a way to force the > admin to use the default manager? > > Thanks again, > > Julien Hello again, I finally fixed it with the following nasty hack: class Entry(models.Model): ... some fields ... objects = models.Manager() # Nasty hack published = PublishedEntryManager() It seems like the 'change_state' view uses the custom manager instead of the default one. Explicitly setting 'objects' make it work. If you can think of a more elegant fix, please let me know ;) Regards, Julien --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
python manage.py runserver giving strange error
Hello django users, Today I have had this strange error: after a syntax error in a module I had to restart my development server. marigold:qmm arno$ python manage.py runserver /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/ Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory All of a sudden, Python pretends not to be able to see manage.py! But manage.py is present and what's more: marigold:qmm arno$ python manage.py Type 'manage.py help' for usage. marigold:qmm arno$ python manage.py help runserver Usage: manage.py runserver [options] [optional port number, or ipaddr:port] Starts a lightweight Web server for development. [...] What's going on? I have no idea where to start looking, I am not even sure it's django related (although I have not found any other problem with python). A reboot of the system (Mac OS X 10.5.6) doesn't solve the problem. I would appreciate any hint. -- Arnaud Delobelle. --~--~-~--~~~---~--~~ 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: Subclass conflict with admin widgets
Yes I see that, it's just if I don't put the custom form in it works fine: class DirectoryAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields': ['cat','name','is_live']}),< CAT FIELD STILL HERE AN OK ('Contact', {'fields': ['phone','mobile','fax','email','web','address']}), ('Details', {'fields': ['description','pic1','pic2','pic3','pic4']}), ] admin.site.register(Business,DirectoryAdmin) It suggest to me there is something in the admin code which normally allows for this 'error' to pass. It's not a big deal, I just wondered if it was somthing django should allow for and the design of the two examples is inherantly the same. On Feb 9, 8:52 pm, Daniel Roseman wrote: > On Feb 9, 7:28 pm, phoebebright wrote: > > > > > I have implemented this solution successfully with a standard model, > > but when I try to use it on one which is subclassed I get an error > > because it is trying to validate the model before it knows about the > > subclass. I can work around this by defining an Admin class for each > > of the subclasses, but it seems to me this should work? > > > Model.py > > > class Directory(models.Model): > > name = models.CharField(max_length=60) > > pic1 = models.ImageField(upload_to='pics', blank=True, > > null=True) > > > class Business(Directory): > > cat = models.ForeignKey(Subcategory) > > > Admin.py > > > AdminImageWidget defined > > > class DirectoryAdminForm(forms.ModelForm): > > pic1 = forms.ImageField(widget=AdminImageWidget()) > > > class Meta: > > model = Directory > > > class DirectoryAdmin(admin.ModelAdmin): > > > form = DirectoryAdminForm > > > fieldsets = [ > > (None, {'fields': ['cat','name','is_live']}), < > > CAT FIELD IS PART OF BUSINESS NOT DIRECTORY SO CAUSES ERROR > > ('Contact', {'fields': > > ['phone','mobile','fax','email','web','address']}), > > ('Details', {'fields': > > ['description','pic1','pic2','pic3','pic4']}), > > ] > > > admin.site.register(Business,DirectoryAdmin) > > > Error > > > ImproperlyConfigured at /admin/town/business/14/ > > > 'DirectoryAdmin.fieldsets[2][1]['fields']' refers to field 'cat' that > > is missing from the form. > > The error message tells you what is going on. Your form definition has > model=Directory in its Meta class, so it only contains fields from the > Directory model. If you want it to contain the fields from the > subclassed Business model, you'll need to change that Meta > declaration. > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Forms, fields and widgets
Hello, I'm fairly new Django user, but have some background experience with other frameworks. Sorry if this topic was discussed before, but I was not able to find any mention of it. My question is related to architectural decisions of the forms, fields and widgets. At the moment in Django, all "incoming" data is processed by the widget and clean by the field. Data flow: raw data -> widget -> field -> form. However, reverse process is different: data -> form -> widget data. As you can see, field does not play and role in reverse data conversion. Let's examine simple task. ModelForm calls model_to_dict() to initialize form fields with initial data. In case of models data is their id's. But what if one will want to develop widget that requires more than just a model id? For example: str(model) and model.id at the same time? There are not so many options how it can be done right now: or derive from ModelForm and override it's data gathering behavior (rewrite model_to_dict()) or run extra query in the widget itself (which is not optimal). Possible naive solution: if it would be possible to make field work in _both_ directions, it would be awesome. If field will know that it works with models (like ModelForm related fields), it will be responsible for cleaning data to the widget-appropriate format. It is my two cents. I don't know if somebody already tried to make it work this way of there were some reasons not to do this way... I don't know. Thanks, Serge. -- Best regards, Serge mailto:serge.ko...@gmail.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Forms, fields and widgets
On Mon, Feb 9, 2009 at 5:18 PM, Serge S. Koval wrote: > > Hello, > > I'm fairly new Django user, but have some background experience with > other frameworks. Sorry if this topic was discussed before, but I was > not able to find any mention of it. > > My question is related to architectural decisions of the forms, > fields and widgets. > > At the moment in Django, all "incoming" data is processed by the > widget and clean by the field. Data flow: raw data -> widget -> field -> > form. > However, reverse process is different: data -> form -> widget > data. As you can see, field does not play and role in reverse data > conversion. > > Let's examine simple task. ModelForm calls model_to_dict() to > initialize form fields with initial data. In case of models data is > their id's. > But what if one will want to develop widget that requires more > than just a model id? For example: str(model) and model.id at the same > time? There are not so many options how it can be done right now: or > derive from ModelForm and override it's data gathering behavior > (rewrite model_to_dict()) or run extra query in the widget itself (which > is not optimal). > > Possible naive solution: if it would be possible to make field work in > _both_ directions, it would be awesome. > If field will know that it works with models (like ModelForm related > fields), it will be responsible for cleaning data to the > widget-appropriate format. > > It is my two cents. I don't know if somebody already tried to make it > work this way of there were some reasons not to do this way... I don't > know. > > Thanks, > Serge. > > -- > Best regards, > Serge mailto:serge.ko...@gmail.com > > > > > I would recommend searching the dev list for a thread titled: "Controlling form/widgets output". Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
using the ImageField with the API
Hey everyone, I've got an interesting problem concerning file uploads. I'm building an online auction and my `Lot` links to a thin `LotImage` so that I can store multiple images of the lots: class Lot(models.Model): ... lot_number = models.PositiveIntegerField("Lot number") Class LotImage(models.Model) ... lot = models.ForeignKey(Lot, related_name="images") main_image = models.ImageField(upload_to=get_main_image_path) you can see I've written a callable for the `upload_to` parameter because I want to store the images in a particular place: def get_thumbnail_path(instance, filename): return os.path.join( LotImage.BASE_PATH, instance.lot.catalogue.__unicode__(), filename ) This is all good and works a treat in the admin UI, but how can I keep this `upload_to` functionality when working with the API by hand? Django's Documentation on the subject talks about the `File` class (http://docs.djangoproject.com/en/dev/topics/files/#the-file-object) which works fine when you explicitly create LotImages: f = open('/tmp/hello.world', 'w') myfile = File(f) f.close() LotImage.create( lot_id = 1, main_image = myfile ) But by doing so, I loose the `upload_to` functionality. How can I keep it without physically moving the file to the right place, then creating a File object and attaching to a new LotImage? I basically want to create exactly what the admin UI does with uploaded files. Can anyone help? Thanks, RM --~--~-~--~~~---~--~~ 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[2]: Forms, fields and widgets
Hello Alex, Tuesday, February 10, 2009, 12:21:05 AM, you wrote: > I would recommend searching the dev list for a thread titled: "Controlling form/widgets output". Alex Thanks, I was looking in django-users list and this topic was django-devel. -- Best regards, Serge mailto:serge.ko...@gmail.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
YUI Image Uploader - OK on Firefox/Mac but not elsewhere
Have been trying to get a RTE plugin working that will allow upload of images. The YUI verion is almost there but will not play well with browsers. The plugin from here http://allmybrain.com/2008/11/06/example-yui-image-upload-with-yui-260/ I modified to get Javascript to make an asynchronous call to this function in the view: def uploadimage(request): try: upload_full_path = settings.CONTENT_IMAGES upload = request.FILES['image'] dest = open(os.path.join(upload_full_path, upload.name), 'wb+') for chunk in upload.chunks(): dest.write(chunk) dest.close() result='{status:"UPLOADED",image_url:"%s%s"}' % (settings.CONTENT_IMAGES_URL, upload.name) return_data = HttpResponse(result,mimetype='Content-Type: text/ html') except Exception, e: return_data = HttpResponse("Error in uploading image") return_data.flush() return return_data The plugin was written for turbon gears/php and there is a tg example here: http://allmybrain.com/2007/10/22/yui-image-uploader-example-with-turbogears/ Firefox/Mac works perfectly. Safari downloads the image instead. No version on PC appears to do anything, (but only have Mac for local testing.) Have tried every possible permutation of the content-type, Content- Type and text/html definitely is the way to go. Various threads on python refer to the need to open the file for reading as rb to make sure windows knows it is binary, but not sure how to do that as the response data is already in memory. In desperation I have also tried to implement image upload in TinyMCE - can't get FileBrowser working on PC. and FCKeditor no modifiable image upload that I could find. So I am back with YUI and hoping someone can suggest something to try --~--~-~--~~~---~--~~ 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: Exception in Django's Exception Handling
On Tue, Feb 10, 2009 at 1:59 AM, Devel63 wrote: > > I'll see if I can extract some small subset and post the details. > > In the meantime, more info: the problem only occurs when an error is > encountered during a call in which the server will return a > HttpResponse('', mimetype='text/xml; charset=utf-8') object in > response to some AJAX request; things apparently work when the server > will return a render_to_response, which shows a page in the browser. > > Before I switched to Django, and just used webapp (a simplified > version of Django in Google App Engine), the first type of problem > would dump the stack trace to the console. Now, the trace does not go > to the console, and it is here that the exception within the exception > is thrown. > > Could this be a setting or path issue? It _could_ be many things. However, unless you give us details, we can't give you details. So far, you haven't even told us the exceptions you are seeing. In the absence of details, we would only be guessing, and given that none of us have seen this problem before, it wouldn't be a particularly educated guess. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: python manage.py runserver giving strange error
I've avoided the problem by using django-admin instead of manage.py... Which does not tell me what's gone wrong. -- Arnaud --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---