Re: How to list all parents and their children if any?
Thanks Karen yet again. Am I right in thinking that this cannot be a symetrical arrangement ie: connector can access values from cable(s) and cable can access values from connector(s) It does not appear to be possible to put a ManyToManyField in both the "parent' models, because one must be declared before the other, and the other is therefore invalid at that time Perhaps there is a work around? Mike On Nov 29, 2:56 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Sat, Nov 28, 2009 at 11:50 PM, adelaide_mike <mike.ro...@internode.on.net > > > > > wrote: > > I have three models: > > > class Connector(models.Model): > > connectorname = models.CharField(max_length=32) > > > class Cable(models.Model): > > cablename = models.CharField(max_length=32) > > > class Node(models.Model): > > connector = models.ForeignKey(Connector) > > cable = models.ForeignKey(Cable) > > node_specific_data = models.CharField(max_length=32) > > > I wish to make a report displaying all Connector names at least once, > > and the Cable name that the Node model relates them to. If I did not > > need the nodespecificdata I could have used a many-to-many between > > Connector and Cable. Sadly I do need it. > > The extra information doesn't prohibit use of ManyToMany, see: > > http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
How to list all parents and their children if any?
I have three models: class Connector(models.Model): connectorname = models.CharField(max_length=32) class Cable(models.Model): cablename = models.CharField(max_length=32) class Node(models.Model): connector = models.ForeignKey(Connector) cable = models.ForeignKey(Cable) node_specific_data = models.CharField(max_length=32) I wish to make a report displaying all Connector names at least once, and the Cable name that the Node model relates them to. If I did not need the nodespecificdata I could have used a many-to-many between Connector and Cable. Sadly I do need it. A Connector may have any number of related nodes, including none. I need to obtain a report displaying all connectors at least once, with their related cablename(s), if any, shown (on additional rows if necessary). Can I do this without resorting to raw SQL? Thanks (yet again) Mike -- 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.
Setting a fontName in a style
One final question if I may (well I hope its the last). In my standard report generating view I need to use Arial font (for example). I have studied the reportlab docs (Paragraphs chapter) for hours and tried all sorts of guesses as to how to do it. Nothing I have tried works. My fault. Now insightful enough. I have the following in my report generating view (which works a treat) and I am sure there is a simple alteration that will change the font. But there is no example in the docs AFAIK. stylesheet = getSampleStyleSheet() normalstyle = stylesheet['Normal'] Any offers? Mike -- 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.
Error when generating PDF
In my report generating view I have this (snip): if tablename == 'Area': areas = Area.objects.all() data.append(['Code','Name','Description']) for area in areas: data.append([ Paragraph(area.area, normalstyle, bulletText=None), Paragraph(area.nick, normalstyle, bulletText=None), Paragraph(area.desc, normalstyle, bulletText=None) ]) table = Table(data, 1*[0.75*inch]+1*[2.0*inch]+1*[4.0*inch], style=ts) elif tablename == 'Rack': racks = Rack.objects.all() data.append(['Code','Name', 'Description']) for rack in racks: data.append([ Paragraph(rack.rack, normalstyle, bulletText=None), Paragraph(rack.nick, normalstyle, bulletText=None), # thats line 108 Paragraph(rack.desc, normalstyle, bulletText=None) ]) table = Table(data, 1*[1.25*inch]+1*[2.0*inch]+1*[4.0*inch], style=ts) When tablename = "Area" the .pdf is generated without error. Wnen it is "Rack" this error is raised: Traceback (most recent call last): File "/home/mrowan/django/django/core/handlers/base.py", line 86, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/home/mrowan/projects/cbm/djcbm/cbm/reports.py", line 108, in print_list Paragraph(rack.nick, normalstyle, bulletText=None), File "/usr/lib/python2.5/site-packages/reportlab/platypus/ paragraph.py", line 523, in __init__ self._setup(text, style, bulletText, frags, cleanBlockQuotedText) File "/usr/lib/python2.5/site-packages/reportlab/platypus/ paragraph.py", line 543, in _setup text = cleaner(text) File "/usr/lib/python2.5/site-packages/reportlab/platypus/ paragraph.py", line 61, in cleanBlockQuotedText L=filter(truth,map(_lineClean, split(text, '\n'))) File "/usr/lib/python2.5/site-packages/reportlab/platypus/ paragraph.py", line 23, in split return [uword.encode('utf8') for uword in text.split(delim)] AttributeError: 'NoneType' object has no attribute 'split' What does the error message mean? Can someone translate please? TIA Mike -- 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: How best to display a report?
Nevermind. Found the solution in a post from abrightwell. Thanks. Mike On Nov 22, 8:40 pm, adelaide_mike <mike.ro...@internode.on.net> wrote: > Hi Kenneth, and thanks for the reference. I must admin I did not > think of looking int he Django docs for ReportLab related stuff. > Should have. > > My new problem is that the example in the docs uses canvas, but in > order to display tabular data I think I need to use SimpleDocTemplate, > with which I am able to prodice the pdf I want. I do not see how to > incorporate this technology into the given example. > > Perhaps someone has done this and can give me the next pointer? > > Mike > > On Nov 22, 9:30 am, Kenneth Gonsalves <law...@au-kbc.org> wrote: > > > On Sunday 22 Nov 2009 3:38:24 am adelaide_mike wrote: > > > > Django 1.0.2 being used to create, manage and report on data in > > > tables. I am using ReportLab to generate a .pdf which I store with a > > > known name in a sub-directory. > > > it is there in the docs - search for reportlab in the docs. > > -- > > regards > > Kenneth Gonsalves > > Senior Project Officer > > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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=.
Re: How best to display a report?
Hi Kenneth, and thanks for the reference. I must admin I did not think of looking int he Django docs for ReportLab related stuff. Should have. My new problem is that the example in the docs uses canvas, but in order to display tabular data I think I need to use SimpleDocTemplate, with which I am able to prodice the pdf I want. I do not see how to incorporate this technology into the given example. Perhaps someone has done this and can give me the next pointer? Mike On Nov 22, 9:30 am, Kenneth Gonsalves <law...@au-kbc.org> wrote: > On Sunday 22 Nov 2009 3:38:24 am adelaide_mike wrote: > > > Django 1.0.2 being used to create, manage and report on data in > > tables. I am using ReportLab to generate a .pdf which I store with a > > known name in a sub-directory. > > it is there in the docs - search for reportlab in the docs. > -- > regards > Kenneth Gonsalves > Senior Project Officer > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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=.
How best to display a report?
Please excuse my lack of knowledge about the following. (If I knew the answer, I would not be asking...) Django 1.0.2 being used to create, manage and report on data in tables. I am using ReportLab to generate a .pdf which I store with a known name in a sub-directory. I have seen websites where a link can be used to activate the workstation's download mechanism, such that, at least in Mac OSX, the .pdf will be displayed. That is exactly what I want. The source code gives no clue as to how this is done. Any pointers would be much appreciated. Thanks Mike -- 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=.
Django and reportlab table question
I am attempting to user ReportLab with Django to make a report displaying my data in a tabular format. An example model is: class Vehicle(models.Model): ve_name = models.CharField(max_length=20) ve_type = models.CharField(max_length=20) My report generating view a copy of the example in the ReportLab docs. I have marked my sticking point with ''' def testX(request): # Our container for 'Flowable' objects elements = [] # A large collection of style sheets pre-made for us styles = getSampleStyleSheet() # A basic document for us to write to 'rl_hello_table.pdf' doc = SimpleDocTemplate('rl_hello_table.pdf') elements.append(Paragraph("Vehicle Summary", styles['Title'])) vehicles = Vehicle.objects.all() '''the question is how to modify the following lines to read the data from vehicles rather than use the hard coded data shown in the example''' data = [['Caves', 'Wumpus Population'], ['Deep Ditch',50], ['Death Gully', 5000], ['Dire Straits', 600], ['Deadly Pit',5], ['Conclusion','Run!']] '''after that, I think I can sort out the following''' # First the top row, with all the text centered and in Times-Bold, # and one line above, one line below. ts = [('ALIGN', (1,1), (-1,-1), 'CENTER'), ('LINEABOVE', (0,0), (-1,0), 1, colors.purple), ('LINEBELOW', (0,0), (-1,0), 1, colors.purple), ('FONT', (0,0), (-1,0), 'Times-Bold'), # The bottom row has one line above, and three lines below of # various colors and spacing. ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple), ('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None, None, 4,1), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.red), ('FONT', (0,-1), (-1,-1), 'Times-Bold')] # Create the table with the necessary style, and add it to the # elements list. table = Table(data, style=ts) elements.append(table) Can anyone give me a push in the right direction? Thanks for any help. Mike -- 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=.
coercing to Unicode: need string or buffer, Connector found
Hi. Still learning, slowly. This is Django 1.0.2 The relevant models are Unit, Connector and Cable class Cable(models.Model): cable = models.CharField(max_length=8, blank=False) desc = models.CharField(max_length=128, blank=True) cabletype = models.ForeignKey(Cabletype, blank=True, null=True) connector_left = models.ForeignKey(Connector, related_name='cable_left', blank=True, null=True) connector_right = models.ForeignKey(Connector, related_name='cable_right', blank=True, null=True) length = models.DecimalField (max_digits=8,decimal_places=2,blank=True,null=True) version = models.ForeignKey(Version, blank=True, null=True) def __unicode__(self): return '%s:%s' % (self.cable, self.version) class Meta: ordering = ['cable'] unique_together=('cable','version') class Unit(models.Model): unit = models.CharField(max_length=8, blank=False) desc = models.CharField(max_length=128, blank=True) rack = models.ForeignKey(Rack) version = models.ForeignKey(Version, blank=True, null=True) def __unicode__(self): return '%s-%s' % (unicode(self.rack), self.unit) class Meta: ordering = ['rack','unit'] unique_together=('rack','unit') class Connector(models.Model): connector = models.CharField(max_length=8, blank=False) desc = models.CharField(max_length=128, blank=True) unit = models.ForeignKey(Unit) connectortype = models.ForeignKey(Connectortype, blank=True, null=True) def __unicode__(self): return '%s-%s' % (unicode(self.unit), self.connector) class Meta: ordering = ['unit','connector'] unique_together=('unit','connector') Attempting my first reportlab report I get this TypeError: coercing to Unicode: need string or buffer, Connector found at the last line in the following view (very much a prototype) cables = Cable.objects.all() for cable in cables: print "cable=", cable# prints OK print "connector_left=", cable.connector_left #prints OK p = Paragraph(cable.cable+cable.desc+cable.connector_left, style) If I make the last line: p = Paragrapg(cable.cable+cable.desc,style) the report is generated correctly. What does the TypeError want me to change? Thanks Mike --~--~-~--~~~---~--~~ 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 get a queryset?
Thanks Max. In an ideal world left_connector, right_connector would be the way to go. However, I need to account for a cable that, at one or both ends is split into separate conductors, that go to separate connectors (thus breaking the rule I had specified.) Nodes, with a little embellishment, allow me to achieve this. I will investigate your itertools suggestion. Mike On Oct 20, 8:38 am, Max Battcher <m...@worldmaker.net> wrote: > adelaide_mike wrote: > > Hi > > My models are, essentially : > > class Cable(models.Model): > > cable = models.CharField(max_length=8) > > > class Connector(models.Model): > > connector = models.CharField(max_length=8) > > > class Node(models.Model): > > cable = models.ForeignKey(Cable) > > connector = models ForeignKey(Connector) > > > So, a real world cable can be plugged in to no, one, or two connectors > > (one at each end). The Node table describes the junctions between > > cables and connectors. > > > Can I, without resorting to raw SQL, build a queryset that shows > > connector-cable-connector? > > You would have a hard time even accomplishing that in raw SQL with those > models... If you have the flexibility to change your models I would try > something like: > > class Connector(models.Model): > name = models.CharField(max_length=8) > > class Cable(models.Model): > name = models.CharField(max_length-8) > left_connector = models.ForeignKey(Connector, blank=True, null=True) > right_connector = models.ForeignKey(Connector, blank=True, null=True) > > This makes your 0, 1, or 2 relationship explicit. I went with the > left/right distinction as it is an easy "handed" way of describing them, > but other choices may be more appropriate depending on your usage > patterns... > > Otherwise, your best bet would seem to me to be to use > Node.objects.all().orderby('cable') and group the > connector-cable-connector by yourself. Something that I generally find > useful in situations like that is Python's groupby function from itertools. > > -- > --Max Battcher--http://worldmaker.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to get a queryset?
Hi My models are, essentially : class Cable(models.Model): cable = models.CharField(max_length=8) class Connector(models.Model): connector = models.CharField(max_length=8) class Node(models.Model): cable = models.ForeignKey(Cable) connector = models ForeignKey(Connector) So, a real world cable can be plugged in to no, one, or two connectors (one at each end). The Node table describes the junctions between cables and connectors. Can I, without resorting to raw SQL, build a queryset that shows connector-cable-connector? Thanks for any input. Mike --~--~-~--~~~---~--~~ 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 change name for model in Admin?
Thanks for the pointer. I find that the verbose_name works as advertised in the case of a model named "Agency", where I use the verbose name "office". However, in the case of the model Franchise the verbose name "company" refuses to work. Anyone know why? Mike On Oct 4, 2:11 am, Nan <ringe...@gmail.com> wrote: > Yes. > > class Foo(models.Model): > # field definitions here > class Meta: > verbose_name = 'Bar' > > See > also:http://docs.djangoproject.com/en/dev/ref/models/options/#ref-models-o... > > On Oct 3, 10:37 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > Hi again. > > I have made a couple of confusing choices for table names in my > > database. I do not really want to change them in the PostgreSQL > > database. Can I change the labels given to them in the Admin. For > > example in the list of administratable tables and the pages that > > follow when doing add or change? > > > Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to change name for model in Admin?
Hi again. I have made a couple of confusing choices for table names in my database. I do not really want to change them in the PostgreSQL database. Can I change the labels given to them in the Admin. For example in the list of administratable tables and the pages that follow when doing add or change? Mike --~--~-~--~~~---~--~~ 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 pass values between views/templates
My only dissatisfaction is that other contributors to this list seem to do almost anything with very few lines of code, whereas I am using many. And, being a newbie I naturally worry that I am on the wrong pathway, having missed the turning. Thanks to both for your reassurance. Mike On Oct 3, 11:59 am, Shawn Milochikwrote: > Your current approach makes sense. If you're concerned that you're > storing too much data in the session, you could just maintain a > session ID in the session and use that as a key for an sqlite3 > database or something, or even a model in your app's database, if that > makes sense. Is there any reason you're unsatisfied with the way > you're doing it? > > 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-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 -~--~~~~--~~--~--~---
How to pass values between views/templates
Hi In my app the user needs to drill down through a series of templates and their views to identify a house. We start with the city, then the street and finally the house, in each case chosen from a rendering of the possible values selected from the relevant database table. I have all this working nicely using request.session['insert value here'] as the tool for storing the choices as they are made. My question is: is there a better or more proper way? Mike --~--~-~--~~~---~--~~ 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 refer to a data item?
Django itself uses the term "column" as witnessed by an exception I just raised reading: no such column. Mike On Sep 17, 11:34 pm, Javier Guerra <jav...@guerrag.com> wrote: > On Thu, Sep 17, 2009 at 9:04 AM, adelaide_mike > > <mike.ro...@internode.on.net> wrote: > > as a database developer for many years I am used to a world > > populated by rows and columns. > > just curious, what kind of database uses 'rows and columns'? all SQL > databases use 'records and fields', while other kinds might use 'keys > and values', or 'documents', or maybe a 'forest of objects'... > > -- > 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-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 -~--~~~~--~~--~--~---
Order_by on greatgrandparent.name
I have a multi-table model, each table related to the next by a one to many foreign key. I wish to do: q = Child.objects.filter(date__gte=startdate).order_by ('parent.grandparent.greatgrandparent__name') This raises an exception no such column: parent.grandparent.greatgrandparent__name Is there a workable way to do this? Thanks in advance for any ideas. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Foreign Key selector on page does not preset
Hi. In my Django 1.0.2 app I have a parent and a child table. On my child ModelForm a selector field for the parent is automatically provided. The form also displays a "date" field representing a column in the child model. In my view I have: form = MyForm(initial={'date': request.session['date'], 'parent': request.session['parent'] }) Print commands show that both "request.session['date']" and "request.session['parent']" have values as expected, the latter being a parent object. The date value shows on the rendered form, but the parent selector does not preselect itself. Anyone know why this might be so? TIA Mike --~--~-~--~~~---~--~~ 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 refer to a data item?
Hi Daniel Yes, as a database developer for many years I am used to a world populated by rows and columns. I realise Django does things differently. Understanding the differences is a bit tricky. My reference to ifchanged relates to the loop in the template that will need to display or not certain fields depending on whether their value changed or did not, in each successive "row". Thanks for your clear explanation. It helped greatly. Mike On Sep 17, 10:26 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Sep 17, 1:48 pm, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > > > Hello > > I, a newbie to Django and Python, have a model thus: > > > class Person(model.Models): > > first_name = models.CharField(max_length=32) > > last_name = models.CharField(max_length=32) > > > In my view.py can do this, to illustrate my question: > > > def testing(request): > > persons = Person.objects.all() > > print "persons=", persons #prints OK > > print "the value in the third column of the second row is ", ?? > > what goes here?? > > return render_to_response('xyz/testing.html', {'persons': > > persons}) > > > I imagine there is a way to do this, surely, otherwise how can I use > > ifchanged in my template. I have battled this for days, got various > > responses from various esteemed sources, but I don't get it. Any help > > available as in "the answer is..." ? Your patience is appreciated. > > > Mike > > What do you mean by 'row' and 'column' here? Are you referring to > database rows/columns? > > You can get the second Person object in your result set by doing > persons[2], and get the last_name field by doing persons[2].last_name, > but the 'third column' has no particular meaning in Django, because a > model is not a database object and its fields have no particular > order. > > I don't understand the reference to ifchanged, or what it has to do > with columns and rows. > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to refer to a data item?
Hello I, a newbie to Django and Python, have a model thus: class Person(model.Models): first_name = models.CharField(max_length=32) last_name = models.CharField(max_length=32) In my view.py can do this, to illustrate my question: def testing(request): persons = Person.objects.all() print "persons=", persons #prints OK print "the value in the third column of the second row is ", ?? what goes here?? return render_to_response('xyz/testing.html', {'persons': persons}) I imagine there is a way to do this, surely, otherwise how can I use ifchanged in my template. I have battled this for days, got various responses from various esteemed sources, but I don't get it. Any help available as in "the answer is..." ? Your patience is appreciated. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Make a bold row in a table
Django 1.0.2 In the following template I intend to make rows that have an empty second column bold. Hence trying 2 in row. My syntax is wrong due to inexperience with Python, and possibly my methodology also. {% extends "base.html" %} {% block content %} Agent summary report The most recent listing for each property listed within the past 12 weeks Address Date Price Method Agent Mobile {% for row in listings %} {% for item in row %} {{ item }} {% endfor %} {% endfor %} {% endblock %} Is there a way to do this? Mike --~--~-~--~~~---~--~~ 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: Confused ForeignKey ?
Oops - my mistake within admin.py. Sorry to waste bandwidtrh. Mike On Sep 11, 10:36 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > Hi > I am just getting into my second project/app but have run into a > problem I have not seen before. My models.py has the following: > > class Cabletype(models.Model): > cabletype = models.CharField(max_length=16, blank=False, > unique=True) > desc = models.TextField() > def __unicode__(self): > return self.catype > > class Cable(models.Model): > cable = models.CharField(max_length=16, blank=False, unique=True) > desc = models.TextField() > cabletype = models.ForeignKey(Cabletype) > def __unicode__(self): > return self.cable > > In admin.py I have: > from djcbm.cbm.models import Cabletype, Cable > from django.contrib import admin > > class CabletypeInline(admin.StackedInline): > model = Cabletype > extra = 5 > > class CabletypeAdmin(admin.ModelAdmin): > inlines = [CabletypeInline] > #search_fields = ['franchise_name'] > admin.site.register(Cabletype, CabletypeAdmin) > > class CableInline(admin.StackedInline): > model = Cable > extra = 5 > > class CableAdmin(admin.ModelAdmin): > inlines = [CableInline] > #search_fields = ['franchise_name'] > admin.site.register(Cable, CableAdmin) > > When I go to Add Cabletype in a new sqlite3 database I get: > > Exception at /admin/cbm/cabletype/add/ > > has no ForeignKey to 'djcbm.cbm.models.Cabletype'> > > Can someone tell me what this indicates? Thanks you in advance for > your valued assistance. > > Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Confused ForeignKey ?
Hi I am just getting into my second project/app but have run into a problem I have not seen before. My models.py has the following: class Cabletype(models.Model): cabletype = models.CharField(max_length=16, blank=False, unique=True) desc = models.TextField() def __unicode__(self): return self.catype class Cable(models.Model): cable = models.CharField(max_length=16, blank=False, unique=True) desc = models.TextField() cabletype = models.ForeignKey(Cabletype) def __unicode__(self): return self.cable In admin.py I have: from djcbm.cbm.models import Cabletype, Cable from django.contrib import admin class CabletypeInline(admin.StackedInline): model = Cabletype extra = 5 class CabletypeAdmin(admin.ModelAdmin): inlines = [CabletypeInline] #search_fields = ['franchise_name'] admin.site.register(Cabletype, CabletypeAdmin) class CableInline(admin.StackedInline): model = Cable extra = 5 class CableAdmin(admin.ModelAdmin): inlines = [CableInline] #search_fields = ['franchise_name'] admin.site.register(Cable, CableAdmin) When I go to Add Cabletype in a new sqlite3 database I get: Exception at /admin/cbm/cabletype/add/ has no ForeignKey to Can someone tell me what this indicates? Thanks you in advance for your valued assistance. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django, Blueprintcss and a data array
I (newbie) am looking at using Blueprintcss to display a 7 column array of data. The data is passed to the template in "dataarray". I have tested the code below without the section and the column headings display correctly. Adding the section to the code causes an error at {% for row in dataarray %}: Caught an exception while rendering: 'int' object is not iterable Very similar code in a template that uses a simple table (without Blueprint) does not throw an error. {% extends "base.html" %} {% block content %} Agent summary report The most recent listing for each property listed within the past 12 weeks Address Date Price Method Agent Mobile {% for row in dataarray %} {% for item in row %} {{ item }} {% endfor %} {% endfor %} {% endblock %} Any hints, or pointers to the display of multi-row columned data would be appreciated. Mike Rowan --~--~-~--~~~---~--~~ 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: Django 1.0.2 + CSS how to?
Thank you Mike Ramirez. [1] makes a difference. I now see the css taking effect. Mike On Aug 30, 8:55 am, Mike Ramirez <gufym...@gmail.com> wrote: > On Saturday 29 August 2009 04:35:11 pm adelaide_mike wrote: > > > > > As a very newbie I am struggling to understand how to use CSS. I read > > in > > >http://docs.djangoproject.com/en/dev/topics/forms/media/#paths-in-med... > >initions > > > that I need to write: > > class Media: > > css = { > > 'screen': ('pretty.css',), > > 'print': ('newspaper.css',) > > } > > > for example. > > > Where is this code placed, in which file? Is this what I should do? > > Any help or pointers to additional docs for beginners would be > > appreciated. > > > Mike > > That's specifically for forms, that code would go in your forms.py file > normally. The actual css files would be served over your MEDIA_URL. > > Media in general would be served over the static files, in your MEDIA_ROOT > direcotry. You'll need to set up django or your httpd to serve static media > over the MEDIA_URL[1]. Once this is done, you can add in css through the > template using the link html tag. > > There is a template context processor that allows you to use {{ MEDIA_URL }} > in your templates [2] That will make using the link tag easier. The only > problem with this is that if you use styles with the url() setting, you'll > need to change these manually (search and replace works) in your *.css files > or you can write a manage.py command to update the css files for you, when > switching media servers. > > example of MEDIA_ROOT: > > app/media > app/media/css > app/media/js > app/media/images > > example of using media in a template: > media="screen" charset="utf-8" /> > > The files that you have defined for your form media should go in a similar > place and the paths are relative to your MEDIA_URL. > > The default.css for me is a site wide style sheet and I put most of the styles > in there. I don't use the metaclass Media, unless the form field needs a > specific style. > > I hope this helps, > > Mike > > [1]http://docs.djangoproject.com/en/dev/howto/static-files/ > [2]http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-c... > > -- > As I was walking down the street one dark and dreary day, > I came upon a billboard and much to my dismay, > The words were torn and tattered, > From the storm the night before, > The wind and rain had done its work and this is how it goes, > > Smoke Coca-Cola cigarettes, chew Wrigleys Spearmint beer, > Ken-L-Ration dog food makes your complexion clear, > Simonize your baby in a Hershey candy bar, > And Texaco's a beauty cream that's used by every star. > > Take your next vacation in a brand new Frigedaire, > Learn to play the piano in your winter underwear, > Doctors say that babies should smoke until they're three, > And people over sixty-five should bathe in Lipton tea. > > signature.asc > < 1KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django 1.0.2 + CSS how to?
As a very newbie I am struggling to understand how to use CSS. I read in http://docs.djangoproject.com/en/dev/topics/forms/media/#paths-in-media-definitions that I need to write: class Media: css = { 'screen': ('pretty.css',), 'print': ('newspaper.css',) } for example. Where is this code placed, in which file? Is this what I should do? Any help or pointers to additional docs for beginners would be appreciated. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Change my model names - consequences?
After adding a model to my Django 1.0.2 app I would like to change the names of two models. Will the syncdb take care of this for me? I anticipate I will need to change the table names in PostgreSQL. Any caveats? Any hints? TIA Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to get DATABASE_NAME
In my reporting function I need to have: If DATABASE_NAME = x: #do this Else: #do the other How can I obtain that name, which is established in settings.py? Mike --~--~-~--~~~---~--~~ 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 tidy up data returned by raw sql has u'blahblah'
OK, and thanks. I asked the wrong question in that case. The correct question might be how do I transfer the data in the returned rows, which is several columns from various tables, into distinct fields on a rendered page? I am assuming that this process will remove the Python unicode indicators. I have not found more than a paragraph or two concerning the use of raw sql. Any pointers would be appreciated. Thanks Mike On Aug 15, 5:37 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Aug 15, 5:23 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > My raw sql returns a list of data very nicely, except that character > > cols have data surrounded by u'', and dates have datetime.date > > (2009-01-01) etc. > > > In my newbie innocence I have not discovered how to remove these > > extras. Any clues? > > > Thanks > > > Mike > > They are just how Python indicates a unicode and a datetime type > respectively. You don't need to remove them. > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to tidy up data returned by raw sql has u'blahblah'
My raw sql returns a list of data very nicely, except that character cols have data surrounded by u'', and dates have datetime.date (2009-01-01) etc. In my newbie innocence I have not discovered how to remove these extras. Any clues? Thanks Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
raw sql Operational Error
Working in Django 1.0.2 with PostgreSQL backend the following produces an error: Operational Error at /report/agent_summary/ near "ON": syntax error The SQL works if run in pgadminIII but with %s replaced by "2009-01-01". Must be a newbie error somewhere. def agent_summary(request): '''build a report showing the most recent advertisement (listing) for properties listed within the last 12 weeks''' startdate = date.today()-timedelta(7*12) cursor = connection.cursor() cursor.execute("SELECT DISTINCT ON (property_id) property_id, date, wha_property.propnum, wha_street.street_name, wha_suburb.suburb_name, wha_agent.first_name, wha_agent.last_name, wha_agency.name FROM wha_listing, wha_agent, wha_agency, wha_property, wha_street, wha_suburb WHERE wha_suburb.id = wha_street.suburb_id AND wha_street.id = wha_property.street_id AND wha_property.id = property_id AND wha_agency.id = wha_agent.agency_id AND wha_agent.id = agent_id AND date > %s ORDER BY property_id, date DESC", [startdate]) listings = cursor.fetchall() return render_to_response('wha/agent_summary.html', {'listings': listings}) Any help very much appreciated. Steep learning curve. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Calculating a date
This should really be a Python enquiry, but I am sure someone will know: I need to calculate the date 12 weeks before today. What is the best way? TIA Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django 1.0.2 ordering fireign keys
Hi Lets say I have two models Street and House, related by a foreign key thus: class House(models.Model): house_number = models.CharField(max_length=16) street = models.ForeignKey(Street) In the admin area, the Change House page displays a list widget by which to select the street. I need them to be listed in alphabetical order. How should a newbie cause this to happen? TIA for yor sual helpful response. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
'str' object not callable
Hi Can some kind soul tell me what, in principle, this means: 'str' object not callable ? It seems to be associated with urls.py Newbie just needs some additional words to help. Have looked at the history of this, which did not help. I do not want to know why the error is arising, I simply want to know what it is trying to tell me, in good ol English (if possible). Thanks Mike --~--~-~--~~~---~--~~ 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: Add extra field to ModelForm
Thanks Alex. A simpler way out would be if the agent field, which is a foreign key pick list, could be caused to show only those values I determine dynamically. Is this possible in a ModelForm? Mke On Jul 12, 12:17 am, Alex Gaynor <alex.gay...@gmail.com> wrote: > On Sat, Jul 11, 2009 at 10:08 AM, adelaide_mike <mike.ro...@internode.on.net > > > > > wrote: > > > Django 1.0.2. My ModelForm concerns (and is based on the table for) > > advertisements for houses placed by real estate agents. > > > I need the agent widget (which by default is a pick list of all > > agents), to be modified on the form to be either (depending on > > circumstances) a non-editable preset display object, or a pick list > > with a dynamically set choice of two agents. > > > So, I need to add extra fields to my ModelForm. Can this be done? > > > Thanks > > > Mike > > Sure, just define a Field on the ModelForm in the same way you would on a > regular Form and it will get added to the Form. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." -- Voltaire > "The people's good is the highest law." -- Cicero > "Code can always be simpler than you think, but never as simple as you want" > -- Me --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Add extra field to ModelForm
Django 1.0.2. My ModelForm concerns (and is based on the table for) advertisements for houses placed by real estate agents. I need the agent widget (which by default is a pick list of all agents), to be modified on the form to be either (depending on circumstances) a non-editable preset display object, or a pick list with a dynamically set choice of two agents. So, I need to add extra fields to my ModelForm. Can this be done? Thanks Mike --~--~-~--~~~---~--~~ 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: duplicate primary key problem
Very cool, Rajesh D. Thanks. Mike On Jul 11, 12:31 am, Rajesh D <rajesh.dha...@gmail.com> wrote: > On Jul 10, 11:06 am, adelaide_mike <mike.ro...@internode.on.net> > wrote: > > > > > I suspect this is a question more for a PostgreSQL list, but please > > bear with me. > > > In Django 1.0.2 working with PostgreSQL 8.3 I have a model with an > > implied pkey. PostgreSQL syas this: > > > CREATE TABLE wha_property > > ( > > id serial NOT NULL, > > propnum character varying(16) NOT NULL, > > beds integer, > > baths integer, > > rooms integer, > > garage character varying(8), > > frontage integer, > > is_corner boolean, > > street_id integer NOT NULL, > > land_area numeric(10,2), > > year_built integer, > > valuation_nr character varying(16), > > CONSTRAINT wha_property_pkey PRIMARY KEY (id), > > CONSTRAINT wha_property_street_id_fkey FOREIGN KEY (street_id) > > REFERENCES wha_street (id) MATCH SIMPLE > > ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY > > DEFERRED, > > CONSTRAINT wha_property_street_id_key UNIQUE (street_id, propnum) > > > The wha_property table is populated with 500,000 rows from another > > database. There are gaps in the series of used id numbers. > > > If I attempt to insert a new row Django mostly reports an integrity > > violation at wha_property_pkey, though a couple of times with > > different parent rows it has worked. My very newbie view for > > inserting or updating a row is here: > > >http://dpaste.com/65435/ > > > I would be very happy if someone can spot where I have an error. If > > anyone cares to criticise my view, please be gentle. I am new at this > > Django/PostgreSQL magic. > > The sequence for the id column might be out of sync. That would cause > your inserts to pick an id that already exists. > > Try the following command: > > python manage.py sqlsequencereset wha > > That will print out the SQL that you need to run to get your sequences > back in sync with your data. Run that SQL. Then try inserting new data > through your view again. > > -RD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
duplicate primary key problem
I suspect this is a question more for a PostgreSQL list, but please bear with me. In Django 1.0.2 working with PostgreSQL 8.3 I have a model with an implied pkey. PostgreSQL syas this: CREATE TABLE wha_property ( id serial NOT NULL, propnum character varying(16) NOT NULL, beds integer, baths integer, rooms integer, garage character varying(8), frontage integer, is_corner boolean, street_id integer NOT NULL, land_area numeric(10,2), year_built integer, valuation_nr character varying(16), CONSTRAINT wha_property_pkey PRIMARY KEY (id), CONSTRAINT wha_property_street_id_fkey FOREIGN KEY (street_id) REFERENCES wha_street (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT wha_property_street_id_key UNIQUE (street_id, propnum) The wha_property table is populated with 500,000 rows from another database. There are gaps in the series of used id numbers. If I attempt to insert a new row Django mostly reports an integrity violation at wha_property_pkey, though a couple of times with different parent rows it has worked. My very newbie view for inserting or updating a row is here: http://dpaste.com/65435/ I would be very happy if someone can spot where I have an error. If anyone cares to criticise my view, please be gentle. I am new at this Django/PostgreSQL magic. Regards and thanks for past help. Mike --~--~-~--~~~---~--~~ 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: Django 1.0.2 foreign key display puzzle
Hi Kenneth I agree that on my reading of the literature what you say is right. Here is my actual line adjusted as you suggest: form = ListingForm(initial={'date': request.session['date'], 'source_id': '2',}) In this case the date field is correctly populated with the preset date, the source foreign key widget is not, thus the user has to make a choice. I want the choice that I presume to be correct to be already presented. Surely this must be possible? BTW I have tried every variation I can think of at the end of that line, with quotes, without quotes, and as a request.session value (that I know is set). Thanks for your reply. Mike On Jun 23, 1:08 pm, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > On Tuesday 23 June 2009 09:14:01 adelaide_mike wrote: > > > form = MyModelForm(initial={'myforeignkeyfieldname': myvalue}) > > assuming the foreignkey value exists, then you would have to insert it's id > into the field myforeignkeyfieldname_id. > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django 1.0.2 foreign key display puzzle
Having failed to get any takers to my earlier posts on this, I will keep it v. short: How do I preset a foreign key value in a Model Form? form = MyModelForm(initial={'myforeignkeyfieldname': myvalue}) does not do it. Surely this can be done? Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Preset foreign key in Model Form
Try again. I am new to Django and the web, so I do not know all the right vocabulary. Sorry. I need my ModelForm to be displayed, for creation of a new record, with a date field and a foreign key (pointing to the Source table) selector list aleady populated. I am doing this: form = ListingForm(initial={'date': request.session['date'], 'source': source,}) The date is correctly displayed. The foreign key selector is not set. I have tried all combinations I can think of for the source argument, such as: "source": request.session["source"] "source_id": source_id "source_id": srequest.session["source_id"] In each case a 'print' assures me the value is available. Manually selecting the 'source' and saving works correctly. I would be grateful for any assistance. Mike --~--~-~--~~~---~--~~ 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 preset a foreign key choice field in a ModelaaForm?
Oops werong action - incomplete message. I have a ModelForm: class ListingForm(ModelForm): class Meta: model = Listing that has a method that, for a new record, should set the ForeighKey field "source" to an object identified in the UserProfile. The "date" value is stored the same way: if request.method == 'GET': if listing_id > '0': listing=Listing.objects.get(pk=listing_id) form = ListingForm(instance=listing) else: print "In listings GET source=", request.session['source'] # thus proving that the "source" object is known. form = ListingForm(initial={'date': request.session['date'], 'source': request.session['source'], 'agent': request.session['agent']}) return render_to_response('wha/listing_form.html', {'form': form, 'source': request.session['source'], 'date': date, }) The "date" is shown correctly, the "source" is not, though the widget is populated with the available choices. What am I doing wrong here? TIA Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to preset a foreign key choice field in a ModelaaForm?
if request.method == 'GET': if listing_id > '0': listing=Listing.objects.get(pk=listing_id) form = ListingForm(instance=listing) else: print "In listings GET source=", request.session['source'] form = ListingForm(initial={'date': request.session['date'], 'source': request.session['source'], 'agent': request.session ['agent']}) #form = ListingForm(instance=listing) return render_to_response('wha/listing_form.html', { 'form': form, 'property': request.session['property'], 'agent': request.session['agent'], 'source': request.session['source'], 'date': dt, 'message': message} ) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to preset a value to a field on a ModelForm
Hi Newbie trying to preset a field on a form where the object is to be inserted. The snippet below does not do it. class FooForm(ModelForm): class Meta: model = Foo if request.method == 'GET': if foo_id > '0': foo=Foo.objects.get(pk=foo_id) form = FooForm(instance=foo)# this part works OK else: form = FooForm() foo=form.save(commit=False) foo.date = request.session['date']# we know request.session ['date'] has a value form = FooForm(instance=foo) What is a better way? TIA Mike --~--~-~--~~~---~--~~ 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: Searching posts to this group
Hmm. Sorry. I see it, for this list. But is there a way for the Snippets? On Jun 10, 6:12 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > Is there a way to search for a word in the Subject line or the text of > posts to this group? Same with the list of snippets. Scanning twenty > at a time (out of 1500 or more) seems a long way to see what exists. > > Mke --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Searching posts to this group
Is there a way to search for a word in the Subject line or the text of posts to this group? Same with the list of snippets. Scanning twenty at a time (out of 1500 or more) seems a long way to see what exists. Mke --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newb - Link users_extra_data table to built-in Users table - how?
Hi I need to store additional info about my users. The following in models.py raises a name error due to User. Have tried auth_users and Users as well. No joy. class User_settings(models.Model): user = models.ForeignKey(User,unique=True) current_date = models.DateField(null=True, blank=True) current_source = models.ForeignKey(Source) What is the correct name for the built-in user table? Mike --~--~-~--~~~---~--~~ 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 - record parent ID in child data entered by ModelForm
Thank you TiNo that works if altered slightly like so: if form.is_valid(): instance = form.save(commit=False) instance.street_id= request.session['street_id'] instance.save() I have been using Django for about ten days, and it requires very different thinking c/w "normal" desktop apps. Still heaps to learn. Thanks again. Mike On Jun 5, 6:15 pm, TiNo <tin...@gmail.com> wrote: > On Fri, Jun 5, 2009 at 11:04, adelaide_mike > <mike.ro...@internode.on.net>wrote: > > > Exception Value: 'PropertyForm' object does not support item > > assignment > > There you go. You can't do: > > > form['street']=request.session['street_id'] > > You can save the form instance first, without commiting, then set the street > the instance: > > if form.is_valid(): > instance = form.save(commit=False) > instance.street = request.session['street_id'] > instance.save() > form.save_m2m() > > see:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav... --~--~-~--~~~---~--~~ 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 - record parent ID in child data entered by ModelForm
Thanks for the offer. I have altered the function as suggested: def property_data(request, property_id='0'): message = '' st = request.session['street_id'] print "At start of property_data, request.method=", request.method print "At start of property_data, st=", st if request.method == "POST": form = PropertyForm(request.POST) form['street']=request.session['street_id'] print "form=", form if form.is_valid(): form.save() message='we are added' return HttpResponseRedirect('somewhere') And here is the traceback: Environment: Request Method: POST Request URL: http://localhost:8000/wha/address/1/add_property/ Django Version: 1.0.2 final Python Version: 2.5.1 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.auth', 'whasite.wha'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/Users/michael/Documents/Django Projects/whasite/../whasite/wha/ data.py" in property_data 35. form['street']=request.session['street_id'] Exception Type: TypeError at /wha/address/1/add_property/ Exception Value: 'PropertyForm' object does not support item assignment On Jun 5, 5:15 pm, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On Jun 5, 5:33 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > > > Another "in principle" question. My Street model is the parent of my > > Property model, many to one via foreign key. > > > User selects the street and I store it in request.session. User then > > gets to enter the property details in this form: > > > class PropertyForm(ModelForm): > > class Meta: > > model = Property > > exclude = ('street', 'price1', 'price2',) > > > and when the Add is clicked we do: > > > def property_data(request, property_id='0'): > > st = request.session['street_id'] > > print "At start of property_data, st=", st # debug, so I > > know it has the correct value > > if request.method == "POST": > > if property_id > '0': > > #do something > > else: > > form = PropertyForm(request.POST) > > form['street']=request.session['street_id'] > > if form.is_valid(): > > try: > > form.save() > > return > > HttpResponseRedirect('somewhere') > > except: > > message='database error in ADD' > > #debug, this is returned > > to the page > > Because all fields in property (except the foreign key street) either > > have data or are blank=True, the problem must? be the lack of the > > foreign key. (In admin I can add propertys). How do I get it into the > > data to be saved? > > > Mike > > Don't guess. Look at what the traceback actually says. Especially, > don't use a raw 'except', as that will swallow all types of errors. > Leave out the try/except for now, and let Django print the traceback > page, then show us what it says. > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Newbie - record parent ID in child data entered by ModelForm
Another "in principle" question. My Street model is the parent of my Property model, many to one via foreign key. User selects the street and I store it in request.session. User then gets to enter the property details in this form: class PropertyForm(ModelForm): class Meta: model = Property exclude = ('street', 'price1', 'price2',) and when the Add is clicked we do: def property_data(request, property_id='0'): st = request.session['street_id'] print "At start of property_data, st=", st # debug, so I know it has the correct value if request.method == "POST": if property_id > '0': #do something else: form = PropertyForm(request.POST) form['street']=request.session['street_id'] if form.is_valid(): try: form.save() return HttpResponseRedirect('somewhere') except: message='database error in ADD' #debug, this is returned to the page Because all fields in property (except the foreign key street) either have data or are blank=True, the problem must? be the lack of the foreign key. (In admin I can add propertys). How do I get it into the data to be saved? Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newb - how to remember the main course while we select the dessert
My latest problem can be illustrated thus: In the first form we select the main course - spam or eggs. In the next form we select the dessert - ice cream or mud cake, and in the third form we select the after-dimmer drink - tea or coffee. How is the proper way to remember the choice made in form 1 and form 2? I assume I need to pass the main_course_id to the second form and get it back so I can pass it and dessert_id to the third form and then get all three back, main_course_id, dessert_id and drink_id so they can be sent to the kitchen. I had thought that the form wizard might help but on reflection I now doubt that. Any clues welcome Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newb problem with form wizard
My non-wizard templates are in this directory, all working as expected: my_wha_templates/wha/ I have built a form wizard in my whasite.wha.forms.py exactly as per the docs. I have pasted the suggested template HTML into a file: my_wha_templates/wha/contact/forms/wizard.html My urls.py is within the app and is as per the docs. So I try http://localhost:8000/wha/contact This raises an exception: TemplateDoesNotExist at wha/contact/ Exception value forms/wizard.html I seem to have something in the wrong place or with the wrong name. Where or what should it be? Thanks for past and future help. Feeling a bit like the Black Knight here. Mike --~--~-~--~~~---~--~~ 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 pls help with stored values
Yes V, thank you. Thats clearly what I need here. Mike On Jun 3, 4:01 pm, V <viktor.n...@gmail.com> wrote: > I'm not sure that I understood your problem, but form wizards might be > what you are looking > forhttp://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/ > I guess > > On Jun 3, 8:04 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > I am a newbie with Django and web stuff, but have long experience with > > desktop databases. > > > In Django my user runs through a series of template.htmls choosing a > > particular great great grandchild object, a house. > > > Then she must select a sales agent object. Just in general, how do I > > arrange for the house object to be put on hold (in my other life I > > would have used an instance or local variable) while we are selecting > > the sales agen? > > > A brief example would be wonderful, but a pointer to some text would > > be welcome too. Have looked at context template processors but did > > not think it relevant. > > > TIA > > > Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie pls help with stored values
I am a newbie with Django and web stuff, but have long experience with desktop databases. In Django my user runs through a series of template.htmls choosing a particular great great grandchild object, a house. Then she must select a sales agent object. Just in general, how do I arrange for the house object to be put on hold (in my other life I would have used an instance or local variable) while we are selecting the sales agen? A brief example would be wonderful, but a pointer to some text would be welcome too. Have looked at context template processors but did not think it relevant. TIA Mike --~--~-~--~~~---~--~~ 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 Django 1.0 help with create object, uopdate object
Thanks Tim for your detailed reply. I have it now. HTML was incorrect, and yes, now I understand better what is happening I have rewritten the view as you suggest. I split it up only to try to make clearer to me what was happening. Thanks again. Mike On Jun 2, 1:48 am, Tim Sawyer <list.dja...@calidris.co.uk> wrote: > Hi, > > I think the recommended approach in django is for forms to submit to the > current URL and for the view to decide whether the request is to display the > form (a HTTP GET) or submit the form (HTTP POST). I'd suggest that you > attempt to re-write this way. > > Your error could be caused by nothing in the POST, if your form is wrong - can > you post your HTML? You could also put an intentional error into your view > which will cause the Django error window to pop up - this contains details of > the POST variables in the request. > > Here's a well commented and cleaner version of the code I posted earlier: > > def edit_result(request, pResultSerial): > """ > This method in views.py takes a single parameter from the url - the serial of > an object. It will either display the HTML form to edit that object, or it > will accept the submit of a form containing the edited data and save it to the > database > """ > # Get an object from the database, using the passed in serial. Raise a 404 > # page not found if the object isn't found > lContestResult = get_object_or_404(ContestResult, pk=pResultSerial) > > # if we are doing a post, the we have data to save. Process it. > if request.method == 'POST': > > # create a form instance, populating it with the data in the object > # selected from the database earlier, then overwriting it with the > # stuff submitted in the HTML form > form = ContestResultForm(request.POST, instance=lContestResult) > > # run the form validation > if form.is_valid(): > # save the object inside the form instance to the database > form.save() > > # our save completed, so redirect to the next url you want to go to > return HttpResponseRedirect('/url/after/successful/save') > > else: > # we aren't doing a POST, so we need to create a form > # instance ready for it to be edited in the HTML. > # we create this and populate it from the object we selected above > form = ContestResultForm(instance=lContestResult) > > # show the HTML form to allow the user to edit the object > # note that this is indented to the same level as the > # "if request is a POST" check, so that if the form.is_valid() check fails, > # we go back and show the HTML again with the form containing errors. > return render__to_response('contests/edit_result.html', > {'form': form}) > > Hope that helps! > > Tim. > > On Monday 01 June 2009 15:56:24 adelaide_mike wrote: > > > Thanks for your response Tim. However, you lost me a bit there, I am > > a real newbie. I have narrowed my question down to this: > > > # in views.py: > > > class PropertyForm(ModelForm): > > class Meta: > > model = Property > > > def property_update(request, property_id='0', street_id='0'): > > print "data/property_save, request.method= ", request.method > > message = '' > > # we attempt to update an edit > > print "attempt to update" > > form = PropertyForm(request.POST) > > if form.is_valid(): > > form.save() > > > return render_to_response('wha/property_form.html', {'form': form, > > 'message': message}) > > > My property_update function is called when the form Save button is > > clicked. The various "print" commands operate as expected. However, > > the validation fails and a form with no data is returned with > > "required data" labels. I conclude the line: > > form = PropertyForm(request.POST) > > does not populate the validation form. What have I got wrong here? > > TIA > > > Mike > > > On Jun 1, 8:14 pm, Tim Sawyer <list.dja...@calidris.co.uk> wrote: > > > On Monday 01 June 2009 01:38:30 adelaide_mike wrote: > > > > I found a really clear explanation of creating and updating database > > > > objects in SAMS TeachYourself Django, but it appears to be for v > > > > 0.96. > > > > > I have looked at "Creating forms from models" in the documentation, > > > > and about one-third the way down it shows the following: > > > > > # Create a form instance from POST data. > > > > > >>> f = ArticleForm(request
Re: Newbie Django 1.0 help with create object, uopdate object
Thanks for your response Tim. However, you lost me a bit there, I am a real newbie. I have narrowed my question down to this: # in views.py: class PropertyForm(ModelForm): class Meta: model = Property def property_update(request, property_id='0', street_id='0'): print "data/property_save, request.method= ", request.method message = '' # we attempt to update an edit print "attempt to update" form = PropertyForm(request.POST) if form.is_valid(): form.save() return render_to_response('wha/property_form.html', {'form': form, 'message': message}) My property_update function is called when the form Save button is clicked. The various "print" commands operate as expected. However, the validation fails and a form with no data is returned with "required data" labels. I conclude the line: form = PropertyForm(request.POST) does not populate the validation form. What have I got wrong here? TIA Mike On Jun 1, 8:14 pm, Tim Sawyer <list.dja...@calidris.co.uk> wrote: > On Monday 01 June 2009 01:38:30 adelaide_mike wrote: > > > > > I found a really clear explanation of creating and updating database > > objects in SAMS TeachYourself Django, but it appears to be for v > > 0.96. > > > I have looked at "Creating forms from models" in the documentation, > > and about one-third the way down it shows the following: > > > # Create a form instance from POST data. > > > >>> f = ArticleForm(request.POST) > > > # Save a new Article object from the form's data. > > > >>> new_article = f.save() > > > # Create a form to edit an existing Article. > > > >>> a = Article.objects.get(pk=1) > > >>> f = ArticleForm(instance=a) > > >>> f.save() > > > # Create a form to edit an existing Article, but use > > # POST data to populate the form. > > > >>> a = Article.objects.get(pk=1) > > >>> f = ArticleForm(request.POST, instance=a) > > >>> f.save() > > > I understand what these code fragments are intended to do (I think) > > but I am not clear as to how to use them. Can someone point me to a > > more fully displayed example? TIA > > > Mike > > Here's an example from my code, does this help? > > Tim. > > def edit_result(request, pResultSerial): > """ > Edit a single result row > """ > lContestResult = get_object_or_404(ContestResult, pk=pResultSerial) > if request.user != lContestResult.owner: > raise Http404() > if request.method == 'POST': > form = ContestResultForm(request.POST, instance=lContestResult) > if form.is_valid(): > form.save() > return > HttpResponseRedirect(reverse('bbr.contests.views.single_contest_event', > args=[lContestResult.contest_event.contest.slug, > lContestResult.contest_event.date_of_event])) > else: > form = ContestResultForm(instance=lContestResult) > > return render_auth(request, 'contests/edit_result.html', {'form': form, > 'ContestResult' : lContestResult}) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie Django 1.0 help with create object, uopdate object
I found a really clear explanation of creating and updating database objects in SAMS TeachYourself Django, but it appears to be for v 0.96. I have looked at "Creating forms from models" in the documentation, and about one-third the way down it shows the following: # Create a form instance from POST data. >>> f = ArticleForm(request.POST) # Save a new Article object from the form's data. >>> new_article = f.save() # Create a form to edit an existing Article. >>> a = Article.objects.get(pk=1) >>> f = ArticleForm(instance=a) >>> f.save() # Create a form to edit an existing Article, but use # POST data to populate the form. >>> a = Article.objects.get(pk=1) >>> f = ArticleForm(request.POST, instance=a) >>> f.save() I understand what these code fragments are intended to do (I think) but I am not clear as to how to use them. Can someone point me to a more fully displayed example? TIA Mike --~--~-~--~~~---~--~~ 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, hierarchical models, url.py problem
Thanks Gabriel. I think it would be good if the tutorial included a three-level hierarchy sowing how to handle the url.py and views.py for the third layer. Anyway, I now understandone step more. Thanks and regards On May 31, 11:46 am, Gabriel <gabriel@gmail.com> wrote: > adelaide_mike escribió: > > > urlpatterns = patterns('whasite.wha.views', > > > (r'^address/{{street.id}}/(?P\d+)/$', 'select_event'), > > (r'^address/(?P\d+)/$', 'select_property'), > > (r'^address/$', 'select_street'), > > (r'^$', 'address'), > > ) > > (r'^address/(?P\d+)/(?P\d+)/$', 'select_event'), > > Url patterns use regular expressions. > > - -- > Kind regards. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie, hierarchical models, url.py problem
I have model classes Suburb, Street ,Property and Event. Each has a name , a foreign key to the model above, and the id provided by default. In the admin everything is fine. The template address.html has a search field and returns a startswith query that generates streets. Clicking a line in the klist of streets prompts the second line of the urlpatterns to build a list of propertys. Clicking a line in propertys returns wha/address/1/3 where 1 is the id of the street and 3 is the id of the property. But line 1 in urlpatterns does not work. I have tried everything, as they say, and have read all the docs I can find, to no avail. I am sure {{street.id}} is incorrect but I do not know what should replace it. from django.conf.urls.defaults import * urlpatterns = patterns('whasite.wha.views', (r'^address/{{street.id}}/(?P\d+)/$', 'select_event'), (r'^address/(?P\d+)/$', 'select_property'), (r'^address/$', 'select_street'), (r'^$', 'address'), ) Have looked at mptt and Pyjamas, both of which seem relevant but I want to crawl before running. Any help would be much appreciated. TIA Mike --~--~-~--~~~---~--~~ 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 include parent name in list of children?
Thank you Tom and Daniel. Starting to see some light here. Mike On May 28, 1:25 am, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On May 27, 2:59 pm, Tom Evans <tevans...@googlemail.com> wrote: > > > > > On Wed, 2009-05-27 at 06:27 -0700, adelaide_mike wrote: > > > Very beginner here. > > > > My model has two classes, Suburb, the parent, and Street, the child: > > > > class Suburb(models.Model): > > > suburb_name = models.CharField(max_length=72) > > > postcode = models.CharField(max_length=4) > > > def __unicode__(self): > > > return '%s %s' % (self.suburb_name, self.postcode) > > > > class Street(models.Model): > > > street_name = models.CharField(max_length=72) > > > suburb = models.ForeignKey(Suburb) > > > def __unicode__(self): > > > return '%s, %s' % (self.street_name, > > > unicode(self.suburb)) > > > > In my view I populate the variable streets: > > > > def search_street(request): > > > query = request.GET['query'] > > > streets = Street.objects.filter(street_name__istartswith = query) > > > # Do a case-insensitive search on the starts-with name of the > > > street. > > > return render_to_response('wha/street_select.html', {'streets': > > > streets, 'query': query}) > > > > The page search_select.html contains: > > > > > > > {% for street in streets %} > > > {{street.street_name}} > > > {{suburb.suburb_name}} > > > {% endfor %} > > > > > > > This displays only the street name, and not the suburb_name. I need > > > it to display as in the admin ie: > > > street_name suburb_name postcode > > > > What change should I make or where can I see an example? > > > > TIA > > > > Mike > > > {{ street.suburb.suburb_name }} > > Note that although this does give the right answer, it'll be very > inefficient in terms of database access, as you'll need to hit the > database to look up the suburb on every single street. > > Easy fix - add select_related() to the lookup in the view: > streets = Street.objects.filter(street_name__istartswith = > query).select_related() > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to include parent name in list of children?
Very beginner here. My model has two classes, Suburb, the parent, and Street, the child: class Suburb(models.Model): suburb_name = models.CharField(max_length=72) postcode = models.CharField(max_length=4) def __unicode__(self): return '%s %s' % (self.suburb_name, self.postcode) class Street(models.Model): street_name = models.CharField(max_length=72) suburb = models.ForeignKey(Suburb) def __unicode__(self): return '%s, %s' % (self.street_name, unicode(self.suburb)) In my view I populate the variable streets: def search_street(request): query = request.GET['query'] streets = Street.objects.filter(street_name__istartswith = query) # Do a case-insensitive search on the starts-with name of the street. return render_to_response('wha/street_select.html', {'streets': streets, 'query': query}) The page search_select.html contains: {% for street in streets %} {{street.street_name}} {{suburb.suburb_name}} {% endfor %} This displays only the street name, and not the suburb_name. I need it to display as in the admin ie: street_name suburb_name postcode What change should I make or where can I see an example? TIA Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Field xyz that is missing from the form
Hi Be gentle with me. I am on my 7th day with Django. I have completed the tutorial for 1.0.2 and have started building an app that has three models in a hierarchy, Suburb, Street and Property. All are available in the basic Admin, working very well. Now I emulated the tutorial by building a SuburbAdmin function (similar to PollAdmin in the tute) as shown in the first half of my admin.py here: http://dpaste.com/47454/ This half works fine by itself. However, when I add the second half of that admin.py to attempt to do a similar thing with Street and Property I get an ImproperyConfigured error stating: 'StreetAdmin.fieldsets[1][1]['fields']' refers to field 'number' that is missing from the form. If I comment out the line ('Property', {'fields': ['number'], 'classes': ['collapse']}), it all (both SuburbAdmin and StreetAdmin) works as advertised except that the StreetAdmin shows every column in the Property table (understandably). Can someone pls tell me what faults there are in my admin.py? TIA Mike --~--~-~--~~~---~--~~ 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: Django 1.0.2 show grandparent in admin
Spot on. Thanks Karen On May 24, 11:08 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Sat, May 23, 2009 at 9:57 PM, adelaide_mike > <mike.ro...@internode.on.net>wrote: > > > > > > > First, please forgive my post to the Django developers group. I mis- > > understood the terminology. > > > I am a total beginner in Django but have long experience with Omnis. > > My data stores addresses in three tables named > > Suburb, (columns are id, name) > > Street, (columns are id, name, suburb_id) > > Property (columns are id, number, street_id) > > > I have the Admin all working well (as per the Poll tutorial) but need > > to extend it. I can "Add a property" and on that page I see a pick > > list for the street name. Can I get that pick list to show the suburb > > name also by somehow concatenating the street and suburb names > > together? > > > In my models.py I have, for each class (using Street as an example): > > def__unicode__(self) > > return self.name > > > I have not found an exception-free way of changing the last line above > > to involve the parent class. Any help would be greatly appreciated. > > Something like (for Street): > > def __unicode__(self): > return u'%s, %s)' % (self.name, unicode(self.suburb)) > > (assuming Suburb's __unicode__ returns its name) should do it. (And > assuming suburb is not allowed to be null -- if it is then you'll need to > test for a null suburb and fall back to just returning the street name and > not attempting to access a non-existant related object.) > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django 1.0.2 show grandparent in admin
First, please forgive my post to the Django developers group. I mis- understood the terminology. I am a total beginner in Django but have long experience with Omnis. My data stores addresses in three tables named Suburb, (columns are id, name) Street, (columns are id, name, suburb_id) Property (columns are id, number, street_id) I have the Admin all working well (as per the Poll tutorial) but need to extend it. I can "Add a property" and on that page I see a pick list for the street name. Can I get that pick list to show the suburb name also by somehow concatenating the street and suburb names together? In my models.py I have, for each class (using Street as an example): def__unicode__(self) return self.name I have not found an exception-free way of changing the last line above to involve the parent class. Any help would be greatly appreciated. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---