Re: ReportLab and Django - templates? ; FK object has no attribute split
There is also template2pdf which is basically and RML subset interpreter, you write your RML from a django template and pass it to a function from template2pdf which will generate a PDF from it. http://code.google.com/p/template2pdf/ That is what we are using, I have even contributed a few patches. On Thu, Nov 18, 2010 at 8:22 PM, Javier Guerra Giraldez wrote: > On Thu, Nov 18, 2010 at 6:08 PM, Victor Hooi wrote: >> But yeah, I'd still love if there was a separate template I could use >> to generate the PDF. It just feels very weird building up the PDF line >> by line in views.py. > > the obvious answer is "write your own"; but it doesn't have to be a > full-fledged templating language capable of creating any PDF > imaginable. just what you need. > > IOW: write a simple function for each PDF format you need, with the > data as parameters, and a file-like object to write on. if you wish, > you can make it very non-django, the data input could be any python > sequence of data objects, that way you can feed it a list of > dictionaries, or a django queryset (handy for testcases). > > then your Django views can be almost as usual: get parameters from the > request, data from the database, filter and preprocess all you need, > and feed to the relevant PDF format function. > > that way you get the same content/presentation separation, even if the > presentation is written in procedural python instead of descriptive > templates. > > -- > Javier > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django-admin.py not functional on 64 bit Vista
Hi Micheal, Pretty sure it has nothing to do with your version of windows. appended MS-DOS PATH: with "C:\hp\bin\Python\Lib\site-packages \django \bin" which allows me to run django-admin.py If you have installed Python and django propely, there is no need to append anything. It should work straight out the box. I'm thinking you disabled Django-admin.py by setting the environmental varible for DJANGO_SETTINGS_MODULE. Try unsetting it to see if that works. Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Uploads outside of a form
I am trying to use Valum's Ajax Upload to do file uploads on a Django- based site I am making. Currently I am avoiding a form simply because AU sends the upload as the entirety of the POST data in an ajax request. Right now I have a very naive approach to doing this: upload = SimpleUploadedFile( filename, request.raw_post_data ) This works great... on small files. I've tested with PDFs, various other files, and up to the ~20MB Google Chrome deb package and they all do great. However, if I move up to something like a CD or DVD iso it bombs horribly. Often Django sends back an Out of Memory response. On the surface this makes sense since SimpleUploadedFile is an in-memory version of the upload classes. I cannot see how to use TemporaryUploadedFile because it does not take actual content in its constructor. As a side note: I would think after using up the available RAM it would go to virtual memory, but whatever. So, my question is, how do I get this to work? Is there a better way to read in the file? I tried directly reading the raw_post_data via Python's IO (system uses 2.6.5) but FileIO's ascii encoder/decoder will obviously complain about non-ascii characters when working with binary files. I have not been able to find info on changing the encoder/decoder. I wouldn't mind passing the data into a form and having Django do the work of picking the right upload class and so on, but I cannot figure out how to pass it because something like upload_form = UploadForm( request.POST, request.FILES ) will not work because the POST contains the file and not the normal Django info and FILES does not exist. As I said, I'm not worried about the method of the solution, just that I get something that works! Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
forloop.last FAIL in template.
Hi everyone, I have a template where Django is spitting out blog tags followed by a ',' when the tag is not the final one in the loop. {% if not forloop.last %}, {% endif %} Strangely, I am still seeing tag1, tag2, tag3,. How can I suppress that last ','? -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Where is everything on ubuntu 10.10
Read up on how linux programs work the file system becomes intuitive. Also try this: python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" cheers sam_w On Fri, Nov 19, 2010 at 3:08 AM, Kenneth Gonsalves wrote: > On Thu, 2010-11-18 at 06:10 -0800, sheeptick wrote: >> The site-packages directory is empty, so where did django go? > > ubuntu guys have something called dist-packages > -- > regards > Kenneth Gonsalves > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Need help using ExtJS in Django
On 19 nov, 07:23, codingJoe wrote: > Newbie question here... I know the basics of Django and nothing of > ExtJS. I am running a simple web framework and I want to integrate > ExtJS Grid into it. > > My first step was to run the example grid from extjs. "Yay!! It > works" > > Then I wanted to render that same working example inside my django > app. here's what I did. > 1. Put the extjs3.0.0 directory structure under my 'app/static' > directory > 2. Made sure that each of these loads based on the same calls in > extjs package (No 404's) > 3. Render the grid. This part simply won't work and I'm not sure > what to do next? > > The point of confusion is in array-grid.html: div> > I see where array-grid.js is supposed to render that. But it just > isn't happening and I'm strugging to figure out why. > > Any advice to help me work through this problem? >From what you describe and if you're 100% positive about 2., then this has nothing to do with Django itself. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: forloop.last FAIL in template.
On 19 nov, 11:09, Sithembewena Lloyd Dube wrote: > Hi everyone, > > I have a template where Django is spitting out blog tags followed by a ',' > when the tag is not the final one in the loop. > > {% if not forloop.last %}, {% endif %} > > Strangely, I am still seeing tag1, tag2, tag3, This shouldn't happen, but since such an obvious bug would have been spotted long ago, I guess you do have an "empty" element (for whatever definition of "empty" apply here) at the end of your list or queryset. So better to first check your data... > -- > Regards, > Sithembewena Lloyd Dubehttp://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using foreignkey data as a primary key
Thanks for the replies. I simplified the problem a bit by deciding it will be easier to have some extra validation code in a separate admin view to do what I need it to and removed the CurrentTag table, similar to what Rainy has said. On Nov 18, 4:59 pm, Rainy wrote: > On Nov 18, 9:04 am, JE wrote: > > > Hi, > > > I'm pretty new to Django so feel free to laugh if something's > > horrendously wrong here that I haven't spotted. > > > I'm trying to use a field from a foreign key as a primary key in > > another model, but have no idea how to do this. > > The idea is to have a table called Tag (columns called tagname and > > tagversion, which create a composite primary key using the > > unique_together option in the metadata). > > Why not just have a boolean column 'current' or 'active' > in Tag model, instead of a separate table? On save, > if it's changed inactive->active, all other tags are set > to be inactive. -ak -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: forloop.last FAIL in template.
Hi Bruno, Thanks for the idea! I checked my data and nothing seems out of the ordinary. truly stumps me. Regards On Fri, Nov 19, 2010 at 12:51 PM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > > > On 19 nov, 11:09, Sithembewena Lloyd Dube wrote: > > Hi everyone, > > > > I have a template where Django is spitting out blog tags followed by a > ',' > > when the tag is not the final one in the loop. > > > > {% if not forloop.last %}, {% endif %} > > > > Strangely, I am still seeing tag1, tag2, tag3, > > This shouldn't happen, but since such an obvious bug would have been > spotted long ago, I guess you do have an "empty" element (for whatever > definition of "empty" apply here) at the end of your list or queryset. > So better to first check your data... > > > > > > > > > -- > > Regards, > > Sithembewena Lloyd Dubehttp://www.lloyddube.com > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Dropdown List
Sean I hear what you say - but is this approach also readily available inside the Admin framework? Derek On 16 November 2010 16:20, Shawn Milochik wrote: > On Tue, Nov 16, 2010 at 9:08 AM, derek wrote: > > " you'll have to have all the states/provinces as 'choices' in the > > ChoiceField in the form, otherwise the form won't validate." > > > > Yup, this is a "real" gotcha. IMO, its not really true filtering if > > you take this approach, as the initial form will still load the X > > million items, even though the user will only be shown a fraction at a > > time. > > > > While this is the case, there's no reason you can't just accept and > validate the input yourself, and not make use of a Django forms.Form. > It's annoying, but nothing compared to writing, say, PHP or ASP > without a framework. > > Hmmm. I think I'll search the tickets and see if some kind of "choices > = any" proposal has been made already. > > Shawn > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: forloop.last FAIL in template.
Bruno, you were absolutely right - the "last" tag in my loop wasn't really the last. I had this: for tag in tags_list: tag.blogs_count = tag.blogpost_set.count() So, each tag would get a blog count, and some tags had zero blogs. In the template, I was only writing out those tags that had a blog count above zero, yet the loop would iterate over the rest of the tags and not write them out. I did a small fix in my views as follows: for tag in tags_list: tag.blogs_count = tag.blogpost_set.count() clean_tags = [] for tag in tags_list: if tag.blogs_count != 0: clean_tags.append(tag) tags_list = clean_tags I am now passing a list of only those tags with a blog count greater than nought. Thanks! On Fri, Nov 19, 2010 at 12:51 PM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > > > On 19 nov, 11:09, Sithembewena Lloyd Dube wrote: > > Hi everyone, > > > > I have a template where Django is spitting out blog tags followed by a > ',' > > when the tag is not the final one in the loop. > > > > {% if not forloop.last %}, {% endif %} > > > > Strangely, I am still seeing tag1, tag2, tag3, > > This shouldn't happen, but since such an obvious bug would have been > spotted long ago, I guess you do have an "empty" element (for whatever > definition of "empty" apply here) at the end of your list or queryset. > So better to first check your data... > > > > > > > > > -- > > Regards, > > Sithembewena Lloyd Dubehttp://www.lloyddube.com > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: forloop.last FAIL in template.
for tag in tags_list: tag.blogs_count = tag.blogpost_set.count() clean_tags = [] for tag in tags_list: if tag.blogs_count != 0: clean_tags.append(tag) tags_list = clean_tags - Just fixed that. The indentation gave the code a different meaning :). On Fri, Nov 19, 2010 at 1:37 PM, Sithembewena Lloyd Dube wrote: > Bruno, you were absolutely right - the "last" tag in my loop wasn't really > the last. I had this: > > for tag in tags_list: > tag.blogs_count = tag.blogpost_set.count() > > So, each tag would get a blog count, and some tags had zero blogs. In the > template, I was only writing out those tags that had a blog count above > zero, yet the loop would iterate over the rest of the tags and not write > them out. > > I did a small fix in my views as follows: > > for tag in tags_list: > tag.blogs_count = tag.blogpost_set.count() > > clean_tags = [] > for tag in tags_list: >if tag.blogs_count != 0: > clean_tags.append(tag) > > tags_list = clean_tags > > I am now passing a list of only those tags with a blog count greater than > nought. > > Thanks! > > On Fri, Nov 19, 2010 at 12:51 PM, bruno desthuilliers < > bruno.desthuilli...@gmail.com> wrote: > >> >> >> On 19 nov, 11:09, Sithembewena Lloyd Dube wrote: >> > Hi everyone, >> > >> > I have a template where Django is spitting out blog tags followed by a >> ',' >> > when the tag is not the final one in the loop. >> > >> > {% if not forloop.last %}, {% endif %} >> > >> > Strangely, I am still seeing tag1, tag2, tag3, >> >> This shouldn't happen, but since such an obvious bug would have been >> spotted long ago, I guess you do have an "empty" element (for whatever >> definition of "empty" apply here) at the end of your list or queryset. >> So better to first check your data... >> >> >> >> >> >> >> >> > -- >> > Regards, >> > Sithembewena Lloyd Dubehttp://www.lloyddube.com >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com >> . >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> >> > > > -- > Regards, > Sithembewena Lloyd Dube > http://www.lloyddube.com > -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
django charts
Hi, I am a new user to django ,can anybody please help me resolve this issue.I am trying to construct a Gant chart based on the certain constraints.Now i am unable to make a line of approach for this.I have defined a class for chart and defined function for it in views.Now how do i pass my values to the gant chart . So the idea is..i have n number of task who have deadlines.So i want to show thiese tasks thru a gant chart and then want to show a pie chart giving the perfomance eg. 4% work done til so and so date. Can anybody help me with the coding of all these. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
fieldsets not working in admin
Hi, playing around with the django tutorial part 2. The fieldsets example does not work at all for me. I don't see the fieldsets. No error displayed. Anyone had this? Using ubuntu 10.04 and django 1.2.3 installed with easy_install not Synaptic. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
auth user permissions
I have forgotten something here, added a model to a site, restarted the server but the add/change/delete permission set is not showing in the auth-user add permission set, what is it I have forgotten please? -- View this message in context: http://old.nabble.com/auth-user-permissions-tp30257316p30257316.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: fieldsets not working in admin
Bah stupid me. Use admin.site.register(Poll, PollAdmin) not just admin.site.register(Poll). Sorry ... On Nov 19, 10:26 am, Reikje wrote: > Hi, playing around with the django tutorial part 2. The fieldsets > example does not work at all for me. I don't see the fieldsets. No > error displayed. Anyone had this? Using ubuntu 10.04 and django 1.2.3 > installed with easy_install not Synaptic. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
filefield and utf-8, rev12661 and filefield.size
with rev 12661, storage.py has been changed and return smart_str(os.path.normpath(path)) has been replaced with return os.path.normpath(path) now, when trying to upload a filefield (or displaying the size of a filefield), we get this error: Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode character u'\xc4' in position 59: ordinal not in range(128) return os.stat(filename).st_size (/usr/lib/python2.5/posixpath.py in getsize) with our setup (apache/mod_wsgi), LANG is set to en_US.UTF-8 (LC_ALL is not set) ... unfortunately, this doesn´t solve the problem: http://code.djangoproject.com/ticket/11030#comment:5 http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror I´ve been doing quite a bit of research and I´ve also discussed this issue with the people responsible for our server-setup. now they say that we need to resolve the issue and that the apache-setup is fine. besides going back to rev 12552, is there another solution? thanks, patrick -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: auth user permissions
Try running "python manage.py syncdb". Hope that helps On Nov 19, 2:00 pm, MikeKJ wrote: > I have forgotten something here, added a model to a site, restarted the > server but the add/change/delete permission set is not showing in the > auth-user add permission set, what is it I have forgotten please? > -- > View this message in > context:http://old.nabble.com/auth-user-permissions-tp30257316p30257316.html > Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: auth user permissions
Thx, knew I'd forgotten something Łukasz Balcerzak wrote: > > Try running "python manage.py syncdb". Hope that helps > > On Nov 19, 2:00 pm, MikeKJ wrote: >> I have forgotten something here, added a model to a site, restarted the >> server but the add/change/delete permission set is not showing in the >> auth-user add permission set, what is it I have forgotten please? >> -- >> View this message in >> context:http://old.nabble.com/auth-user-permissions-tp30257316p30257316.html >> Sent from the django-users mailing list archive at Nabble.com. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- View this message in context: http://old.nabble.com/auth-user-permissions-tp30257316p30257562.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
AttributeError: Model object has no attribute blah
Hi, I've been using Djangos manytomany functionality to add values into the auto generated table, here are my model classes: class Contract_Item(models.Model): quant = models.DecimalField(max_digits=10, decimal_places=4) item = models.OneToOneField(Item) class Contract(models.Model): contract_no = models.AutoField(primary_key=True) start_date = models.DateField() end_date = models.DateField() change_date = models.DateField() contract_type = models.ForeignKey(Contract_Type) comment = models.CharField(max_length=300) creno = models.ManyToManyField(Creditor) debno = models.ManyToManyField(Debtor) contract_items = models.ManyToManyField(Contract_Item) when i try to read values into the manytomany table with the following code: (new_contract is the contract object i used to read values into) new_contract = models.Contract(blah=blah) for items in i_contract_item_list: new_contract.contract_items.add(items) new_contract.save() However when i run this the following error occurs and I cant seem to find the problem: AttributeError: 'Contract' object has no attribute 'contract_items' Any help would be appreciated! Thanks, JP De Villiers -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django charts
I am not an expert on charts, but I am using highcharts.com to generate some. What I do here is: 1) get the data from the database inside the view (look for querysets on django-documentation) 2) render this data on a template 3) build the chart using this library inside the template bye, global Em 19/11/2010, às 04:56, Priya escreveu: > Hi, > I am a new user to django ,can anybody please help me resolve this > issue.I am trying to construct a Gant chart based on the certain > constraints.Now i am unable to make a line of approach for this.I have > defined a class for chart and defined function for it in views.Now how > do i pass my values to the gant chart . > So the idea is..i have n number of task who have deadlines.So i want > to show thiese tasks thru a gant chart and then want to show a pie > chart giving the perfomance eg. 4% work done til so and so date. > Can anybody help me with the coding of all these. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Variable extends tag
Hi, In the django documentation (http://docs.djangoproject.com/en/dev/topics/templates/) it says that {% extends %} tag should be the first one. Is there a way to create variable base templates? Like this: {% if is_blah %} {% extends 'base.html' %} {% else %} {% extends 'base2.html' %} {% endif %} I tried this and did not work. Thanks, global -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Nested Categories in Admin
You will need to use Javascipt: handwritten or via framework e.g. JQuery. Its been asked about before on this mailing list and numerous people have blogged on it. On Nov 16, 11:58 am, Federico Capoano wrote: > Any suggestion? > > On Nov 14, 6:15 pm, Federico Capoano wrote: > > > Hi all, > > > I would like to find a way to get categories and subcategories > > displayed in the admin, in the form of a multiple select. > > > Like: > > > parent > > child1 > > child2 > > parent2 > > child3 > > > Do I have to make a custom field or is there already a solution > > around? > > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
URL grows in address bar with each click
I've noticed a thing which is likely a symptom of something I'm doing wrong. A good example is a page I'm serving which holds a form. If there are issues with the form content, the same page is reloaded, with an updated warning message in the body of the HTML. The page is, say, addInfo.html and the urlconf for it is: (r'^moreInfo', 'myProj.app.views.goInfo'), And in my views.py I call that page again with a message def goInfo(request): ... badInfo = "That name is not in the database" return render_to_response(tempsDir +'addInfo.html', {'WarnText': badInfo }) It all works very nicely, but I've noticed that as this gets called, the URL in the address bar of the browser keeps growing with each pass: Going from http://localhost:8000/moreInfo to: http://localhost:8000/localhost:8000/moreInfo to: http://localhost:8000/localhost:8000/localhost:8000/moreInfo Similarly other urls get appended occasionally in other situations. My searching isn't turning anything up about appended URLs or growing URLs. Does someone know what causes this and how I can just make it stop growing? Regards, Ross. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: URL grows in address bar with each click
What does the "action" parameter of your HTML form contain? I'm guessing it's a relative URL. If you want it to go to the same place, you can make the action blank ("") and it will submit to the same page. Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: URL grows in address bar with each click
Aha! Thanks Shawn. I'd left a forgotten "http://localhost:8000/ moreInfo" in there. I was so hung up on Django urls.py I forgot about simple html mistakes and leftovers. Thanks for the pointer! -Ross. On Nov 19, 10:16 am, Shawn Milochik wrote: > What does the "action" parameter of your HTML form contain? I'm > guessing it's a relative URL. > > If you want it to go to the same place, you can make the action blank > ("") and it will submit to the same page. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Generic relation overflows the maximum recursion depth
I'm trying to save a model and then insert it into a generic relation. Having this models.py file: from django.db import models from datetime import datetime from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.db.models.signals import post_save STATUSCHOICE = ( ('d', 'Working draft'), ('p', 'Publish!') ) # Create your models here. class Tag(models.Model): name = models.CharField(max_length=20, unique=True) def __unicode__(self): return self.name class PostBase(models.Model): title = models.CharField(max_length=200) content = models.TextField() pub_date = models.DateTimeField() tags = models.ManyToManyField(Tag, null=True) status = models.CharField(max_length=1, choices=STATUSCHOICE) def clean(self): self.pub_date = datetime.now() class Meta: abstract = True def __unicode__(self): return self.title class Post(PostBase): pass class Review(PostBase): image = models.ImageField(upload_to="blog/upload") class BlogContent(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') class Comment(models.Model): content = models.CharField(max_length=300) pub_date = models.DateTimeField() email = models.EmailField() name = models.CharField(max_length=30) post = models.ForeignKey(Post) # Signals def post_save_callback(sender, instance, **kwargs): bc = BlogContent(content_object=instance) bc.save() post_save.connect(post_save_callback) The problem occurs when creating a Post model and saving it: p = Post(title="foobar", ) p.save() I get the following error message: RuntimeError: maximum recursion depth exceeded The problem should be located in the post_save_callback function. Kind regards, Jonas Geiregat jo...@geiregat.org -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Generic relation overflows the maximum recursion depth
On Nov 19, 3:46 pm, Jonas Geiregat wrote: > I'm trying to save a model and then insert it into a generic relation. > Having this models.py file: > > from django.db import models > from datetime import datetime > from django.conf import settings > from django.contrib.contenttypes.models import ContentType > from django.contrib.contenttypes import generic > from django.db.models.signals import post_save > > STATUSCHOICE = ( > ('d', 'Working draft'), > ('p', 'Publish!') > ) > > # Create your models here. > > class Tag(models.Model): > name = models.CharField(max_length=20, unique=True) > > def __unicode__(self): > return self.name > > class PostBase(models.Model): > title = models.CharField(max_length=200) > content = models.TextField() > pub_date = models.DateTimeField() > tags = models.ManyToManyField(Tag, null=True) > status = models.CharField(max_length=1, choices=STATUSCHOICE) > > def clean(self): > self.pub_date = datetime.now() > > class Meta: > abstract = True > > def __unicode__(self): > return self.title > > class Post(PostBase): > pass > > class Review(PostBase): > image = models.ImageField(upload_to="blog/upload") > > class BlogContent(models.Model): > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey('content_type', 'object_id') > > class Comment(models.Model): > content = models.CharField(max_length=300) > pub_date = models.DateTimeField() > email = models.EmailField() > name = models.CharField(max_length=30) > post = models.ForeignKey(Post) > > # Signals > def post_save_callback(sender, instance, **kwargs): > bc = BlogContent(content_object=instance) > bc.save() > post_save.connect(post_save_callback) > > The problem occurs when creating a Post model and saving it: > > p = Post(title="foobar", ) > p.save() > > I get the following error message: > RuntimeError: maximum recursion depth exceeded > > The problem should be located in the post_save_callback function. > > Kind regards, > > Jonas Geiregat > jo...@geiregat.org You haven't specified that your post_save callback is associated with the Post model. As a result, it's connected to *every* save - including the save of the BlogContent object that you create within the callback. Hence the infinite recursion. Do this: post_save.connect(post_save_callback, sender=Post) to associated the callback just with the Post model. -- 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Variable extends tag
extends can take a variable arg, set the variable to the base you want. {% extends base %} http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#extends -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
django_content_type integrity error on sync and loaddata
I'm trying to recreate my database and reload the data in it, using the following steps: On my app I dump data to a fixtures file with > ./manage.py dumpdata > test_fixture then drop and recreate the database then run > ./manage.py syncdb to recreate the database tables and > ./manage.py loaddata test_fixture to repopulate the database but the loaddata command fails with the folowing error: IntegrityError: duplicate key value violates unique constraint "django_content_type_app_label_key" The fixture loads correctly if I truncate the django_content_type table after running syncdb. But I don't want to do this every time I set up a test database. What am I doing wrong here? Is there someway to create the fixture so that it dosn't try to repopulate the django_content_type table? Thanks, Murray -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: mac No module named _md5 error
which python returns /opt/local/Library/Frameworks/Python.framework/ Versions/2.6/bin/python I didn't install python 2.6.6, at least to my knowledge. Django doesn't automatically load it does it? I have not explicitly loaded Python myself. The first time I checked was after loading django I just did a python --version and there it was. On Nov 19, 12:24 am, "Adam V." wrote: > How did you install 2.6.6, and what does "which python" give 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django_content_type integrity error on sync and loaddata
When you run dumpdata you can specify apps or models within an app to export. That will allow you to avoid bringing Django's scaffolding into your fixtures. Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Pass variable by URL to admin views
I want to pass a variable by URL to another page in django admin. it seems it is not working, i want to pass the variable "/? name=hello",but the url becomes "/?e=1" ( i think this is a redirect made by Django )... does any one knows how to solve this problem Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
I have an idea for a new tag
When rendering dictionary, there is absolutely no way to display values sorted by keys. The only workaround is to copy all the dict items to a sortable structure e.g. list and pass the list to the template, instead of the dictionary. Why not introduce a new tag to solve this problem: I say, it should be called {%secretfor%} and the usage would be {%secretfor k,v in mydict %} ... do stuff {%endsecretfor%} would work like sorted(mydict.keys) I won't stick with the tag name, but you see my point. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Cache problem after new image uploaded?
I have a custom settings form with a photo field: photo = forms.ImageField(max_length=200, required=False) On submission with a new photo being uploaded, I delete any existing image including its parent folder and replace with the new one. When the settings page is reloaded, the old image is still displayed. However, if I do a power refresh in the browser, ctrl+F5 the cache is removed and the uploaded image displays fine. Here are some of the response headers from the server: HTTP/1.1 200 OK Server: nginx/0.7.65 Date: Fri, 19 Nov 2010 18:32:38 GMT Content-Type: image/jpeg Connection: keep-alive Last-Modified: Fri, 19 Nov 2010 18:32:34 GMT Etag: "1a0685-d65-4956c214f7f1b" Accept-Ranges: bytes Content-Length: 3429 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Cache problem after new image uploaded?
This can be replicated in ie8 100% of the time and FF about 10% of the time. On Nov 19, 12:42 pm, vcarney wrote: > I have a custom settings form with a photo field: photo = > forms.ImageField(max_length=200, required=False) > > On submission with a new photo being uploaded, I delete any existing > image including its parent folder and replace with the new one. When > the settings page is reloaded, the old image is still displayed. > However, if I do a power refresh in the browser, ctrl+F5 the cache is > removed and the uploaded image displays fine. > > Here are some of the response headers from the server: > > HTTP/1.1 200 OK > Server: nginx/0.7.65 > Date: Fri, 19 Nov 2010 18:32:38 GMT > Content-Type: image/jpeg > Connection: keep-alive > Last-Modified: Fri, 19 Nov 2010 18:32:34 GMT > Etag: "1a0685-d65-4956c214f7f1b" > Accept-Ranges: bytes > Content-Length: 3429 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Static files ...
Hello, Sorry not to have replied for so long, but I thought I'd better just try and dig through it! In the meantime, I have upgraded to Django (1, 3, 0, 'alpha', 1) and follow the instructions in the development documentation. I am just trying to serve my static files for development purposes, but no matter what I do, I get 404s for my image and css files. Google Chrome reports: Request URL:http://localhost:8000/static/%20/admin/img/images/ cellobutton.jpg with that strange %20 in the middle of my link, which seems to relate to the curly braces in my link: The rest of the path is where my files are, in fact, if localhost:8000 appends my settings.py line: STATICFILES_ROOT = '/Users/jonno/django_projects/static' And I have: {% load staticfiles %} {% get_staticfiles_prefix as STATIC_PREFIX %} at the top of my template. Sorry to trouble all with this again! Thanks for any help -- Jon. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Static files ...
On 11/19/2010 1:56 PM, jonno wrote: > Hello, > > Sorry not to have replied for so long, but I thought I'd better just > try and dig through it! In the meantime, I have upgraded to Django > (1, 3, 0, 'alpha', 1) and follow the instructions in the development > documentation. I am just trying to serve my static files for > development purposes, but no matter what I do, I get 404s for my image > and css files. Google Chrome reports: > > Request URL:http://localhost:8000/static/%20/admin/img/images/ > cellobutton.jpg > > with that strange %20 in the middle of my link, which seems to relate > to the curly braces in my link: > > > Bingo! (I hope). Try regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Cache problem after new image uploaded?
Doing a redirect to the page with ?rand=time.time() did not work either. On Nov 19, 12:47 pm, vcarney wrote: > This can be replicated in ie8 100% of the time and FF about 10% of the > time. > > On Nov 19, 12:42 pm, vcarney wrote: > > > > > > > > > I have a custom settings form with a photo field: photo = > > forms.ImageField(max_length=200, required=False) > > > On submission with a new photo being uploaded, I delete any existing > > image including its parent folder and replace with the new one. When > > the settings page is reloaded, the old image is still displayed. > > However, if I do a power refresh in the browser, ctrl+F5 the cache is > > removed and the uploaded image displays fine. > > > Here are some of the response headers from the server: > > > HTTP/1.1 200 OK > > Server: nginx/0.7.65 > > Date: Fri, 19 Nov 2010 18:32:38 GMT > > Content-Type: image/jpeg > > Connection: keep-alive > > Last-Modified: Fri, 19 Nov 2010 18:32:34 GMT > > Etag: "1a0685-d65-4956c214f7f1b" > > Accept-Ranges: bytes > > Content-Length: 3429 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Static files ...
On 11/19/2010 1:56 PM, jonno wrote: > And I have: > > {% load staticfiles %} > {% get_staticfiles_prefix as STATIC_PREFIX %} > > at the top of my template. Sorry to trouble all with this again! > Thanks for any help -- Jon. PS: You might want to consider injecting STATIC_PREFIX into your contexts with a context processor. That way it happens without any need for template code. In particular, see http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-static regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: I have an idea for a new tag
An easy alternative is to make a sort filter: register.filter('sort',lambda x: sorted(x)) and then do {% for k,v in mydict.items|sort %} {{k}}:{{v}} {% endfor %} I had to look at the docs to realize there isn't a sort filter in django for some reason. I long ago added the one above to builtins and I don't know how I could have lived without it. Another handy one I feel the same way about is "contains" register.filter('contains', lambda x,y: y in x or []) {% if mydict|contains:"foo" %} This is foo: {{mydict.foo}} {% endif %} -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Models not being updated when accessed by multiple processes
Hi, This might be a gotcha on the models side, but I would like clarification and guidance on how to write the code better concerning multiple process accessing the same data via models. I have a backend script that runs the following code in multiple processes: 1 object = MyModel.object.get(id=1) 2 print object.value# starting value is 5 3 while object.fail_to_get_lock(): 4sleep(5) 5 object = MyModel.object.get(id=1) # Re-get the object so we can have the latest state 6 object.value = object.value - 1 7 print object.value# returns 4 8 object.release_lock() If the above code fails to get the lock because another process is running the code, it goes to sleep until the other process finishes. The other process will also be decrementing object.value, so if we have 2 processes running the above script at the same time, I would expect the later process to return line 7 as 3 and not 4. As a result, if 2 processes runs the above code at the same time, instead of getting a final value for object.value of 3, I get a 4. db is MySQL with innodb engine and auto_commit on. Is there some sort of caching going on in the models? How would I write the code so that it will always see the latest state of data in the db? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Models not being updated when accessed by multiple processes
On 11/19/2010 5:35 PM, Iqbal Abdullah wrote: > Hi, > > This might be a gotcha on the models side, but I would like > clarification and guidance on how to write the code better concerning > multiple process accessing the same data via models. > > I have a backend script that runs the following code in multiple > processes: > > 1 object = MyModel.object.get(id=1) > 2 print object.value# starting value is 5 > 3 while object.fail_to_get_lock(): > 4sleep(5) > 5 object = MyModel.object.get(id=1) # Re-get the object so we can > have the latest state > 6 object.value = object.value - 1 > 7 print object.value# returns 4 > 8 object.release_lock() > > If the above code fails to get the lock because another process is > running the code, it goes to sleep until the other process finishes. > The other process will also be decrementing object.value, so if we > have 2 processes running the above script at the same time, I would > expect the later process to return line 7 as 3 and not 4. > Shouldn't some saving occur for that to be true? regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using foreignkey data as a primary key
If you really want to have a separate table for Tag, You can do this: class CurrentTag(models.Model): tag = models.OneToOneField(Tag, primary_key=True) def __unicode__(self): return self.tag On Nov 20, 12:10 am, JE wrote: > Thanks for the replies. > I simplified the problem a bit by deciding it will be easier to have > some extra validation code in a separate admin view to do what I need > it to and removed the CurrentTag table, similar to what Rainy has > said. > > On Nov 18, 4:59 pm, Rainy wrote: > > > > > > > > > On Nov 18, 9:04 am, JE wrote: > > > > Hi, > > > > I'm pretty new to Django so feel free to laugh if something's > > > horrendously wrong here that I haven't spotted. > > > > I'm trying to use a field from a foreign key as a primary key in > > > another model, but have no idea how to do this. > > > The idea is to have a table called Tag (columns called tagname and > > > tagversion, which create a composite primary key using the > > > unique_together option in the metadata). > > > Why not just have a boolean column 'current' or 'active' > > in Tag model, instead of a separate table? On save, > > if it's changed inactive->active, all other tags are set > > to be inactive. -ak -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Feedback on New Database Template Application
Hello Django Users, I decided to write a series of applications that will make up a cms among other things and the first application is a database template application. It's for a cms where users won't have OS access. There is a demo site that has nothing but the application and revision. It uses class based generic views and the new static content service found in trunk or 1.3. If you have any interest or time please take a look and provide feedback on it, specifically if you think it needs changes or if it might be useful to you. Click on application link for a Trac instance and to see/checkout the code if you would like. http://templates.django-development.com/template/list/ I am hoping to make this usable to others and all feedback is appreciated. Direct to me if you would like at nosrednakram @t gmail dot com. I've locked most of the templates but you can create/delete/etc new templates with the demo account. Thank you, Mark Anderson -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Models not being updated when accessed by multiple processes
Hi Steve, Ops, yes, I forgot to include the object.save() in the pseudo code above. Yes, we're actually saving it: 1 object = MyModel.object.get(id=1) 2 print object.value# starting value is 5 3 while object.fail_to_get_lock(): 4sleep(5) 5 object = MyModel.object.get(id=1) # Re-get the object so we can have the latest state 6 object.value = object.value - 1 7 object.save() 8 print object.value# returns 4 9 object.release_lock() On 11月20日, 午前7:39, Steve Holden wrote: > On 11/19/2010 5:35 PM, Iqbal Abdullah wrote: > > > Hi, > > > This might be a gotcha on the models side, but I would like > > clarification and guidance on how to write the code better concerning > > multiple process accessing the same data via models. > > > I have a backend script that runs the following code in multiple > > processes: > > > 1 object = MyModel.object.get(id=1) > > 2 print object.value # starting value is 5 > > 3 while object.fail_to_get_lock(): > > 4 sleep(5) > > 5 object = MyModel.object.get(id=1) # Re-get the object so we can > > have the latest state > > 6 object.value = object.value - 1 > > 7 print object.value # returns 4 > > 8 object.release_lock() > > > If the above code fails to get the lock because another process is > > running the code, it goes to sleep until the other process finishes. > > The other process will also be decrementing object.value, so if we > > have 2 processes running the above script at the same time, I would > > expect the later process to return line 7 as 3 and not 4. > > Shouldn't some saving occur for that to be true? > > regards > Steve > -- > DjangoCon US 2010 September 7-9http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
A Model to store links to other models
I'm having trouble coming up with a pretty solution to a seemingly simple task. I'm relatively new to Django. I want to allow the end user to control various lists of links on the site used for navigation. The admin should allow the creation of "link groups" which have a collection of "links". These links would reference a pre-determined list of models. Let's say, for example, that there is a "link group" created for the footer links of a website. In the admin section, a user could add a link to a specific blog (from the Blog model), another link to the about us page (flatpages), etc. In other words, I'm trying to associate individual records from a number of tables together as a group of objects having a URL. I'm trying to find a nice, abstract solution. Obviously I don't want actual URLs in the database. This is something I would use frequently so I want to see if I can find or write an app to do this--if I can come up with an elegant solution. This would be nice, but, I can't imagine how it could be possible: class LinkGroup(models.Model): site = models.ForeignKey(Site) name = models.CharField() class Links(models.Model): link_group = ForeignKey(LinkGroup) model_type = ??? model_id = ForeignKey() # no can do! sort_order = PositiveIntegerField(default=100) This is an idea, however, I don't like having to reference the import in the DB. It's just begging for problems. class LinkModel(models.Model): name = models.CharField() # such as "Flat Page" model = models.CharField() # such as "myapp.models.FlatPage" class LinkGroup(models.Model): site = models.ForeignKey(Site) name = models.CharField() # such as "Navigation Links" class Link(models.Model): text = CharField() # such as "About Us" link_group = ForeignKey(LinkGroup) model = ForeignKey(LinkModel) model_id = PositiveIntegerField() # such as the PK for the myapp.models.FlatPage model sort_order = PositiveIntegerField(default=100) Any suggestions? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Display ForeignKey label rather than ID in a CharField
I have to override the default display of a foreignkey field in a form and instead display it as a CharField. Currently it displays the selection's ID but I need to display the label instead To be clear, the select option would be the default display for the ForeignKey. At the moment after I've turned the display to a CharField it displays 23 in the field. I need to display Fish. Fish Any help 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: I have an idea for a new tag
Just a thought, what about: {% for k,v in mydict|order:'key' %} or {% for k,v in mydict orderby key %} -Adam On Nov 19, 10:55 am, Paweł Roman wrote: > When rendering dictionary, there is absolutely no way to display > values sorted by keys. The only workaround is to copy all the dict > items to a sortable structure e.g. list and pass the list to the > template, instead of the dictionary. > > Why not introduce a new tag to solve this problem: > > I say, it should be called {%secretfor%} and the usage would be > > {%secretfor k,v in mydict %} > ... do stuff > {%endsecretfor%} > > would work like sorted(mydict.keys) > > I won't stick with the tag name, but you see my point. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django Tutorial - http://docs.djangoproject.com/en/dev/intro/tutorial01/
I'm trying to work through part 1 of the tutorial at: http://docs.djangoproject.com/en/dev/intro/tutorial01/ and I seem to be having problems getting my model code to work. I currently have Django-1.2.3, and Python 2.7 installed. I was able to run the startproject and create the mysite directory successfully. I then was also able to successfully start development server at 127.0.0.1:8000. I then ran the syncdb command to create all the stuff needed for the apps that came setup with Django. Next I ran the "startapp polls" command successfully to create the polls directory. I then put in the prescribed code for the two tables to be used by the polls app. Then I added the polls app to the installed apps list in my setting.py. Up to this point everything worked as described in the tutorial documentation. Then when I ran the syncdb command again to build the two new tables for the polls app I got the following error messages: python manage.py sql polls Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 438, in execute_manager utility.execute() File "C:\Python27\lib\site-packages\django\core\management \__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 219, in execute self.validate() File "C:\Python27\lib\site-packages\django\core\management\base.py", line 249, in validate num_errors = get_validation_errors(s, app) File "C:\Python27\lib\site-packages\django\core\management \validation.py", lin e 28, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors self._populate() File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate self.load_app(app_name, True) File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 78, in load_app models = import_module('.models', app_name) File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im port_module __import__(name) File "C:\Documents and Settings\hversemann\djangoprojects\mysite \polls\models. py", line 5, in class Poll(models.Model): File "C:\Documents and Settings\hversemann\djangoprojects\mysite \polls\models. py", line 7, in Poll pub_date = models.DateFimeField('date published') AttributeError: 'module' object has no attribute 'DateFimeField' I'm not sure what more I can do or where else to look to figure this out. I've just recently started learning python and only yesterday started this tutorial. I would appreciate any help in resolving this issue. Thanks. hank23 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Multiple inheritance model
I'm trying to integrate two existing apps, both of which provide a django Model - call them ModelA and ModelB - my app's model needs to inherit from both of these. I know django models support multiple inheritance, but both ModelA and ModelB define a Meta class, override the save() method, etc., so that won't work. What will work very nicely is for ModelB to simply inherit from ModelA, but since both are 3rd party apps, I don't want to hack their code. So, I need a clever idea for how I can take this inheritance hierarchy: django.Model /\ ModelA ModelB \ / MyModel and **logically** convert it, without touching code in ModelA or ModelB, to this: django.Model | ModelA | ModelB | MyModel One idea I had was this: class MyModel(ModelA, ModelB): ... Meta: # copy of ModelB's Meta code def foo(self, *args, **kwargs): ModelA.foo(self, *args, **kwargs) ModelB.foo(self, *args, **kwargs) But this approach fails on the save() - both Models do some processing before and after the call to super.save(). The annoying thing about this problem is that it's very easy to hack a solution by modifying the code for ModelB - just one tiny little change - but this isn't really an option since I want the app I'm building to be re-usable, and don't want to distribute it with a hacked copy of another app. hoping someone out there more clever than I can offer an idea? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Tutorial - http://docs.djangoproject.com/en/dev/intro/tutorial01/
just off the cuff - what's a "DateFimeField"?should be DateTimeField? On Nov 19, 12:44 pm, hank23 wrote: > I'm trying to work through part 1 of the tutorial at: > > http://docs.djangoproject.com/en/dev/intro/tutorial01/ > > and I seem to be having problems getting my model code to work. I > currently have Django-1.2.3, and Python 2.7 installed. I was able to > run the startproject and create the mysite directory successfully. I > then was also able to successfully start development server at > 127.0.0.1:8000. I then ran the syncdb command to create all the stuff > needed for the apps that came setup with Django. Next I ran the > "startapp polls" command successfully to create the polls directory. I > then put in the prescribed code for the two tables to be used by the > polls app. Then I added the polls app to the installed apps list in my > setting.py. Up to this point everything worked as described in the > tutorial documentation. Then when I ran the syncdb command again to > build the two new tables for the polls app I got the following error > messages: > > python manage.py sql polls > Traceback (most recent call last): > File "manage.py", line 11, in > execute_manager(settings) > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 438, in execute_manager > utility.execute() > File "C:\Python27\lib\site-packages\django\core\management > \__init__.py", line > 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "C:\Python27\lib\site-packages\django\core\management\base.py", > line 191, > in run_from_argv > self.execute(*args, **options.__dict__) > File "C:\Python27\lib\site-packages\django\core\management\base.py", > line 219, > in execute > self.validate() > File "C:\Python27\lib\site-packages\django\core\management\base.py", > line 249, > in validate > num_errors = get_validation_errors(s, app) > File "C:\Python27\lib\site-packages\django\core\management > \validation.py", lin > e 28, in get_validation_errors > for (app_name, error) in get_app_errors().items(): > File "C:\Python27\lib\site-packages\django\db\models\loading.py", > line 146, in > get_app_errors > self._populate() > File "C:\Python27\lib\site-packages\django\db\models\loading.py", > line 61, in > _populate > self.load_app(app_name, True) > File "C:\Python27\lib\site-packages\django\db\models\loading.py", > line 78, in > load_app > models = import_module('.models', app_name) > File "C:\Python27\lib\site-packages\django\utils\importlib.py", line > 35, in im > port_module > __import__(name) > File "C:\Documents and Settings\hversemann\djangoprojects\mysite > \polls\models. > py", line 5, in > class Poll(models.Model): > File "C:\Documents and Settings\hversemann\djangoprojects\mysite > \polls\models. > py", line 7, in Poll > pub_date = models.DateFimeField('date published') > AttributeError: 'module' object has no attribute 'DateFimeField' > > I'm not sure what more I can do or where else to look to figure this > out. I've just recently started learning python and only yesterday > started this tutorial. I would appreciate any help in resolving this > issue. Thanks. > > hank23 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Tutorial - http://docs.djangoproject.com/en/dev/intro/tutorial01/
On Fri, 2010-11-19 at 12:44 -0800, hank23 wrote: > 'DateFimeField' typo -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Models not being updated when accessed by multiple processes
I'm wondering, how are fail_to_get_lock and release_lock implemented? It would be some kind of multiprocess lock, which seems overly complicated.. using save() in this case is cumbersome, because save() is not threadsafe... you'll have to try to maintain your own lock. If you only want to implement increments and decrements, you can use F() object and update() methods to update the database. I have an example, here http://pastebin.com/qp4ExWC2 On Nov 19, 4:30 pm, Iqbal Abdullah wrote: > Hi Steve, > > Ops, yes, I forgot to include the object.save() in the pseudo code > above. Yes, we're actually saving it: > > 1 object = MyModel.object.get(id=1) > 2 print object.value # starting value is 5 > 3 while object.fail_to_get_lock(): > 4 sleep(5) > 5 object = MyModel.object.get(id=1) # Re-get the object so we can > have the latest state > 6 object.value = object.value - 1 > 7 object.save() > 8 print object.value # returns 4 > 9 object.release_lock() > > On 11月20日, 午前7:39, Steve Holden wrote: > > > > > > > > > On 11/19/2010 5:35 PM, Iqbal Abdullah wrote: > > > > Hi, > > > > This might be a gotcha on the models side, but I would like > > > clarification and guidance on how to write the code better concerning > > > multiple process accessing the same data via models. > > > > I have a backend script that runs the following code in multiple > > > processes: > > > > 1 object = MyModel.object.get(id=1) > > > 2 print object.value # starting value is 5 > > > 3 while object.fail_to_get_lock(): > > > 4 sleep(5) > > > 5 object = MyModel.object.get(id=1) # Re-get the object so we can > > > have the latest state > > > 6 object.value = object.value - 1 > > > 7 print object.value # returns 4 > > > 8 object.release_lock() > > > > If the above code fails to get the lock because another process is > > > running the code, it goes to sleep until the other process finishes. > > > The other process will also be decrementing object.value, so if we > > > have 2 processes running the above script at the same time, I would > > > expect the later process to return line 7 as 3 and not 4. > > > Shouldn't some saving occur for that to be true? > > > regards > > Steve > > -- > > DjangoCon US 2010 September 7-9http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: A Model to store links to other models
On 11/19/2010 8:51 PM, Micah Carrick wrote: > I'm having trouble coming up with a pretty solution to a seemingly > simple task. I'm relatively new to Django. > > I want to allow the end user to control various lists of links on the > site used for navigation. The admin should allow the creation of "link > groups" which have a collection of "links". These links would reference > a pre-determined list of models. Let's say, for example, that there is a > "link group" created for the footer links of a website. In the admin > section, a user could add a link to a specific blog (from the Blog > model), another link to the about us page (flatpages), etc. > > In other words, I'm trying to associate individual records from a number > of tables together as a group of objects having a URL. I'm trying to > find a nice, abstract solution. Obviously I don't want actual URLs in > the database. This is something I would use frequently so I want to see > if I can find or write an app to do this--if I can come up with an > elegant solution. > > This would be nice, but, I can't imagine how it could be possible: > > > class LinkGroup(models.Model): > site = models.ForeignKey(Site) > name = models.CharField() > > class Links(models.Model): > link_group = ForeignKey(LinkGroup) > model_type = ??? > model_id = ForeignKey() # no > can do! > sort_order = PositiveIntegerField(default=100) > > > This is an idea, however, I don't like having to reference the import in > the DB. It's just begging for problems. > > > class LinkModel(models.Model): > name = models.CharField() # such as "Flat Page" > model = models.CharField() # such as "myapp.models.FlatPage" > > class LinkGroup(models.Model): > site = models.ForeignKey(Site) > name = models.CharField() # such as "Navigation Links" > > class Link(models.Model): > text = CharField() # such as "About Us" > link_group = ForeignKey(LinkGroup) > model = ForeignKey(LinkModel) > model_id = PositiveIntegerField() # such as the PK for the > myapp.models.FlatPage model > sort_order = PositiveIntegerField(default=100) > > > Any suggestions? > What's wrong with the first approach? I use a similar technique to put pages in sections at http://holdenweb.com/ - here are the relevant models: class Section(models.Model): secid = models.IntegerField(primary_key=True) # This field type is corrected sectitle = models.CharField(max_length=50) secpath = models.CharField(max_length=50) secbgcolor = models.CharField(max_length=50) secstcolor = models.CharField(max_length=50) secpos = models.CharField(max_length=1) secsequence = models.IntegerField() # This field type is corrected sechandler = models.CharField(max_length=50) sechomeslot = models.IntegerField() # This field type is corrected sechometitle = models.CharField(max_length=50) secnews = models.CharField(max_length=20, null=True) class Meta: db_table = 'section' unique_together = (('secpath', ), ('sectitle', )) class Admin: list_display = ('sectitle', ) def __str__(self): return self.sectitle class Page(models.Model): pagpath = models.CharField(primary_key=True, max_length=50) pagdoctitle = models.CharField(max_length=250) pagtitle = models.CharField(max_length=200, blank=True, null=True) pagsecid = models.ForeignKey(Section, blank=True, null=True, db_column='pagsecid') # This field type is corrected pagsequence = models.IntegerField() # This field type is corrected pagtplname = models.CharField(max_length=50) paggenerated = models.SmallIntegerField() paglinkpath = models.CharField(max_length=50, blank=True, null=True) pagcontent = models.TextField() pagnavbarstuff = models.TextField(null=True, blank=True) pagctype = models.CharField(max_length=1, default="R") # This field type is corrected pagid = models.IntegerField() # Note this should eventually become the PK pagnews = models.CharField(max_length=20, blank=True, null=True) class Meta: db_table = 'page' def __str__(self): return self.pagpath What is it that the first model didn't do for you? regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.