Model Methods and displaying in template?

2009-08-09 Thread rmschne
I'm looking for the right syntax for inside a template to display a model variable that is actually not a field in the database (defined by the mode), but a Model method. Class Member(model.Models): id = models.IntegerField(primary_key=True, db_column='ID') lname = models.CharField(max_le

Re: Model Methods and displaying in template?

2009-08-09 Thread rmschne
int it was). I fixed the missing tab and I put a few more bits of defensive coding. Thanks! On Aug 9, 12:55 pm, Daniel Roseman wrote: > On Aug 9, 12:42 pm, rmschne wrote: > > > > > > > I'm looking for the right syntax for inside a template to display a > > m

Unicode Text for Dictionary Keys ok for Templates?

2009-08-16 Thread rmschne
I'm extracting data from a database and then cross-tabbing the data (with some Python) code to create a list of dictionary data. Because the key names are derived from data in the database, and the database is composed of unicode text, the keys are unicode, e.g. here are three records in the list

Re: Unicode Text for Dictionary Keys ok for Templates?

2009-08-17 Thread rmschne
Karen, Humm. Ah. Yes. Obvious, isn't it! Thanks. On Aug 16, 8:13 pm, Karen Tracey wrote: > On Sun, Aug 16, 2009 at 1:28 PM, rmschne wrote: > > > I'm extracting data from a database and then cross-tabbing the data > > (with some Python) code to create a list

Re: Making Custom Model Methods to Work

2008-08-24 Thread rmschne
Daniel You helped a lot. You are right that my code wasn't clear. I only extracted snipets and forgot bits, e.g. talk _title and speaker_title which are in the model but not in what I reported. Frankly, all I'm trying to do right now is experiment to learn how this works. Eventually, I have a

Making Custom Model Methods to Work

2008-08-24 Thread rmschne
I'm new to Django, and have played with Python for a few years on and off (not a real programmer). I'm keen to use Django to explore some data because of its custom data models which I plan to rely on extensively (putting the complex code there). Try as I might, I can't see how to get them to wo

Avoiding MIME_BASE64_TEXT SpamAssassin Test when sending Email From Django?

