Re: Hi guys, I'm having trouble with newform-admin interface
astray wrote: > ProgrammingError: error: There's no relation named "django_session" > <--- message translated by my own because I'm not English user. Just > focus on the meanig of this message cause this might be not identical. > _ > > I'm guessing this message is related with my db table. Can't solve > error though. Or might be serious error somewhere. Stuck on this > problem half of my day and making me frustrated. Please give me help > to get out of this damned message :( You probably need to do `python manage.py syncdb`, as you have probably installed the django.contrib.sessions application after you ran a syncdb the last time. Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Does the development enterprise application have the available third party report library
vance ma wrote: > Does the development enterprise application have the available report > library? What application? What library? Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: set session expiry time in settings.py
burcu wrote: > Him Team, > > i want to set session expiry time in settings.py. Could you please > help me regarding this case? http://docs.djangoproject.com/en/dev/topics/http/sessions/#session-cookie-age -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: models problem
Vicky wrote: > Some datas in my database are missing when i view it using models.Am > using MYSql db. The datas that are in database when viewing using > querry browser where not seen when using model to access database. can > anyone help Does the ORM "calculated" SQL correspond to the SQL you are running? /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: which class does ####__iexact belong to, where #### is the attribute of a model?
rabbi wrote: > Hi, > I'm trying to write a generic filter function do something like > following: >MyModel.objects.filter( getattr(???,my_dict['search_field'] > +'__iexact')=my_dict['search_value'] ) > > But I don't know what to put in place of '???' > Where does 'field__iexact' actually come from? > Is it part of MyModel or somewhere else? You don't need getattr: MyModel.objects.filter(**{ my_dict['search_field'] + '__iexact': my_dict['search_value'] }) I believe that will do the trick :) Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Deleting a session variable
Michael wrote: > Hello, > I'm sure this is a easy question. > > In one of my views I need to delete the session variable > 'request.session['percent']'. However, sometimes 'request.session > ['percent']' never gets created. When this is the case I get an error > when I do 'del request.session['percent']'. How do I check to see if > 'request.session['percent']' has been created? if 'percent' in request.session: del request.session['percent'] Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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 locate the OS currently logged in user??
PeteDK wrote: > Hi. > > I want to retreive the name of the currently logged in user on the OS > on which my django app lives. > Is this possible? You are aware that on most systems, more than one user is allowed to login concurrently? [...] > i have looked into the python standard library, and a module named > getpass() however i cant get i to work:-( > > i hope someone has a clever idea to solve this problem. > > PS: and the webserver runs linux. :-) This will give you a list of the currently logged in users: >>> import commands >>> [line.split()[0] for line in commands.getoutput("/usr/bin/who").split("\n")] ['razor'] /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError - unpack non-sequence
Alfonso wrote: > Upgraded to latest svn trunk and now getting brand new error on every > page/url path save for homepage. Not entirely sure how to track down > the fault in configuration etc. Anyone help? Thankyou! Please specify the exact svn revision. Also, what revision was the last where your project worked? /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Module not callable (Practical Django Projects)
marsii wrote: > I working whit the book Practical Django Project and have a problem > with th weblog example. > > (I have Django revision 8511. > > I got the following error when I try to add an entry: > --- > TypeError at /admin/coltrane/entry/add/ > > 'module' object is not callable > from markdown import markdown [...] > self.body_html = markdown(self.body) <-- LINE 76 ERROR The imported name 'markdown' should be a function, yet python thinks it's a module. What is it? Try importing markdown and running the above snippet outside of django in a python shell. Does that work? Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: json
yozhik wrote: > hi all, > > does anyone have a very simple example of how to use json and jquery > to communicate between django and javascript. i'm trying to use > $.getJSON but getting confused what parameters to provide to it. docs > say > getJSON(url,data,func). well, func is my javascript function which > handles data from django. but I am mainly confused about url. `url` is the URL where jQuery will request the JSON data from. It could be `/json/somefeed/` or whatever you have configured the URL of your Django view to in urls.py. Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: amd64 vs x86 hosting
mcosta wrote: > One question: ¿amd64 or x86? we've got some bechmark claiming superior > performance for amd64, both with python and mysql, but then we can not > tune with psyco. We've taken a look at pyrex but we do not know even > if we are shooting in our foot with any of these. ¿are these > technologies useful for actual web app tuning? In my experience, when it comes to database backed web applications, the application logic is seldom the bottleneck (unless, of course, you do a lot of numbers crushing). You should probably focus your optimization on your database instead, and not so much whether you should use psyco or pyrex to speed up your Python code. Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to setup the admin media?
Ethan wrote: > In my first django project, use the apache server, in the admin page, > it can't find the css file. and how does the admin css file generate? http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id3 -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multiple relationships between multiple tables
Necmettin Begiter wrote: > Hello all, > > I have, say, 8 tables: Persons, works, phones, emails, addresses, > eaddresses, articles, books. > > Each one may have relationship with another one, like so: > > A person may have more than one work, phone, email, address, eaddress, > article and book. > A phone, email, address, eaddress, .. may be related to more than one > persons. > > So, here is a sample model: > > class Relations(models.Model): > srctbl = models.CharField(max_length=2, choices=TBL_CHOICES) > srcidx = models.IntegerField() > tgttbl = models.CharField(max_length=2, choices=TBL_CHOICES) > tgtidx = models.IntegerField() > > But there's a *slight* problem here. Possible values for *idx fields > must change when *tbl are changed, like so: > > If I select Person for srctbl, srcidx must contain names of possible > persons; if I select Phone for srctbl, srcidx must contain possible > phone numbers. And this is the same for tgt* fields. I have been looking > around Django Docs and references for a while now, but couldn't come > with a solution. IntegerField()s must actually be like ForeignKey(Person > or Phone or Email or Address or eAddress) .. Any ideas on how to achieve > this? Why aren't you using ManyToManyField's? It sounds like that's what you're trying to emulate ;) Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to assign a value to a model object field
Lenny wrote: > Hi! > How can I assign a value to a model object field where the field name > in a string? As with any other python object, you can use setattr: setattr(instance, "property", "value") Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: cannot import name SimpleCookie on new Django install
Wayne Collier wrote: > from Cookie import SimpleCookie > ImportError: cannot import name SimpleCookie It sounds like your python installation is broken. What about when you fire up a plain python shell and type: >>> from Cookie import SimpleCookie Cookie is a bundled module in the standard library for python 2.5 (and 2.4) Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ensuring a string does not get escaped in views.py
Kevin wrote: > album_uri_to_copy might look like: > http://www.ggpht.com//data/feed/api/user/someuser/album?id=4rdioE_s&kind=photo > > When calling: > album_feed = gclient1.GetFeed(album_uri_to_copy) > > from a Python shell it works fine. When calling it from Django it > returns an Exception saying that album_uri_to_copy isn't a valid uri > or atom feed (this is a google error message). > > I SUSPECT that the & is getting changed to "&". The thing is, I've > used {{ album_uri|safe }} in my template, so album_uri_to_copy should > be safe! I'm thinking that Django is interfering with the > album_uri_to_copy string in the GetFeed() call. Well - you can check what the value actually is by using the python `print` statement on the developlment server. Everything you print will be written to the terminal running `runserver`. print "album_uri_to_copy is", album_uri_to_copy album_feed = gclient1.GetFeed(album_uri_to_copy) More about debugging django here: http://simonwillison.net/2008/May/22/debugging/ Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: page not updating right away
ashbii wrote: > I am new to Django, but love it so far. I went through a tutorial and > created a basic blog app. I'm using Django's admin interface to add > new blog posts -- I have a blog "Post" model. > > My problem is that whenever I enter and save a new blog post via > admin, its not showing up on the web page (template) right away. It > usually shows up after a few hours. It shows up right away on the > admin side though. This leads me to believe that there is some sort > of caching going on, but I do not have any type of Django cache > setting going on in my settings.py file. Is this a python cache > issue? I've tried pkill python, but doesn't work either. Is there a > template/web page cache in Django? No there isn't. Could you show us the code for your view? Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: syntax for runtime evaluation of Q objects
chris wrote: > Dear django users, > > Being rather new to django, I can't wrap my head around the > following: > I am trying to execute a query from a search form. The search form > has three fields, Names, Dates and Places. I want to AND the queries, > so that if Names and Places are filled in, I want to return only > records that match both. > > My idea was to build up the condition in a dictionary while looking > through the fields returned from the form like this: > > if places: > Q['places'] = Q(persplace__icontains=places) > > if names: > Q['names'] = Q(persname__icontains=names) > > etc and then concatenate and execute the whole at the end: > > results = Person.objects.filter("|".join(Q.values()) You are almost right. Istead of "|".join() you need to use something like reduce and operator.or_: import operator results = Person.objects.filter(reduce(operator.or_, Q.values())) The builtin function `reduce` will apply the first argument to every element in the sequence given as the second argument and reduce it to a single value, just as if you wrote: var1 | var2 | var3 Another thing is - unless you use the key of the dictionary, a list might be more appropriate for this ;) Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: render_to_response failed to render media files in base.html
Chuck Bai2 wrote: > Here is my view code: > > def contact(request): > form = ContactForm() # An unbound form > return render_to_response('contact.html', { > 'form': form, > }) > My contact form page rendered but without all the media files(CSS files, > Javascripts files, images). The text part of the page is OK and I can > see my contact form displayed OK. > If I left the form out, just render the page using direct_to_template > like below, the page is working fine. All the media files are rendered. > > def contact(request): > return direct_to_template(request, template='contact.html') These views doesn't have anything to do with serving media. Check the two outputs if the media paths are correct. You are probably missing the context_instance argument for render_to_response to have context processors activated and get any context processor generated extra context variables available in your template. Use the RequestContext as a base context when using render_to_response: return render_to_response('contact.html', { 'form': form, }, context_instance=RequestContext(request)) Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Has anyone looked into writing an SSH backend for file uploads?
Andrew Ingram wrote: [...] > Ideally you'd be able to provide it with a tuple of machines to > connect to which would allow you to upload to all the machines at once > (but even if there's one that only allows you to upload to one machine > that would still be useful). What if one of the machines was unresponsive at the time of the upload? Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: newbie: printing a date in a template
KJ wrote: > In my view, I have this definition: > from datetime import date > todaysdate = date.today() > > In my template, I am trying to print out this date using: > {{ todaysdate }} > > And everything else in the template prints fine, but the date doesn't > print. Is there something simple I am doing wrong? Is `todaysdate` listed in your context? /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Fwd: python sql query in django
James Matthews wrote: > I have three tables: > > class Technology(models.Model): >technology = models.CharField(max_length=100, null=True, > blank=True ) >def __unicode__(self): >return self.technology >class Meta: >ordering = ["technology"] > > class Publication(models.Model): >pubtitle = models.TextField(null=True, blank=True) > def __unicode__(self): >return self.pubtitle >class Meta: >ordering = ["pubtitle"] > > class Techpubcombo(models.Model): >technology = models.ForeignKey(Technology) >publication = models.ForeignKey(Publication) > > The user selects a technology from the drop down menu on the web > page. The technology is retrieved > from the database table and then it must be used to retrieve the > publication attributes, by first going through the Techpubcombo table. > > I wrote the select to retrieve the data for the html drop down box: >technology_list = Technology.objects.all().order_by('technology') > > After the user makes a selection, the technology_id is retrieved: > technology_id = request.POST['technology_id'] >t = get_object_or_404(Technology, pk=technology_id) > > Now I need to use the technology_id to get to the publication > attributes > > This is where I'm stuck. > > I get error messages when I try to do something like: > > pub=t.techpubcombo.publications_set() I believe this would work: publications = Publication.objects.filter(techpubcombo__technology=t) Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Something is eating memory. How to track it down?
AndyB wrote: > I've got a Django app that seems to eat up a lot of memory. I posted a > message on Stack Overflow and it got a little sidetracked into a > debate about the merits of WSGI and Apache in Worker MPM mode. First thing - make sure DEBUG is set to off. If that's not the problem, Let me take a wild shoot in the dark; are you by any chance looping through a large queryset? I recently had a proces hog about 1.8 GB RAM when looping through a queryset with approx. 350k items as: for obj in Model.objects.all(): do_something(obj) I rewrote it to: objs = Model.objects.all().values_list("id", flat=True) for obj_id in objs: obj = Model.object.get(pk=obj_id) do_something(obj) ... and my RAM usage was below 30 MB at all time. > Maybe it's getting late and I deserve a nice gin and tonic... Cheers, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Something is eating memory. How to track it down?
Alex Gaynor wrote: >> I recently had a proces hog about 1.8 GB RAM when looping through a >> queryset with approx. 350k items as: >> >> for obj in Model.objects.all(): >> do_something(obj) >> >> I rewrote it to: >> >> objs = Model.objects.all().values_list("id", flat=True) >> for obj_id in objs: >> obj = Model.object.get(pk=obj_id) >> do_something(obj) >> >> ... and my RAM usage was below 30 MB at all time. >> > > You also executed 350k SQL queries. A better idea would be to start with: Well, that in itself shouldn't cause that much RAM usage - just longer execution time. My guess, without looking at the queryset implementation, is that they cache earlier, passed by items. > for obj in Model.objects.all().iterator(): >do_something(obj) Thank you. I didn't know about that function. That is certainly prettier than my "hack" :) I assumed that was the default behaviour when iterating. There shouldn't be any need to cache previous items, as there (to my knowledge).is no way to retrieve previous items from a python iterator. Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Fieldlookup: NOT
Thomas Guettler wrote: > Hi, > > > For forms which display a list of results I use: > form=QueryForm(request.GET) > > queryset=MyModel.objects.filter(**form.cleaned_data) > > But, now I need to use exclude() instead of filter(). > > > I looked at the queryset API, but it seems that there is no > alternative to qs.exclude(). What's wrong with exclude() as it is now? -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Email error reporting not working
Rex wrote: > Hi, > > I am having trouble getting error reporting via email to work (as > described here http://docs.djangoproject.com/en/dev/howto/error-reporting/ > ). When I hit a 500 error, no email reaches the admin's inbox. > > Here is what I have done: > - I set DEBUG to False > - I defined an Admin user and entered my email address > - I ensured that Postfix is installed and running > > Is there anything else I need to do? I will gladly provide any extra > information to troubleshoot this. Does postfix receive the e-mail? Check the mail.log. -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: Discovering the ip/port in use by runserver
tow wrote: > I know it uses whatever I specified. What I'm asking is, inside the > django process, is it possible to find out what I specified? > > ie, if I did "./manage.py runserver" - how do I find out, from a view > inside the django process, that I'm running on localhost:8000? > > if I did './manage.py runserver other.ip.address:", how do I find > out, from a view inside the django process, that I'm running on > some.other.ip.address:? > > Clearly I know what I did, I'm wondering if I can get a view inside > the django process to know what I did. You could probably just read it from sys.argv ;) /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ 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: prettier html
Carl Karsten wrote: > nicely formated template code generates lots of CRs in the resulting html. I > am > trying to figure out how to make the html a bit easier to read. > > for instance, how can I make this: > > {% ifequal day.day day.today %} class="today"{% endifequal %}> > > Not put the CR inside the ? > > I realize i may be asking for magic, but I am thinking maybe something like > skip > the CR for lines ending with %} I used something like this once. However, you should think twice before adding it on a busy site. from BeautifulSoup import BeautifulSoup class BeautifulSoupPrettifyMiddleware(object): def process_response(self, request, response): if 'text/html' in response['Content-Type']: soup = BeautifulSoup(response.content) response.content = soup.prettify() return response -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Defining your own fields for newforms
Hi I am working on defining my own CurrencyField for newforms. The idea is to store the value (amount) in the DB by the smallest unit as an IntegerField. That is: 1,450.75 => 145075 The clean method will happily clean the incoming strings into the right amount formatted as an integer: In [2]: f = CurrencyField() In [3]: f.clean("1,450.75") Out[3]: 145075 My problem is when I need to present a bound form to the user. I do a check to see if the value to be cleaned is some sort of int. If so - I convert it to my special value, CurrencyValue. As I read the source, the widget will apply smart_unicode (from django.newforms.util) to the value given, thus I implemented a __unicode__ method in CurrencyValue (and had it extend StrAndUnicode (from django.newforms.util)). However it seems as the data attribute of the BoundField gives me a raw python int: In [30]: bf = BoundField(f, field, 'price') In [31]: unicode(bf) Out[31]: u'' In [32]: bf.data Out[32]: 1495 In [33]: type(bf.data) Out[33]: I can see (by inserting some print-commands in the clean() method) that the clean() method has been activated - and indeed returns at line 43. Looking at my code - I can't see how the clean() method should be able to return an int? It will return either a CurrencyValue or None. In short - why doesn't Out[31] give me value="14.95"? Am I solving this problem the wrong way? I realize that this is a little complicated, so please let my know if I can clearify anything ;) The source code for CurrencyValue and CurrencyField is here: http://dpaste.com/14508/ Thank you, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Defining your own fields for newforms
John Shaffer wrote: > I see you're using a recent trunk checkout. Why not use models.DecimalField, > newforms.DecimalField, and the Python decimal module? They will accurately > handle your data with much less effort. As long as i can be sure that it will never fall back to some sort of float representation incurring precision loss - that would work fine. Reading the django source code, it seems pgsql and sqlite (which we use in our environments) are both safe. Both uses NUMERIC which as far as I can see should be arbitrary precision. However, the sqlite manual is a little onclear on that issue. I'll go with the DecimalField. Thank you, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Flash Message template tag
rtconner wrote: > Oh yeah I also wrote a FlashMsgMiddleware that makes this even easier. > It's not needed at all, but it'll save you a line of code here and > there. I can't post it if anyone wants it. Why not just post it to http://www.djangosnippets.org ? :) -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Making the django documentation available from the admin documentation site
Hello I was wondering if the idea of including the ./docs part of the django source in the installed django module has ever come up before? This way you could get the documentation part of the admin to render the django documentation together with your application documentation. This would be great when you're developing on the road without a fast internet connection. I don't think it would be that difficult to implement once the django documentation text files are in place as part of the installed django module somewhere. One problem would be that it isn't very nice to store the text files in the python package path (/usr/lib/python2.4/site-packages). But on the other hand - django.contrib.admin already has it's media stored there. Does python/setuptools have a special place for storing external documentation for python modules? Like in /usr/(local/)share/doc/python or something? If anyone else has not done this before, I could start working with getting it integrated by getting the user to do a `svn export` of the docs to somewhere before firing up the admin :) Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Making the django documentation available from the admin documentation site
David Reynolds wrote: > Christian, > > SmileyChris has a rather cunning application that does just that: > > http://smileychris.tactful.co.nz/ramblings/django-documentation/ > Great, thanks. :) Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Running django+apache on my macbook
John M wrote: > OK, > > So I know Linux / Apache pretty well, never really done any hard-core > stuff with it. Now I want to use apache on my macbook (intel) OSx > 10.5 (upgrade),but have no clue about how to do it. > > Googling for how to install mod_python results in a lot of issues from > what I can find, 64bit vs 32bit, etc. > > So my question is, whats the easiest way to just get my macbook intel > 10.5 to run apache and Django. You don't really need Apache and mod_python for developing Django, just use the built-in webserver. Take a look here: http://www.djangoproject.com/documentation/install/ Note the first paragraph of "Install Apache and mod_python". Developing your applications under mod_python is quite a hassle IMO. Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: approach on newforms fields for foreign key that can be selected or created
Dan Conner wrote: [...] > Any thoughts on a good approach, or link to examples? I have a draft text on my blog that i was working on some time ago. Maybe you can get inspired: http://www.technobabble.dk/2008/jan/06/filtering-foreign-key-choices-newforms-admin/ Maybe I should test it against the current nfa-branch and finish it off some day ;-) Regards, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: A twist on cross importing models
Christopher Mutel wrote: > Hello all- > > I have tried a couple of tips found on the list to solve my problem > with circular model imports, but with no lucks. Here is my basic > schema: > > #foo/models.py > > from bar.models import Formula > > class Variable(models.Model): > amount = models.FloatField(null=True) > is_formula = models.BooleanField(default=False) > formula = models.OneToOneField(Formula, null=True, > related_name="variable_formula") > > def get_amount(self): > if self.is_formula: > return self.formula.evaluate() > else: > return self.amount > > #bar/models.py > > from foo.models import Variable > > class Formula(models.Model): > formula = models.TextField() # Where formula is a text string like > 'var:1337*var:42', and the numbers are id numbers. > > def calculate(self): > # re stuff > for each_found_variable in groups(): # Simplified to show process > - this obviously doesn't work. > raw_string.append(Variable.objects.get(id=this_id).get_amount()) > return eval(raw_string, stuff_to_make_eval_safe) > > In this case, the circular reference occurs only in a method of the > class - I don't know if this makes a difference. How can I structure > my import statements so that this is possible? I should note that > there are more than one variable, so that combining everything into > one models file is not really possible (and doesn't really address the > chicken/egg problem either). It occurs at import time. When you do from bar.models import Formula bar.models is interpreted which then does from foo.models import Variable and you're stuck. You need to import the model files as modules. That is, you need to do `import foo.models` in bar/models.py and `import bar.models` in foo/models.py. Then you should be able to do `foo.models.Variable.objects...`. HTH, Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: A twist on cross importing models
Matthias Kestenholz wrote: > I can think of two methods of loading Variable inside your calculate > function: > > - Write the import statement in the function instead of writing it at > the top of the module. You may only use module level imports* out off the main scope. And then you could just as well import it at the top of the file as you would otherwise. * that is, `import ...` not `from ... import ...`. /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: IndexError instead of DoesNotExist with filter( )[0]
Viktor Nagy wrote: > Hi, > > I have the following code in my views.py > ... > try: > q = models.Queue.objects.filter(type=type, status=0)[0] > except models.Queue.DoesNotExist: > return WebAPIResponseError(request, DOES_NOT_EXIST) .filter() always returns a queryset. Methods on querysets that return new querysets never raises DoesNotExist. See which methods that returns what on: http://www.djangoproject.com/documentation/db-api/ /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache file permission, wont let me edit file
slix wrote: > i try to edit httpd.conf file by adding > LoadModule python_module modules/mod_python.so > > but it wont let me. how do i change the file permissions to do this? > also is there some security issues here i should consider? You probably need administrative rights (root access) for that. So use sudo og su if you have that kind of access. Else you need to contact your administrator and have her do the updates for you. Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to a record to a ManyToMany Table?
Greg wrote: > Hello, > I'm trying to add a record to a ManyToMany table in a script. Use obj.m2mfield.add(related_obj). /Christian -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ASP.Net GridView Equivalent in Django
Ian wrote: > I am .Net developer looking to switch over to Python. > > I have started looking at Django and was wondering if there is a > widget equivalent to ASP.Net's GridView in terms of richness of > functionality. What does ASP.Net's GridView do? Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Add db tables on-the-fly
MickaelC wrote: > Hi, > It is a method to add tables to a model without having to manually > launch the syncdb command in a shell? > > If yes > can you give me tips ? > else > :-( What problem are you trying to solve? This really doesn't sound like a common Django idiom. If you insist, you could probably do (using 0.96): from django.core.management import syncdb syncdb() Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How do I add the user ID to a template?
Huuuze wrote: > A n00b question for everyone: My base template has a "Welcome > " section in it. Currently, I'm adding the username (which > is coming from Django's auth/auth framework) to the template with the > following bit of code: > > {{ request.session.user.username }} > > This works, however, it requires me to add the "request" object to any > return statement that deals with displaying a page: > > return render_to_response('somepage.html', {'request':request}) > > I'm guessing there's a better way to do this, but I can't seem to find > an answer. Help! Use the RequestContext: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: psycopg2
Will wrote: >> You're not asking it to do a whole hell of a lot. > > In terms of security, perhaps this is the most critical part of the > stack? SQL injection is one of the nastiest security vulnerabilities > IMHO. The problem with SQL injections shouldn't IMHO be solved at driver level, but is an application level problem. Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can anyone explain this?
Lars Wessman wrote: > While this probably has to do with the setup of my machine, I wonder > if anyone has seen this before (I am using Postgesql 7.4.13 and > psycopg2): > > mydir# python manage.py syncdb > Loading 'initial_data' fixtures... > Traceback (most recent call last): > File "manage.py", line 11, in ? > execute_manager(settings) > File "/usr/lib/python2.3/site-packages/django/core/management.py", > line 1665, in execute_manager > execute_from_command_line(action_mapping, argv) > File "/usr/lib/python2.3/site-packages/django/core/management.py", > line 1564, in execute_from_command_line > action_mapping[action](int(options.verbosity), > options.interactive) > File "/usr/lib/python2.3/site-packages/django/core/management.py", > line 590, in syncdb > load_data(['initial_data'], verbosity=verbosity) > File "/usr/lib/python2.3/site-packages/django/core/management.py", > line 1358, in load_data > fixture_name, format = fixture_label.rsplit('.', 1) > AttributeError: 'str' object has no attribute 'rsplit' > mydir# python > Python 2.3.4 (#1, Mar 10 2006, 06:12:09) > [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> dir(str) > ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', > '__eq__', '__ge__', '__getattribute__', '__getitem__', > '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', > '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', > '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', > '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', > 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', > 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', > 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', > 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith', > 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] rsplit is a function of python 2.4. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Newforms and CSS classes
Hi Is it possible to have css classes attached to newforms widgets? I would like to be able to distinguish between fx. checkboxes, radio buttons, submit buttons, text fields (which are all 's). In the oldforms module when having a required charfield, there would be a class="vTextField required" to make CSS styling easier. Am I overlooking something, or is newforms missing this? -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Newforms and CSS classes
Honza Král wrote: >> Is it possible to have css classes attached to newforms widgets? I would >> like to be able to distinguish between fx. checkboxes, radio buttons, >> submit buttons, text fields (which are all 's). > well, you can pass args={'class' : 'whatever'} to the widget's __init__() > or you could subclass the widget and do that inside This does (IMHO) not comply very much with the DRY philosophy of django. > but there is currently no class set globally for all widgets > >> In the oldforms module when having a required charfield, there would be >> a class="vTextField required" to make CSS styling easier. >> >> Am I overlooking something, or is newforms missing this? I was able to hack newforms by adding this in the __init__ of Field: # Attach field + widget type css classes self.css_class = type(self).__name__ + " " + type(widget).__name__ # Add an extra class, Required, if applicable if self.required: self.css_class += " Required" Furthermore, to handle the output, I edited the _html_output of BaseForm and added an extra item in the formatting dict: 'class': field.css_class At last I updated the output functions (as_table, as_ul and as_p) to have a 'class="%(class)s"'. All this results in the following HTML structure for a required CharField with a (default) TextInput widget: CharField: Just thought I would mention my solution if anyone else is interested ;) Also, please let me know if anyone else have an easier solution to this. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Newforms and CSS classes
Christian Joergensen wrote: >>> Is it possible to have css classes attached to newforms widgets? I would >>> like to be able to distinguish between fx. checkboxes, radio buttons, >>> submit buttons, text fields (which are all 's). > >> well, you can pass args={'class' : 'whatever'} to the widget's __init__() >> or you could subclass the widget and do that inside > > This does (IMHO) not comply very much with the DRY philosophy of django. > >> but there is currently no class set globally for all widgets >> >>> In the oldforms module when having a required charfield, there would be >>> a class="vTextField required" to make CSS styling easier. >>> >>> Am I overlooking something, or is newforms missing this? > > I was able to hack newforms by adding this in the __init__ of Field: I actually went a little further and hacked an extension for newforms to accomplish this. Furthermore it will allow for layout definitions using fieldsets and YUI grids: http://www.djangosnippets.org/snippets/214/ An example using a fieldset and two columns: class MyForm(WTForm): name1 = forms.CharField(label="Name (1)") email1 = forms.EmailField(label="E-mail address (1)") name2 = forms.CharField(label="Name (2)") email2 = forms.EmailField(label="E-mail address (2)") class Meta: layout = (Fieldset("Person details", Columns(("name1", "name2"), ("email1", "email2"))),) This will result in the form layout of: +-[ Person details ]--+ |+-+-+| || Name (1)| E-mail address (1) || || [_] | [_] || || | || || Name (2) | E-mail address (2) || || [_] | [_] || |+-+-+| +-+ -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Creating link to root
Florian Lindner wrote: > Hello, > a common problem I have is that I have references in my main template like > CSS > or an background image: > > > > This template is used within different paths. Therefore I need to have the > styles.css availabe in every path the template could be used. Couldn't you just do href="/styles.css" ? -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: cronjob
patrickk wrote: > I just tried to set up a cronjob with plesk and I got this error: > > from: can't read /var/mail/django.core.management > /var/www/vhosts/mydomain.at/www/scripts/cronjobs/mail_editors.py: line > 4: import: command not found > /var/www/vhosts/mydomain.at/www/scripts/cronjobs/mail_editors.py: line > 5: syntax error near unexpected token `settings' > /var/www/vhosts/mydomain.at/www/scripts/cronjobs/mail_editors.py: line > 5: `setup_environ(settings)' > > Here´s the test-script: > > # coding: utf-8 You're missing the shebang line: #!/usr/bin/python -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: How to define choices that works in admin interface?
David Marko wrote: > How to define choices for filed that works in admin interface? When I > define CharField as below, the list of choices is computed intially > and doesn't refresh when data changes in Choices table. > > type = models.CharField(verbose_name='Type', maxlength=30, choices = > Choice.filter(""), null=False, blank=False) Normally, one would use a foreign key in this case: choice = models.ForeignKey(Choice) Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Forms and .META
Matt Davies wrote: > Hello everyone > > I've got a views.py in my forms application that emails form data off to > another department. > > It's a bookign form for events that appears on the events details page. > > www.bongo.com/events/EVENTSLUG > > The form is displayed in a template and is on our web site, works a treat. > > I've also got a forms.py in the application, in which we define the contents > of the forms in classes. > > eg. > > class TrainingEventForm(Form): > """A form for email bookings of training events""" > firstname = CharField() > surname = CharField() > username = CharField() > > I need to be able to pull out the EVENTSLUG from the referring URL in the > form in order to only select the event that has that slug. > > I know how to do it in a view with request.META, but I'm in a form now, > there is no request and Form does not have an object type of META. > > Anyone got any ideas how to pull that data out of the reffering URL? Or > even a better suggestion on how to accomplish this. Shouldn't you just have an entry like this in your urls.py: (r'^events/(?P[^/]+)', 'project.application.views.view') And in your view collect the slug and look it up: def view(request, slug): s = get_object_or_404(Event, slug__exact=slug) I don't understand why you are talking about forms here :) -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: New user having trouble with First View
newDjangoer wrote: > Hello, > > I am a new user to Django and developing apps at that. I ran the > server successfully . Once I created the "First View" tutorial > (datetime page17) in the book and changed the settings.py and urls.py, > I get the following: [...] > Exception Type: SyntaxError > Exception Value: invalid syntax (views.py, line 6) What's on that line? -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Choices from table vs. Foreign Key relationship.
radioflyer wrote: > So the recommendation seems to be when your selection choices are not > static you should go ahead and use a Foreign Key relationship. You get > the automatic loading of the table into a select widget etc. > > But there's this issue of the cascade on delete. > > I have a Student model with a Foreign Key relationship to Teacher. > When a teacher is removed, so go the students. Too dangerous for my > particular scenario. There doesn't seem to be a Django feature that > allows for adjusting the cascade. > > I thought to uncouple the relationship and use the Teacher model > strictly as a 'lookup table.' > > What are best practices on this? What will I be losing if I just load > the teachers as 'choices' on the student forms? Is it worth creating > my own cascade protection to keep the Foreign Key relationship? Don't delete the Teacher. Instead, I would add a boolean field 'active' to the model and change the value on delete. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Filtering on the existance of a "reverse" foreign key relationsship
Hello To understand the problem, assume I have a model consisting of Country and SoccerTeam. The SoccerTeam has a country = models.ForeignKey(Country). Say, I need to find the countries having one or more related soccer teams. I was not able to come up with a solution using the ORM, but got to this using a list comprehension: clist = [c for c in Country.objects.order_by('name') if len(c.soccerteam_set.all()) > 0] This is slow as hell. Understandable, as I have 213 countries and 4161 soccer teams in my test data. I believe this could be done quite a lot faster using SQL. Do I really need to use custom SQL here, or does the django ORM provide the means to solve this problem? Thanks, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Filtering on the existance of a "reverse" foreign key relationsship
Jonathan Buchanan wrote: >> To understand the problem, assume I have a model consisting of Country >> and SoccerTeam. >> >> The SoccerTeam has a country = models.ForeignKey(Country). >> >> Say, I need to find the countries having one or more related soccer >> teams. I was not able to come up with a solution using the ORM... >> >> ...Do I really need to use custom SQL here, or does the django ORM provide >> the means to solve this problem? > > You could use QuerySet's "extra" method to add the custom SQL > required, which might be something like the following in this case > (you'd need to replace "appname" with the name of the application the > models belong to, of course): > > Country.objects.all().extra( > where=['(SELECT COUNT(*) FROM appname_soccerteam WHERE > appname_soccerteam.country_id = appname_country.id) > 0'] > ) Great idea! I did not think about the 'extra' method. Works perfectly. Gave me a speedup factor of about 250k :) Thanks, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Filtering on the existance of a "reverse" foreign key relationsship
Daniel Roseman wrote: >>> Country.objects.all().extra( >>> where=['(SELECT COUNT(*) FROM appname_soccerteam WHERE >>> appname_soccerteam.country_id = appname_country.id) > 0'] >>> ) >> Great idea! I did not think about the 'extra' method. Works perfectly. >> Gave me a speedup factor of about 250k :) >> >> Thanks, > > Alternatively you could use the normal django syntax: > Country.objects.filter(soccerteam__name__isnull=False) But the thing is, I can have multiple SoccerTeam relations. Doesn't that rule out this solution? -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Filtering on the existance of a "reverse" foreign key relationsship
[EMAIL PROTECTED] wrote: > This is already in the api, no need to write extra sql, try: > > c.soccerteam_set.count() > > http://www.djangoproject.com/documentation/db_api/#backward I know of the FOO_set-property, but I need to use it as a filter condition. As far as my Django experience goes, this isn't possible. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: caching views with dynamic parameters
Christian Joergensen wrote: > You could do a simple: > > def my_view(request): > return render_my_view(request, request.session.LANGUAGE_CODE) > > def render_my_view(request, language_code): > # do stuff > > render_my_view = cache_page(render_my_view, cache_time) Reading Jeremy's discovery, this will not work. I naturally assumed the cache generated the key from the arguments. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to tell if django is running from apache or standalone?
sandro.dentella wrote: > Hi all, > > how can I test from within settings.py if I'm running via mod_python > or in standalone way? I need to set a variable, accordingly. You could import os and look in os.environ for differences. Maybe somthing differs. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: cannot update model in view
Kenneth Gonsalves wrote: hi i have a model which has a unicode string in one field. In admin I can save and update the model. In my view, using custom manipulators i can create new models using model.objects.create. But when i try to update and save the model in a view, I get a ProgrammingError. But the error message does not specify what the programming error is. Just says 'current transaction is aborted, commands ignored until end of transaction block SET TIME ZONE 'Asia/Calcutta'. On looking at the traceback i get in I have seen this before. I believe the thing is that your database driver does not support unicode. Try to encode it to something. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How can i specify rows and cols in a TextField()?
Fabio Gomes wrote: I m liked the simplicity of generic views, but i can´t find a way to set up how many rows and cols my textarea have, is there a way to do it? I believe you can style them using CSS. Please correct me if i am wrong. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Dynamically adding fields to a database model class
Hey I am trying to save myself some time and use a bit of setattr magic[1] on my models. However when I do that, and later need to fetch the value of the field, I get (insted of the actual value): I suspect there is some django magic happening behind the scenes, and maybe the setattr trick is not at all possible. Can anyone shed some light on this? Thank you! [1] Like: setattr(MyModel, 'foo', models.IntegerField()) -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Dynamically adding fields to a database model class
Russell Keith-Magee wrote: > On 1/20/07, Christian Joergensen <[EMAIL PROTECTED]> wrote: >> I suspect there is some django magic happening behind the scenes, and >> maybe the setattr trick is not at all possible. Can anyone shed some >> light on this? > > Yes - the model class has a metaclass that is used to convert the > member fields in the model declaration and turns them into attributes. Thank you, this was exactly the pointer i needed. If anyone in the future encounters a similar problem, my solution was: MyModel.add_to_class('foo', models.IntegerField()) Instead of: setattr(MyModel, 'foo', models.IntegerField()) This doesn't seem to cause any problems (yet!). > It's not 'magic' - just python metaclasses - and it's call contained > in django.db.models.base In my book of python, this still count as magic ;-) Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Re: Syntax error with render_to_response call
Tipan wrote: > def codeview(request): > manipulator = CodeViewManipulator() > if request.method == 'POST': > new_data = request.POST.copy() > errors = manipulator.get_validation_errors(new_data) > if not errors: > > return HttpResponseRedirect("/hive/codeoutput/") > else: > errors = new_data = {} > code_list=CodeTest.objects.all() > return render_to_response('codeview.html', {'code_list':code_list}) > > This always generates a Django Syntax Error on the return > render_to_response line. I can define a new view with just the last two > lines and it works fine. The function also runs if I substitute a > return HttpResponse line instead of the render_to_response, but then it > won't display my html template page. > > Is there some ruling preventing me from using render_to_response in > this way? > > Any advice welcome - it's driving me crazy! Could it be a case of tab vs. spaces indentation? What more that Syntax Error does the django error page tell you? -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info signature.asc Description: OpenPGP digital signature
Signals and model instances with deferred attributes
Hello, I am experiencing an inconvenience in regards to working with signals on model instances with deferred attributes. Specifically I am trying to get a post_save signal to fire from a save() call on such a model instance. The problem is that the sender class (`origin` in django.db.models.base.ModelBase.save_base) will be the special deferred class as returned by django.db.models.query_utils.deferred_class_factory and not the actual model class. Thus a subscription to post_save on the real model class will not receive the signal signaled by the deferred class. An obvious workaround would be to just override the save() method. If however this behavior is intentional, I think this should be at least noted in the documentation (on the defer() method) to save others wasting time on debugging why their signals doesn't fire. Regards, Christian -- 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.