2009-11-23 Thread rmschne
I'm using Django's email sending functions (http:// docs.djangoproject.com/en/dev/topics/email/#topics-email) to send mail. I construct the simple HTML mail with a small bit of Python code which is based on data from a database accessed via Django and using a Django template to construct the html

Re: Avoiding MIME_BASE64_TEXT SpamAssassin Test when sending Email From Django?

2009-11-24 Thread rmschne
Jerek, Thanks ... starting now. -- 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 m

How to update one field in one existing record via Django?

2009-12-16 Thread rmschne
Am I missing something? I want to be able to update just one field in one records of a database via the Django data model. If I create an object for that record and update that one field, via b=Att(fieldname=a_variable) b.save It creates a new record with all other fields blank. For simplicity

Re: How to update one field in one existing record via Django?

2009-12-16 Thread rmschne
te: > > try: > >  b = Att.objects.get( pk = whatever_you_like ) > >  b.fieldname = a_variable > >  b.save > > except Att.DoesNotExist: > >  print "oy vey" > > > you could also replace b.fieldname = ... with: > > b.__setattr__( 'f

Creating PHP code via template? Ignores PHP code enclosed in print <<

2009-12-30 Thread rmschne
I am trying to include some PHP code in Django template to created PHP file(s) which get executed on the web server when copied across. I'm finding that PHP code that is inside of <

Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-14 Thread rmschne
As I understand, in Django/Python, True is 1 and False=0. And when connected to the database, we use a TinyInt for that variable and assign it to a NullBooleanField. Problem is that some people use their PC's with a Microsoft Access based front end to the database (MySQL). The forms use check-bo

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-14 Thread rmschne
Tom, Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit t

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-14 Thread rmschne
bly be there now. On Jul 14, 3:57 pm, Tom Evans wrote: > On Wed, Jul 14, 2010 at 1:45 PM, rmschne wrote: > > As I understand, in Django/Python, True is 1 and False=0.  And when > > connected to the database, we use a TinyInt for that variable and > > assign it to a NullBoole

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-16 Thread rmschne
Tom, Thanks ... Can I get a bit more of your brain power. I'm struggling with understanding the custom-model-fields document sufficient to allow me to do it. At the top of the models.py files, I put in: class MyNullBooleanField(models.NullBooleanField): """Designed to work with how Microsoft

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-16 Thread rmschne
(While slapping my forehead) ... figured it out. Have to remove "models" as a prefix to MyNullBooleanField, as of course, the field definition is not in models. forinvoice.MyNullBooleanField(null=True, db_column='forinvoice', blank=True) Now to get on debugging the functionality of the new f

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-16 Thread rmschne
To complete the story, in case someone finds this in the future, I ended up with the following which at the time of this writing seems to work: class MyNullBooleanField(models.NullBooleanField): """Designed to work with how Microsoft Access stores booleans as -1 and 0 into MySQL. The to_py

can foreign key fields be empty?

2010-07-18 Thread rmschne
I have two tables where one is a foreign key for the other. For some of the "children" there is no "parent". Hence I want to leave the linking field NULL (empty) in the child database table. I am having trouble making a queryset which finds all children without parents. I was thinking looking fo

Re: can foreign key fields be empty?

2010-07-18 Thread rmschne
Thanks ... but where does "None=True" go? On Jul 18, 7:08 pm, Subhranath Chunder wrote: > A simple "None=True" should work. > > Thanks, > Subhranath Chunder. > > > > On Sun, Jul 18, 2010 at 11:25 PM, rmschne wrote: > > I have two tables where o

Re: can foreign key fields be empty?

2010-07-19 Thread rmschne
That's what's vexing me. I've done it now with a SQL query to return a Python list. Not as elegant, but appears to work . Thanks. On Jul 18, 9:05 pm, Ramiro Morales wrote: > On Sun, Jul 18, 2010 at 4:33 PM,rmschne wrote: > > Thanks ... but where does "None=True" go

Re: can foreign key fields be empty?

2010-07-21 Thread rmschne
Em, Perfect. Thanks for taking the time on this. Greatly appreciated!! I'm going to re-write the code here. (in all my reading, I missed _isnull field lookup) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email

distinct() ?

2010-07-21 Thread rmschne
I'm trying to use the distinct() and it's giving me unexpected results. Surely it's something simple, but I can't spot it. I've referred to http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct In SQL, it would be: select distinct status from members; in Django I am using: status

Re: distinct() ?

2010-07-21 Thread rmschne
Yep. (as I slap my forehead). I read that but erroneously concluded that since I had no sort_by on the query, I didn't pursue it. There is a default ordering in the model. I've solved the problem by passing the returned dictionary through my own distinct() function which strips out duplicates.

Re: distinct() ?

2010-07-21 Thread rmschne
Member.objects.values('status').order_by('status').distinct() from jaymzcd works perfectly. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this gro

Re: distinct() ?

2010-07-21 Thread rmschne
ies with redundant keys this > way. > > Thanks, > Subhranath Chunder. > > > > On Wed, Jul 21, 2010 at 11:40 PM, rmschne wrote: > > Member.objects.values('status').order_by('status').distinct()  from > > jaymzcd works perfectly. Thank

Crashing Dev Server (or Browser?)

2010-08-01 Thread rmschne
I have a small Django app that until now has been used simply for access to the data (in MySQL) for doing computations/reporting and outputting results to files. Have not been using the ADMIN module or Dev server or anything. Now that hard part of this work, I'm starting to get the admin app go

Re: Crashing Dev Server (or Browser?)

2010-08-01 Thread rmschne
tem/Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/lib-dynload/zlib.so 0x10154 -0x101546fff +_mysql.so ??? (???) <71D7CF20- D04F-3CA2-D091-4CA096A7E8D9> /Users/rmschne/.python-eggs/ MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so 0x

Re: Crashing Dev Server (or Browser?)

2010-08-01 Thread rmschne
Sorted. But gosh, why did this simple error crash Python? for both these models, a recent change was to remove a database field and replace with function in the model. However I neglected to change the __unicode__() method for that model to change the the variable from "self.abcdefg" to "self.ab

how to query foreign keys down more than one level

2010-08-07 Thread rmschne
I have a model like that I would like query down more than one level (using my nomenclature). class Library(models.Model) branch=models.CharField(max_length=100) class Book(models.Model) libraryid=models.ForeignKey(Library,related_name="books") class Chapter(models.Model) bookid=models.For

Re: how to query foreign keys down more than one level

2010-08-07 Thread rmschne
Thanks to Steve and Daniel. Cool. I'm learning as I go about naming fields. Going back and fixing where possible (but sometimes a lot of work). Agree right to do the first time; but learning! -- You received this message because you are subscribed to the Google Groups "Django users" group. To

QuerySet returned based on a Python List?

2010-03-28 Thread rmschne
I have a query in Django with returns a queryset. c1=Contact.objects.filter(hostid__tablename=s) where "s" is a string holding a tablename. What I want to do is have Django return a query set where "s" is not just a string, but a Python list, e.g. ['01','03','54']. How do i construct a qu

Re: QuerySet returned based on a Python List?

2010-03-28 Thread rmschne
> > c1=Contact.objects.filter(hostid__tablename__in=list_of_names) > > The ORM is cool. Ah. "in". how could I have missed that in the doc. Too much staring and not enough reading, I guess. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" g

Query Set involving Model Method

2011-01-16 Thread rmschne
Following is an extract of a Model I'm using. I'd like to be able to query it to get a query set return that uses one of the Model Definitions, e.g. get all the Hosts where "complete=True" where 'complete' is a model definition. I know the nomenclature to use when exclude/include on a field in th

Re: Query Set involving Model Method

2011-01-16 Thread rmschne
Thanks. I'm still messing with this; but don't think it quite what I'm looking for. I want/need the Model Definition function complete() for use at the record level. I did this as a function since the rules are not based simply on the value of the fields. Ideally, I'd like to have the class Dinn

Re: Query Set involving Model Method

2011-01-16 Thread rmschne
n a good solution and it is better than complex queries in > terms of performance. > > On 16 янв, 19:16, rmschne wrote: > > > > > > > > > Thanks. I'm still messing with this; but don't think it quite what I'm > > looking for. > > > I want

Re: Query Set involving Model Method

2011-01-17 Thread rmschne
Much thanks to all. I could not get something like: gs=DinnerHost.objects.all().filter(complete()=True to work. probably think fingers on my side to get the nomenclature write; but I suspect not possible. While I liked the idea of computing a new field "complete" in the database which is updated

All of the sudden getting TemplateDoesNotExist error

2012-07-24 Thread rmschne
I have made no changes to settings.py. Honest. I'm running Django 1.4.0 alpha. The variable TEMPLATE_DIRS is pointing to a folder which exists and the template 'directory.html' i wish to load in in that folder, /Users/rmschne/Documents/source/django/projects/socmgmt/template

Re: All of the sudden getting TemplateDoesNotExist error

2012-07-25 Thread rmschne
her things, from content held in the database. I simply copy the HTM files to the server on change. Sort of taking the approach "it works, don't break it on purpose". I'll do an upgrade to current version this week. On Wednesday, 25 July 2012 02:33:17 UTC+1, Karen Tracey

TemplateDoesNotExist Error...

2012-11-19 Thread rmschne
I have moved to a new laptop which is both my development and production platform. The only change in infrastructure is that I run Python, Django, and all else in a virtual environment (VirtualEnv). I am not using Django to run on a web server. I have a function which produces a set of H

Re: TemplateDoesNotExist Error...

2012-11-19 Thread rmschne
Yes, with guidance from Django/Python, I am sure the error occurs there. Django/Pythyon presents the trace and the line number which causes the exception is reported to the command Line. However, I will look again at that line and all lines above. Yes, I know there is a "good" chance as the cl

Text Field stifles creating HTML

2013-04-11 Thread rmschne
Django 1.5.1. I have a data model with a Django TextField: notes=models.TextField(db_column='notes',blank=True) and in thy MySQL the 'notes' field is "TEXT". When I output the 'notes' field in a Django Template in a for loop, the template just stops. It does not go through the entire list of r

Re: Text Field stifles creating HTML

2013-04-11 Thread rmschne
Further debugging ... printed the HTML that is produced by the call to render and the HTML is created correctly. Thus, I have concluded the problem has nothing to do with Django. Closed. -- You received this message because you are subscribed to the Google Groups "Django users" group. To uns

Re: Re. My Django Book.

2015-07-31 Thread rmschne
I'm no way an advanced user, but I found the book simplistic and not worth it. Django's own documentation is much better https://docs.djangoproject.com On Thursday, 30 July 2015 21:35:16 UTC+1, Steve Burrus wrote: > > * Say I was wondering if anyone else has ever read this particulkar Django >

How to access Django data with the field name in text?

2016-11-14 Thread rmschne
I have a extracted all the field names from a Django model into a list called "fields", e.g. fields = [(f.name, f.verbose_name) for f in Meetingattendee._meta.get_fields()] I ask the user to select a record, e.g. att=Meetingattendee.objects.get(id=attid) where "attid" is the ID of the record

Re: How to access Django data with the field name in text?

2016-11-14 Thread rmschne
ant to do it like this > > setattr(att, "fname", "value_to_be_set") > > and to get the value > > first_name = getattr(att, "fname") > > On Mon, Nov 14, 2016 at 8:38 AM, rmschne > > wrote: > >> I have a extracted all the field names

Model Manager QuerySet over-ride class not working as expected

2014-11-02 Thread rmschne
I've upgraded to Django 1.7.1 Following the upgrade most (haven't tested all, but for all tested this true) the over-rided queryset is not functioning. when the code calls qs=Member.Active_objects.all() then all members are returned, not just those which confrom to the filter specified in

Re: Model Manager QuerySet over-ride class not working as expected

2014-11-02 Thread rmschne
:12:10 UTC, rmschne wrote: > > I've upgraded to Django 1.7.1 > > Following the upgrade most (haven't tested all, but for all tested this > true) the over-rided queryset is not functioning. > > when the code calls > qs=Member.Active_objects.all() > > then all mem

Re: Model Manager QuerySet over-ride class not working as expected

2014-11-03 Thread rmschne
Colin, Thanks... no, I'm saying anything about an "assert" statement as I did not use it. I'm saying that : when I call the main class object ("class Member"), the return is all records in the database (as expected). : when I call the custom subclass object (class MemberActive), I expect a fi

Re: Model Manager QuerySet over-ride class not working as expected

2014-11-03 Thread rmschne
anks! --rms On Monday, 3 November 2014 10:12:10 UTC, Daniel Roseman wrote: > > On Sunday, 2 November 2014 18:12:10 UTC, rmschne wrote: >> >> I've upgraded to Django 1.7.1 >> >> Following the upgrade most (haven't tested all, b

Re: Model Manager QuerySet over-ride class not working as expected

2014-11-03 Thread rmschne
Collin, Thanks ... no I'm not saying that as I did do any assert statements. When I add that to the main calling programme, it fails with an "Assertion Error". Having not used assert statements before, I'm not sure what that means. Can you help? What I am saying is that when from the callin

Unicode error in __unicode__(self) function

2017-05-08 Thread rmschne
I have a Django setup that has worked for a very long time. Yesterday I upgraded from Django 1.10 to 1.11.1 and am getting the error: raise DjangoUnicodeDecodeError(s, *e.args) django.utils.encoding.DjangoUnicodeDecodeErrorJón : 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not

Re: Unicode error in __unicode__(self) function

2017-05-08 Thread rmschne
17:22:42 UTC+1, Tom Evans wrote: > > What data is "Jón"? > > Is it u'J\xf3n' or something else? (print repr(self.fname)) > > Cheers > > Tom > > On Mon, May 8, 2017 at 5:10 PM, rmschne > > wrote: > > I have a Django setup that h

Re: Unicode error in __unicode__(self) function

2017-05-09 Thread rmschne
> I'm sorry - but this isn't your real error. > > You will see it in your WSGI daemon logs once you set DEBUG to false. > > > > This error is caused by Django trying to print the error using ascii codec > for the debug output (I haven't chased it down any further and I should > really repor

How to get Foreign Key Objects programmatically?

2017-10-29 Thread rmschne
I'm using Django as front end to a MySQL database. User interface is a terminal program, not a web site. I've written a very simple generic function to edit the fields of one record of a Django "object". It works fine for editing editable fields. User specifies which field, then is shown the c

How to properly use MySQL Generated Fields in Django

2019-04-15 Thread rmschne
I have a generated field in a MySQL table "alpha = upper(substr(`lname`,1,1))" where the field lname is a last name of a person. Idea is that I get a field of the first letter of the last name. In Django, I have in the table 'attendees' a field alpha = models.CharField("alpha", max_length=1,