Re: Unicode error in __unicode__(self) function
On Tuesday 09 May 2017 06:00:31 rmschne wrote: > > 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 report it). > > > > > > > > As said, your real error is somewhere else and that will probably > > make more sense. > > > > > > > > > > Melvyn Sopacua > > Melvyn, > > Thanks. I understand what you are saying. Obvious, but I didn't notice > that. However, I do think it's a Django bug. This app is not running > on a web server so there is no WSGI daemon. Ah yes! That triggers a memory. Since `python manage.py runserver` runs on terminal the codec is set to ascii (even when using a UTF-8 locale). So set debug to false and see what comes up in the console. Another way is to temporarily change the data to ascii. It should then still yield an error and that is your real one. > Do you have a suggestion > on what I can do to get a better detection of the error to enable > reporting it? Since runserver crashes, your options are limited. You could maybe construct a test case using django.test.Client[1] and see what is triggered. -- Melvyn Sopacua [1] https://docs.djangoproject.com/en/1.11/topics/testing/tools/#the-test-client -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2030225.42xNKJQA4H%40devstation. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
On May 9, 2017 11:42 AM, Melvyn Sopacua wrote: > I'm sorry - but this isn't your real error. Your error is in another castle? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5911f4a1.d2d61c0a.786e9.2a60SMTPIN_ADDED_MISSING%40gmr-mx.google.com. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
Paste the whole stack traceof the error On 5/9/17, rmschne wrote: > > >> 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 report it). >> >> >> >> As said, your real error is somewhere else and that will probably make >> more sense. >> >> >> >> -- >> >> Melvyn Sopacua >> > > Melvyn, > > Thanks. I understand what you are saying. Obvious, but I didn't notice > that. However, I do think it's a Django bug. This app is not running on a > web server so there is no WSGI daemon. Do you have a suggestion on what I > can do to get a better detection of the error to enable reporting it? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/b3ed676d-811a-4c53-b176-bd460f5dd54a%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei13o3uH%2BVZK%3D6BE7tvf82KW6ccRPrP%3DfcHwZVyY9PydFA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
> 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 report it). > > > > As said, your real error is somewhere else and that will probably make > more sense. > > > > -- > > Melvyn Sopacua > Melvyn, Thanks. I understand what you are saying. Obvious, but I didn't notice that. However, I do think it's a Django bug. This app is not running on a web server so there is no WSGI daemon. Do you have a suggestion on what I can do to get a better detection of the error to enable reporting it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b3ed676d-811a-4c53-b176-bd460f5dd54a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
On Monday 08 May 2017 09:10:15 rmschne wrote: > 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 in > > range(128). 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 report it). As said, your real error is somewhere else and that will probably make more sense. -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9764105.YSOjKmLg3v%40devstation. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
Yes, it is the first name of a person with a European name, who it's got that "ó" character. My understanding that it is Unicode. The variable prints ok in the rest of the code to the screen and in Django templates, but this __unicode_(self) method fails. On Monday, 8 May 2017 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 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 in > > range(128). You passed in ( > 'soc_util.models.Meetingattendee'>) > > > > when in the code simply printing the "Meetingattendee" object with > > > > def __unicode__(self): > > print self.fname > > return self.fname > > > > The above is a simplified version. The error first cropped up on the > more > > complex version > > > > def __unicode__(self): > > s=u'%s: %s, %s %s, %-12s, %s %s, %s, INV:%s, PO:%s, ItemCode:%s' > % > > (self.id,self.meeting.date.strftime("%d-%b-%Y"),self.table,self.seat,\ > > self.attendeestatus.status,self.fname, self.lname, > > self.affiliation, \ > > self.invoiceno,self.ponumber,self.itemcode) > > return s > > > > where I eventually determined that the code was not working when working > the > > field self.fname. > > > > self.fname fails when it is "Jón". Works fin with "Jon", of course. > > > > I have not tried to revert back to Django 1.10, but i guess that's the > next > > step unless there is something in Django 1.11.1 that was changed that > > affects this. I can't find anything mentioned in the release notes. > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "Django users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to django-users...@googlegroups.com . > > To post to this group, send email to django...@googlegroups.com > . > > Visit this group at https://groups.google.com/group/django-users. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/django-users/4d37cc78-7fe9-41b6-bcba-eb788465e54f%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e450ce55-cafa-4cb3-adda-6decea1c87cf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Unicode error in __unicode__(self) function
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 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 in > range(128). You passed in ( 'soc_util.models.Meetingattendee'>) > > when in the code simply printing the "Meetingattendee" object with > > def __unicode__(self): > print self.fname > return self.fname > > The above is a simplified version. The error first cropped up on the more > complex version > > def __unicode__(self): > s=u'%s: %s, %s %s, %-12s, %s %s, %s, INV:%s, PO:%s, ItemCode:%s' % > (self.id,self.meeting.date.strftime("%d-%b-%Y"),self.table,self.seat,\ > self.attendeestatus.status,self.fname, self.lname, > self.affiliation, \ > self.invoiceno,self.ponumber,self.itemcode) > return s > > where I eventually determined that the code was not working when working the > field self.fname. > > self.fname fails when it is "Jón". Works fin with "Jon", of course. > > I have not tried to revert back to Django 1.10, but i guess that's the next > step unless there is something in Django 1.11.1 that was changed that > affects this. I can't find anything mentioned in the release notes. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/4d37cc78-7fe9-41b6-bcba-eb788465e54f%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1Lw_gfZANGr95XFM2RSoRVemtnv3YSvC3zK1FTgbnSiGg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Unicode error in __unicode__(self) function
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 in range(128). You passed in () when in the code simply printing the "Meetingattendee" object with def __unicode__(self): print self.fname return self.fname The above is a simplified version. The error first cropped up on the more complex version def __unicode__(self): s=u'%s: %s, %s %s, %-12s, %s %s, %s, INV:%s, PO:%s, ItemCode:%s' % (self.id,self.meeting.date.strftime("%d-%b-%Y"),self.table,self.seat,\ self.attendeestatus.status,self.fname, self.lname, self.affiliation, \ self.invoiceno,self.ponumber,self.itemcode) return s where I eventually determined that the code was not working when working the field self.fname. self.fname fails when it is "Jón". Works fin with "Jon", of course. I have not tried to revert back to Django 1.10, but i guess that's the next step unless there is something in Django 1.11.1 that was changed that affects this. I can't find anything mentioned in the release notes. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4d37cc78-7fe9-41b6-bcba-eb788465e54f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
result of filter query returning empty because of def __unicode__(self)
Does adding a def __unicode__(self): method into a model affect the queries being returned ? I am currently experiencing a situation in which the presence of def __unicode__(self): in the model is interfering with the results being returned. These two are my models class modelLabTestName(models.Model): test_category = models.ForeignKey(modelLabCategory) test_name = models.CharField(max_length=128, unique=True , default="None") def __unicode__(self): return self.test_name #-->--- Line A #return "Test Name : " + self.test_name --->--- Line B class modelNormalLabTest(models.Model): test_name = models.ForeignKey(modelLabTestName,default=None) field_name = models.CharField(max_length=128) field_value = models.CharField(max_length=128) Now notice in the above there are two lines A and B. Currently Line B is commented and this query works and I get back an object lab_entries= modelNormalLabTest.objects.filter(test_name__test_name="ABC") However if I replace return self.test_name in the model modelLabTestName with this instead (Line B) return "Test Name : " + self.test_name The query fails (i.e - No object is returned) My question is why is this happening and if there is any way for me to fix this issue. I already checked the value of the test_name property with the following statement and it is returning the correct value t = modelLabTestName.objects.all()[0].test_name #t = "ABC" then why is lab_entries= modelNormalLabTest.objects.filter(test_name__test_name="ABC") or even this modelLabTestName.objects.get(test_name="ABC"); returning nothing ? when the model modelLabTestname has the following method in it def __unicode__(self): return "Test Name : " + self.test_name Any suggestions would be appreciated. I am using Django (1.10.5) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb0e5164-751e-4a85-b71f-72e4c69d49d1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
On Tue, Aug 26, 2014 at 12:22 PM, Przemek Ciborowski wrote: > > So to be more clearly, let create new django project with one application for > example with name networks. > Add those lines to the networks/models.py: > > class Vlan(models.Model): > > name = models.CharField(max_length=30, name='Vlan name') "name" is not an argument for CharField - do you mean verbose_name? I suspect this error causes Vlan.name to not be defined. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1K34Lr8AXHBqdd9QqdGC%2BS7nMU1MjqZW9yYeu%2Bn%3DTDbrA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Thank you a lot! James & Tundebabzy - Thanks:) It was the mistake. Regards Przemek W dniu wtorek, 26 sierpnia 2014 15:38:33 UTC+2 użytkownik James Schneider napisał: > > Try changing the 'name' argument to 'verbose_name' like so: > > name = models.CharField(max_length=30, verbose_name='Vlan name') > > I don't believe model fields accept 'name' as a keyword arg. This would > also explain the slightly confusing error due to the overlap of 'name' > appearing in multiple spots. > > https://docs.djangoproject.com/en/dev/ref/models/fields/#field-options > > > -James > > > > On Tuesday, August 26, 2014, Przemek Ciborowski > wrote: > >> So to be more clearly, let create new django project with one application >> for example with name networks. >> Add those lines to the networks/models.py: >> >> class Vlan(models.Model): >> >> name = models.CharField(max_length=30, name='Vlan name') >> >> def __unicode__(self): >> return self.name >> >> add those two lines to networks/admin.py >> >> from .models import * >> admin.site.register(Vlan) >> >> It should be (and was) enough to run admin interface. Unfortunately when >> I'm trying to add new vlan or list current vlans I get: >> --- >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method:POSTRequest URL: >> http://127.0.0.1:8000/admin/networks/vlan/add/ Django Version:1.6.6Exception >> Type: AttributeErrorException Value: >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location: C:\Scripts\Test1\networks\models.py in __unicode__, >> line 11Python Executable: C:\Python\Main\Scripts\python.exePython >> Version: 2.7.8Python Path: >> >> ['C:\\Scripts\\Test1', >> 'C:\\Scripts\\Test1', >> 'C:\\Windows\\SYSTEM32\\python27.zip', >> 'C:\\Python\\Main\\DLLs', >> 'C:\\Python\\Main\\lib', >> 'C:\\Python\\Main\\lib\\plat-win', >> 'C:\\Python\\Main\\lib\\lib-tk', >> 'C:\\Python\\Main\\Scripts', >> 'C:\\Python27\\Lib', >> 'C:\\Python27\\DLLs', >> 'C:\\Python27\\Lib\\lib-tk', >> 'C:\\Python\\Main', >> 'C:\\Python\\Main\\lib\\site-packages'] >> >> Server time: Tue, 26 Aug 2014 14:12:06 +0200 >> >> >> >> --- >> >> More information here : http://dpaste.com/26QQPKZ >> >> Look this is code from first part of official django tutorial. >> When I delete def __unicode__(self) method from models file, it works >> fine but in vlan list I get Vlan object, Vlan object etc instead of >> names. >> >> >> Regards >> Przemek. >> >> >> >> >> W dniu poniedziałek, 25 sierpnia 2014 22:47:10 UTC+2 użytkownik Przemek >> Ciborowski napisał: >>> >>> Hello guys, >>> >>> I'm really beginner in django. >>> I have extremely simple example: >>> >>> class Vlan(models.Model): >>> name = models.CharField(max_length=30, name='Vlan name') >>> number = models.IntegerField(default=0, name='Vlan number') >>> >>> def __unicode__(self): >>> return self.name >>> >>> When I'm trying to use admin interface, I got this error: >>> >>> AttributeError at /admin/networks/vlan/add/ >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Request Method:POST Request URL:http://127.0.0.1:8000/admin/ >>> networks/vlan/add/ Django Version:1.6.6Exception Type: >>> AttributeErrorException >>> Value: >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Exception Location: D:\Scripts\Mercury\networks\models.py in __str__, >>> line 10Python Executable: C:\Python\Main\Scripts\python.exePython >>> Version: 2.7.8 >>> >>> I'm sure that it was working a few days ago. And in meantime I did >>> django upgrade. >>> What I'm doing wrong, and how I can fix it? >>> >>> Thanks in advance. >>> Przemek. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe f
Re: Model - def __unicode__(self) - doesn't work
On 25 Aug 2014 23:32, "Babatunde Akinyanmi" wrote: > > Hi Przemek, > I'm not sure there's a name attribute for Field and its subclasses. > Does removing the name attribute work? > Oops. I meant argument not attribute > On 25 Aug 2014 22:19, "Przemek Ciborowski" wrote: >> >> Hello guys, >> >> I'm really beginner in django. >> I have extremely simple example: >> >> class Vlan(models.Model): >> name = models.CharField(max_length=30, name='Vlan name') >> number = models.IntegerField(default=0, name='Vlan number') >> >> def __unicode__(self): >> return self.name >> >> When I'm trying to use admin interface, I got this error: >> >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method: >> POST >> Request URL: >> http://127.0.0.1:8000/admin/networks/vlan/add/ >> Django Version: >> 1.6.6 >> Exception Type: >> AttributeError >> Exception Value: >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location: >> D:\Scripts\Mercury\networks\models.py in __str__, line 10 >> Python Executable: >> C:\Python\Main\Scripts\python.exe >> Python Version: >> 2.7.8 >> >> I'm sure that it was working a few days ago. And in meantime I did django upgrade. >> What I'm doing wrong, and how I can fix it? >> >> Thanks in advance. >> Przemek. >> >> -- >> You received this message because you are subscribed to the Google Groups "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BWjgXPDJ33DJCPVsgWECABEu_-dnmSi4GTPWtiRXKiX_s%2BuxA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
On 26 Aug 2014 14:38, "James Schneider" wrote: > > Try changing the 'name' argument to 'verbose_name' like so: > > name = models.CharField(max_length=30, verbose_name='Vlan name') > > I don't believe model fields accept 'name' as a keyword arg. This would also explain the slightly confusing error due to the overlap of 'name' appearing in multiple spots. > Just like I pointed out in my earlier mail. Remove the name argument or change it to verbose_name as recommended by James > https://docs.djangoproject.com/en/dev/ref/models/fields/#field-options > > > -James > > > > On Tuesday, August 26, 2014, Przemek Ciborowski wrote: >> >> So to be more clearly, let create new django project with one application for example with name networks. >> Add those lines to the networks/models.py: >> >> class Vlan(models.Model): >> >> name = models.CharField(max_length=30, name='Vlan name') >> >> def __unicode__(self): >> return self.name >> >> add those two lines to networks/admin.py >> >> from .models import * >> admin.site.register(Vlan) >> >> It should be (and was) enough to run admin interface. Unfortunately when I'm trying to add new vlan or list current vlans I get: >> --- >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method: >> POST >> Request URL: >> http://127.0.0.1:8000/admin/networks/vlan/add/ >> Django Version: >> 1.6.6 >> Exception Type: >> AttributeError >> Exception Value: >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location: >> C:\Scripts\Test1\networks\models.py in __unicode__, line 11 >> Python Executable: >> C:\Python\Main\Scripts\python.exe >> Python Version: >> 2.7.8 >> Python Path: >> >> ['C:\\Scripts\\Test1', >> 'C:\\Scripts\\Test1', >> 'C:\\Windows\\SYSTEM32\\python27.zip', >> 'C:\\Python\\Main\\DLLs', >> 'C:\\Python\\Main\\lib', >> 'C:\\Python\\Main\\lib\\plat-win', >> 'C:\\Python\\Main\\lib\\lib-tk', >> 'C:\\Python\\Main\\Scripts', >> 'C:\\Python27\\Lib', >> 'C:\\Python27\\DLLs', >> 'C:\\Python27\\Lib\\lib-tk', >> 'C:\\Python\\Main', >> 'C:\\Python\\Main\\lib\\site-packages'] >> >> Server time: >> Tue, 26 Aug 2014 14:12:06 +0200 >> >> >> >> --- >> >> More information here : http://dpaste.com/26QQPKZ >> >> Look this is code from first part of official django tutorial. >> When I delete def __unicode__(self) method from models file, it works fine but in vlan list I get Vlan object, Vlan object etc instead of names. >> >> >> Regards >> Przemek. >> >> >> >> >> W dniu poniedziałek, 25 sierpnia 2014 22:47:10 UTC+2 użytkownik Przemek Ciborowski napisał: >>> >>> Hello guys, >>> >>> I'm really beginner in django. >>> I have extremely simple example: >>> >>> class Vlan(models.Model): >>> name = models.CharField(max_length=30, name='Vlan name') >>> number = models.IntegerField(default=0, name='Vlan number') >>> >>> def __unicode__(self): >>> return self.name >>> >>> When I'm trying to use admin interface, I got this error: >>> >>> AttributeError at /admin/networks/vlan/add/ >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Request Method: >>> POST >>> Request URL: >>> http://127.0.0.1:8000/admin/networks/vlan/add/ >>> Django Version: >>> 1.6.6 >>> Exception Type: >>> AttributeError >>> Exception Value: >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Exception Location: >>> D:\Scripts\Mercury\networks\models.py in __str__, line 10 >>> Python Executable: >>> C:\Python\Main\Scripts\python.exe >>> Python Version: >>> 2.7.8 >>> >>> I'm sure that it was working a few days ago. And in meantime I did django upgrade. >>> What I'm doing wrong, and how I can fix it? >>> >>> Thanks in advance. >>> Przemek. >> >> -- >> You received this
Re: Model - def __unicode__(self) - doesn't work
Try changing the 'name' argument to 'verbose_name' like so: name = models.CharField(max_length=30, verbose_name='Vlan name') I don't believe model fields accept 'name' as a keyword arg. This would also explain the slightly confusing error due to the overlap of 'name' appearing in multiple spots. https://docs.djangoproject.com/en/dev/ref/models/fields/#field-options -James On Tuesday, August 26, 2014, Przemek Ciborowski wrote: > So to be more clearly, let create new django project with one application > for example with name networks. > Add those lines to the networks/models.py: > > class Vlan(models.Model): > > name = models.CharField(max_length=30, name='Vlan name') > > def __unicode__(self): > return self.name > > add those two lines to networks/admin.py > > from .models import * > admin.site.register(Vlan) > > It should be (and was) enough to run admin interface. Unfortunately when > I'm trying to add new vlan or list current vlans I get: > --- > AttributeError at /admin/networks/vlan/add/ > > 'Vlan' object has no attribute 'name' > > Request Method:POSTRequest URL: > http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception > Type:AttributeErrorException Value: > > 'Vlan' object has no attribute 'name' > > Exception Location:C:\Scripts\Test1\networks\models.py in __unicode__, > line 11Python Executable:C:\Python\Main\Scripts\python.exePython Version: > 2.7.8Python Path: > > ['C:\\Scripts\\Test1', > 'C:\\Scripts\\Test1', > 'C:\\Windows\\SYSTEM32\\python27.zip', > 'C:\\Python\\Main\\DLLs', > 'C:\\Python\\Main\\lib', > 'C:\\Python\\Main\\lib\\plat-win', > 'C:\\Python\\Main\\lib\\lib-tk', > 'C:\\Python\\Main\\Scripts', > 'C:\\Python27\\Lib', > 'C:\\Python27\\DLLs', > 'C:\\Python27\\Lib\\lib-tk', > 'C:\\Python\\Main', > 'C:\\Python\\Main\\lib\\site-packages'] > > Server time:Tue, 26 Aug 2014 14:12:06 +0200 > > > > --- > > More information here : http://dpaste.com/26QQPKZ > > Look this is code from first part of official django tutorial. > When I delete def __unicode__(self) method from models file, it works fine > but in vlan list I get Vlan object, Vlan object etc instead of names. > > > Regards > Przemek. > > > > > W dniu poniedziałek, 25 sierpnia 2014 22:47:10 UTC+2 użytkownik Przemek > Ciborowski napisał: >> >> Hello guys, >> >> I'm really beginner in django. >> I have extremely simple example: >> >> class Vlan(models.Model): >> name = models.CharField(max_length=30, name='Vlan name') >> number = models.IntegerField(default=0, name='Vlan number') >> >> def __unicode__(self): >> return self.name >> >> When I'm trying to use admin interface, I got this error: >> >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method:POSTRequest URL:http://127.0.0.1:8000/admin/ >> networks/vlan/add/Django Version:1.6.6Exception Type:AttributeErrorException >> Value: >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location:D:\Scripts\Mercury\networks\models.py in __str__, >> line 10Python Executable:C:\Python\Main\Scripts\python.exePython Version: >> 2.7.8 >> >> I'm sure that it was working a few days ago. And in meantime I did django >> upgrade. >> What I'm doing wrong, and how I can fix it? >> >> Thanks in advance. >> Przemek. >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com > > . > To post to this group, send email to django-users@googlegroups.com > . > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/01dd14d6-43d7-4519-bffb-b6d33a083f54%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/01dd14d6-43d7-4519-bffb-b6d33a083f54%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWRN00qpz1SRvzgC_k0av92MQyPsN0TSU1CBdBh-QFbWw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
So to be more clearly, let create new django project with one application for example with name networks. Add those lines to the networks/models.py: class Vlan(models.Model): name = models.CharField(max_length=30, name='Vlan name') def __unicode__(self): return self.name add those two lines to networks/admin.py from .models import * admin.site.register(Vlan) It should be (and was) enough to run admin interface. Unfortunately when I'm trying to add new vlan or list current vlans I get: --- AttributeError at /admin/networks/vlan/add/ 'Vlan' object has no attribute 'name' Request Method:POSTRequest URL: http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception Type:AttributeErrorException Value: 'Vlan' object has no attribute 'name' Exception Location:C:\Scripts\Test1\networks\models.py in __unicode__, line 11Python Executable:C:\Python\Main\Scripts\python.exePython Version:2.7.8Python Path: ['C:\\Scripts\\Test1', 'C:\\Scripts\\Test1', 'C:\\Windows\\SYSTEM32\\python27.zip', 'C:\\Python\\Main\\DLLs', 'C:\\Python\\Main\\lib', 'C:\\Python\\Main\\lib\\plat-win', 'C:\\Python\\Main\\lib\\lib-tk', 'C:\\Python\\Main\\Scripts', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', 'C:\\Python27\\Lib\\lib-tk', 'C:\\Python\\Main', 'C:\\Python\\Main\\lib\\site-packages'] Server time:Tue, 26 Aug 2014 14:12:06 +0200 --- More information here : http://dpaste.com/26QQPKZ Look this is code from first part of official django tutorial. When I delete def __unicode__(self) method from models file, it works fine but in vlan list I get Vlan object, Vlan object etc instead of names. Regards Przemek. W dniu poniedziałek, 25 sierpnia 2014 22:47:10 UTC+2 użytkownik Przemek Ciborowski napisał: > > Hello guys, > > I'm really beginner in django. > I have extremely simple example: > > class Vlan(models.Model): > name = models.CharField(max_length=30, name='Vlan name') > number = models.IntegerField(default=0, name='Vlan number') > > def __unicode__(self): > return self.name > > When I'm trying to use admin interface, I got this error: > > AttributeError at /admin/networks/vlan/add/ > > 'Vlan' object has no attribute 'name' > > Request Method:POSTRequest URL: > http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception > Type:AttributeErrorException Value: > > 'Vlan' object has no attribute 'name' > > Exception Location:D:\Scripts\Mercury\networks\models.py in __str__, line > 10Python Executable:C:\Python\Main\Scripts\python.exePython Version:2.7.8 > > I'm sure that it was working a few days ago. And in meantime I did django > upgrade. > What I'm doing wrong, and how I can fix it? > > Thanks in advance. > Przemek. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01dd14d6-43d7-4519-bffb-b6d33a083f54%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Hi, thanks for your reply. It didn't help, I also trid return unicode(self.name) Regards Przemek. W dniu wtorek, 26 sierpnia 2014 10:24:07 UTC+2 użytkownik monoBOT monoBOT napisał: > > Be sure to returm a unicode object like this: > > def __unicode__(self): > return u"%s" % self.name > > > 2014-08-25 23:48 GMT+01:00 Mario Gudelj > >: > >> Your problem is in the add view. Post your view code >> On 26/08/2014 7:20 am, "Przemek Ciborowski" > > wrote: >> >>> Hello guys, >>> >>> I'm really beginner in django. >>> I have extremely simple example: >>> >>> class Vlan(models.Model): >>> name = models.CharField(max_length=30, name='Vlan name') >>> number = models.IntegerField(default=0, name='Vlan number') >>> >>> def __unicode__(self): >>> return self.name >>> >>> When I'm trying to use admin interface, I got this error: >>> >>> AttributeError at /admin/networks/vlan/add/ >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Request Method:POST Request URL: >>> http://127.0.0.1:8000/admin/networks/vlan/add/ Django >>> Version:1.6.6Exception >>> Type: AttributeErrorException Value: >>> >>> 'Vlan' object has no attribute 'name' >>> >>> Exception Location: D:\Scripts\Mercury\networks\models.py in __str__, >>> line 10Python Executable: C:\Python\Main\Scripts\python.exePython >>> Version: 2.7.8 >>> >>> I'm sure that it was working a few days ago. And in meantime I did >>> django upgrade. >>> What I'm doing wrong, and how I can fix it? >>> >>> Thanks in advance. >>> Przemek. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-users...@googlegroups.com . >>> To post to this group, send email to django...@googlegroups.com >>> . >>> Visit this group at http://groups.google.com/group/django-users. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAHqTbj%3DNk8DTt5UNGktqkGb6-Lwqvt8-g2sSW9EpbMZ_8YPRSQ%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-users/CAHqTbj%3DNk8DTt5UNGktqkGb6-Lwqvt8-g2sSW9EpbMZ_8YPRSQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > *monoBOT* > Visite mi sitio(Visit my site): monobotsoft.es/blog/ > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a69ad175-f1e3-4b1f-990b-92402a0c7489%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Hi, thanks for your reply. I forgot to mention that this problem occurs with admin interface. Regards Przemek. W dniu wtorek, 26 sierpnia 2014 00:49:01 UTC+2 użytkownik somecallitblues napisał: > > Your problem is in the add view. Post your view code > On 26/08/2014 7:20 am, "Przemek Ciborowski" > wrote: > >> Hello guys, >> >> I'm really beginner in django. >> I have extremely simple example: >> >> class Vlan(models.Model): >> name = models.CharField(max_length=30, name='Vlan name') >> number = models.IntegerField(default=0, name='Vlan number') >> >> def __unicode__(self): >> return self.name >> >> When I'm trying to use admin interface, I got this error: >> >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method:POST Request URL: >> http://127.0.0.1:8000/admin/networks/vlan/add/ Django Version:1.6.6Exception >> Type: AttributeErrorException Value: >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location: D:\Scripts\Mercury\networks\models.py in __str__, >> line 10Python Executable: C:\Python\Main\Scripts\python.exePython >> Version: 2.7.8 >> >> I'm sure that it was working a few days ago. And in meantime I did django >> upgrade. >> What I'm doing wrong, and how I can fix it? >> >> Thanks in advance. >> Przemek. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d53ae3ac-70d2-4bd0-86de-2e2f8e6ce700%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Be sure to returm a unicode object like this: def __unicode__(self): return u"%s" % self.name 2014-08-25 23:48 GMT+01:00 Mario Gudelj : > Your problem is in the add view. Post your view code > On 26/08/2014 7:20 am, "Przemek Ciborowski" wrote: > >> Hello guys, >> >> I'm really beginner in django. >> I have extremely simple example: >> >> class Vlan(models.Model): >> name = models.CharField(max_length=30, name='Vlan name') >> number = models.IntegerField(default=0, name='Vlan number') >> >> def __unicode__(self): >> return self.name >> >> When I'm trying to use admin interface, I got this error: >> >> AttributeError at /admin/networks/vlan/add/ >> >> 'Vlan' object has no attribute 'name' >> >> Request Method:POST Request URL: >> http://127.0.0.1:8000/admin/networks/vlan/add/ Django Version:1.6.6Exception >> Type: AttributeErrorException Value: >> >> >> 'Vlan' object has no attribute 'name' >> >> Exception Location: D:\Scripts\Mercury\networks\models.py in __str__, >> line 10Python Executable: C:\Python\Main\Scripts\python.exePython >> Version: 2.7.8 >> >> I'm sure that it was working a few days ago. And in meantime I did django >> upgrade. >> What I'm doing wrong, and how I can fix it? >> >> Thanks in advance. >> Przemek. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAHqTbj%3DNk8DTt5UNGktqkGb6-Lwqvt8-g2sSW9EpbMZ_8YPRSQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAHqTbj%3DNk8DTt5UNGktqkGb6-Lwqvt8-g2sSW9EpbMZ_8YPRSQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- *monoBOT* Visite mi sitio(Visit my site): monobotsoft.es/blog/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BxOsGA4ahT-x2BLsm-rjiTM_eOCpdoWVGdKg-mNKvB%2BOKXdmg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Your problem is in the add view. Post your view code On 26/08/2014 7:20 am, "Przemek Ciborowski" wrote: > Hello guys, > > I'm really beginner in django. > I have extremely simple example: > > class Vlan(models.Model): > name = models.CharField(max_length=30, name='Vlan name') > number = models.IntegerField(default=0, name='Vlan number') > > def __unicode__(self): > return self.name > > When I'm trying to use admin interface, I got this error: > > AttributeError at /admin/networks/vlan/add/ > > 'Vlan' object has no attribute 'name' > > Request Method:POSTRequest URL: > http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception > Type:AttributeErrorException Value: > > 'Vlan' object has no attribute 'name' > > Exception Location:D:\Scripts\Mercury\networks\models.py in __str__, line > 10Python Executable:C:\Python\Main\Scripts\python.exePython Version:2.7.8 > > I'm sure that it was working a few days ago. And in meantime I did django > upgrade. > What I'm doing wrong, and how I can fix it? > > Thanks in advance. > Przemek. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHqTbj%3DNk8DTt5UNGktqkGb6-Lwqvt8-g2sSW9EpbMZ_8YPRSQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Model - def __unicode__(self) - doesn't work
Hi Przemek, I'm not sure there's a name attribute for Field and its subclasses. Does removing the name attribute work? On 25 Aug 2014 22:19, "Przemek Ciborowski" wrote: Hello guys, I'm really beginner in django. I have extremely simple example: class Vlan(models.Model): name = models.CharField(max_length=30, name='Vlan name') number = models.IntegerField(default=0, name='Vlan number') def __unicode__(self): return self.name When I'm trying to use admin interface, I got this error: AttributeError at /admin/networks/vlan/add/ 'Vlan' object has no attribute 'name' Request Method:POSTRequest URL: http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception Type:AttributeErrorException Value: 'Vlan' object has no attribute 'name' Exception Location:D:\Scripts\Mercury\networks\models.py in __str__, line 10Python Executable:C:\Python\Main\Scripts\python.exePython Version:2.7.8 I'm sure that it was working a few days ago. And in meantime I did django upgrade. What I'm doing wrong, and how I can fix it? Thanks in advance. Przemek. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com <https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com?utm_medium=email&utm_source=footer> . For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BWjgXO244j099HJ2B0p36eeCzuJH26PUM2HZK%3DAXwm-KkKxqQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Model - def __unicode__(self) - doesn't work
Hello guys, I'm really beginner in django. I have extremely simple example: class Vlan(models.Model): name = models.CharField(max_length=30, name='Vlan name') number = models.IntegerField(default=0, name='Vlan number') def __unicode__(self): return self.name When I'm trying to use admin interface, I got this error: AttributeError at /admin/networks/vlan/add/ 'Vlan' object has no attribute 'name' Request Method:POSTRequest URL: http://127.0.0.1:8000/admin/networks/vlan/add/Django Version:1.6.6Exception Type:AttributeErrorException Value: 'Vlan' object has no attribute 'name' Exception Location:D:\Scripts\Mercury\networks\models.py in __str__, line 10Python Executable:C:\Python\Main\Scripts\python.exePython Version:2.7.8 I'm sure that it was working a few days ago. And in meantime I did django upgrade. What I'm doing wrong, and how I can fix it? Thanks in advance. Przemek. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50470bc3-c7a0-4afd-b655-f7a3cf8304a0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: def __unicode__(self) in models.py is not working
It appears as though when using Python3.3 and Django 1.6dev you should use __str__ and not __unicode__. __unicode__ seems to be gone from Python3.3 On Tuesday, February 12, 2013 4:45:33 PM UTC-5, David wrote: > > I am working through the tutorial and find that the *def > __unicode__(self):* command to give an object a readable name in admin is > not working. I am cutting code from the tutorial. When I access the > detail screen in /admin/ all I see is [table name] object and not the name > I defined in def __unicode__(self): return: self.name > > I am working with the 1.6dev release in a 64bit Win7 environment. > > Is this a known issue with dev? I have searched Django users without > success. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: def __unicode__(self) in models.py is not working
On Wed, Feb 13, 2013 at 9:45 AM, David wrote: > I am working through the tutorial and find that the *def > __unicode__(self):* command to give an object a readable name in admin is > not working. I am cutting code from the tutorial. When I access the > detail screen in /admin/ all I see is [table name] object and not the name > I defined in def __unicode__(self): return: self.name > > I am working with the 1.6dev release in a 64bit Win7 environment. > > Is this a known issue with dev? I have searched Django users without > success. > > Without seeing the code, it's hard to tell. If you could post the relevant model.py code and the admin.py code (http://dpaste.org/ is your friend) Does your model have a field called name? Have you restarted the test or webserver since you added the change? Cheers L. > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- So the future isn't a boot stamping on a human face, forever. It's a person in a beige business outfit advocating beige policies that nobody wants (but nobody can quite articulate a coherent alternative to) with a false mandate obtained by performing rituals of representative democracy that offer as much actual choice as a Stalinist one-party state. And resistance is futile, because if you succeed in overthrowing the beige dictatorship, you will become that which you opposed. http://www.antipope.org/charlie/blog-static/2013/02/political-failure-modes-and-th.html -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
def __unicode__(self) in models.py is not working
I am working through the tutorial and find that the *def __unicode__(self):*command to give an object a readable name in admin is not working. I am cutting code from the tutorial. When I access the detail screen in /admin/ all I see is [table name] object and not the name I defined in def __unicode__(self): return: self.name I am working with the 1.6dev release in a 64bit Win7 environment. Is this a known issue with dev? I have searched Django users without success. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Stuck going through tutorial (with def __unicode__(self): bit)
Right. 9 times out of ten its the server not restarting which someone already mentioned. If you're new to python try using ecli On Mar 20, 2010 10:22 AM, "Daniel Roseman" wrote: On Mar 20, 1:56 pm, Ed57 wrote: > Hi > > I'm just trying to learn abou... You haven't shown us your code, but my guess would be one of two issues - either the server hasn't restarted itself, in which case hit ctrl-c and do it manually; or it's an indentation issue, so that the method is being parsed as a standalone function rather than a member of the Poll class. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group -- 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: Stuck going through tutorial (with def __unicode__(self): bit)
On Mar 20, 1:56 pm, Ed57 wrote: > Hi > > I'm just trying to learn about django (I'm also new to python). In the > tutorial there's a bit where you put the def __unicode__(self): method > in your classes. I've done this but when I do Poll.objects.all() - > the class is called Poll - i just get . The > tutorial says this might happen if I'm using an old version of django, > but I'm using 1.1.1 and the tutorial is for 1.1.1 so I don't know > whats wrong. > > Any ideas? You haven't shown us your code, but my guess would be one of two issues - either the server hasn't restarted itself, in which case hit ctrl-c and do it manually; or it's an indentation issue, so that the method is being parsed as a standalone function rather than a member of the Poll class. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Stuck going through tutorial (with def __unicode__(self): bit)
Hi I'm just trying to learn about django (I'm also new to python). In the tutorial there's a bit where you put the def __unicode__(self): method in your classes. I've done this but when I do Poll.objects.all() - the class is called Poll - i just get . The tutorial says this might happen if I'm using an old version of django, but I'm using 1.1.1 and the tutorial is for 1.1.1 so I don't know whats wrong. Any ideas? -- 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: __unicode__(self) doesn't work
2009/10/12 Denis Bahati > Hi there i have the problem with unicode function it doesn't give me any > changes. the poll list is displayed as Poll object and does doesn't give me > error if i write the models.py like this:from django.db import models > import datetime > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' > > this identation makes functions live in module, not class. You should add one ident to your methods to push them into class body like this: class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() --~--~-~--~~~---~--~~ 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: __unicode__(self) doesn't work
On Mon, Oct 12, 2009 at 2:19 AM, Denis Bahati wrote: > if i change the code like the one shown below it gives me the traceback > about indents, i also included below. > from django.db import models > import datetime > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField() > def __unicode__(self): > return self.choice No, it is stell wrong. Your model definitions need to look like this: http://dpaste.com/hold/106119/ Note how the methods are indented at the same level of the model field definitions because both of them pertain th the same class (the model). I'd suggest to read some Python material to familiarize yourself with indentation rules and class definitions. Regards, -- Ramiro Morales | http://rmorales.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 -~--~~~~--~~--~--~---
Re: Hi All: __unicode__(self)
On Monday 12 Oct 2009 11:25:27 am Russell Keith-Magee wrote: > On Mon, Oct 12, 2009 at 1:44 PM, Kenneth Gonsalves > > wrote: > > On Monday 12 Oct 2009 11:05:38 am Denis Bahati wrote: > >> class Poll(models.Model): > >> question = models.CharField(max_length=200) > >> pub_date = models.DateTimeField('date published') > >> def __unicode__(self): > >> return self.question > >> def was_published_today(self): > >> return self.pub_date.date() == datetime.date.today() > >> def was_published_today(self): > >> return self.pub_date.date() == datetime.date.today() > >> was_published_today.short_description = 'Published today?' > > > > please learn some python! > > Kenneth - please learn some manners. You have repeatedly demonstrated > on this list that you have a deep yearning for brevity. However, let > me assure you that it really doesn't take that much effort to write in > whole sentences (with capitalization and everything). If you throw in > some politeness while you are at it, all the better. I think this is uncalled for - granted I tend to be brief. In this case, I replied once, he re-posted and (using the word 'please') I pointed out that his problem is due to lack of python knowledge. What is rude about it? Maybe the solution I gave is wrong. Or maybe I should not have given a solution and just stopped with asking him to learn some python? Anyway, I do not want to make an issue of this - at least I hope *this* post correctly follows grammatical rules. -- regards kg http://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 -~--~~~~--~~--~--~---
Re: Hi All: __unicode__(self)
Thank in advance for the advices. On Mon, Oct 12, 2009 at 8:55 AM, Russell Keith-Magee wrote: > > On Mon, Oct 12, 2009 at 1:44 PM, Kenneth Gonsalves > wrote: > > > > On Monday 12 Oct 2009 11:05:38 am Denis Bahati wrote: > >> class Poll(models.Model): > >> question = models.CharField(max_length=200) > >> pub_date = models.DateTimeField('date published') > >> def __unicode__(self): > >> return self.questiona > >> def was_published_today(self): > >> return self.pub_date.date() == datetime.date.today() > >> def was_published_today(self): > >> return self.pub_date.date() == datetime.date.today() > >> was_published_today.short_description = 'Published today?' > > > > please learn some python! > > Kenneth - please learn some manners. You have repeatedly demonstrated > on this list that you have a deep yearning for brevity. However, let > me assure you that it really doesn't take that much effort to write in > whole sentences (with capitalization and everything). If you throw in > some politeness while you are at it, all the better. > > Yours, > Russ Magee %-) > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Hi All: __unicode__(self)
On Mon, Oct 12, 2009 at 1:44 PM, Kenneth Gonsalves wrote: > > On Monday 12 Oct 2009 11:05:38 am Denis Bahati wrote: >> class Poll(models.Model): >> question = models.CharField(max_length=200) >> pub_date = models.DateTimeField('date published') >> def __unicode__(self): >> return self.question >> def was_published_today(self): >> return self.pub_date.date() == datetime.date.today() >> def was_published_today(self): >> return self.pub_date.date() == datetime.date.today() >> was_published_today.short_description = 'Published today?' > > please learn some python! Kenneth - please learn some manners. You have repeatedly demonstrated on this list that you have a deep yearning for brevity. However, let me assure you that it really doesn't take that much effort to write in whole sentences (with capitalization and everything). If you throw in some politeness while you are at it, all the better. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Hi All: __unicode__(self)
On Mon, Oct 12, 2009 at 1:35 PM, Denis Bahati wrote: > Hi all, > I have a problem with __unicode__(self) function it doesn't give any changes > to the display of poll list it just display the Poll object when i code like > below: Ok - you need to do two things. 1) Stop posting the same question over and over again. We saw it the first time. 2) Get hold of a good Python tutorial. The official Python tutorial is good [1]; another good one is Dive Into Python [2]. Strange as it may seem, the reason you are getting an error that reads "IndentationError, unexpected indent, models.py line 10" is because you have an indentation error, caused by an unexpected indent, on line 10 of models.py. Django isn't a programming language. It's just a library that uses the Python language. If you're going to write web sites using Django, you really need to understand Python first. So before you try to work through the Django tutorial, work through the Python tutorial. I could give you the answer to your question very easily, but I'm not going to - specifically because you _really_ need to work out this one by yourself. The error message you are getting is 100% correct, and points you to the exact problem. The cause is described in the *introduction* to the official Python tutorial. [1] http://docs.python.org/tutorial/ [2] http://www.diveintopython.org/ Yours Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Hi All: __unicode__(self)
On Monday 12 Oct 2009 11:05:38 am Denis Bahati wrote: > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' please learn some python! class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() -- regards kg http://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 -~--~~~~--~~--~--~---
Hi All: __unicode__(self)
Hi all, I have a problem with __unicode__(self) function it doesn't give any changes to the display of poll list it just display the Poll object when i code like below: from django.db import models import datetime class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice if i change the code like the one shown below it gives me the traceback about indents, i also included below. from django.db import models import datetime class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): eturn self.choice Environment: Request Method: GET Request URL: http://localhost/testproject/admin/polls/poll/5/ Django Version: 1.1 Python Version: 2.5.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'testproject.polls'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response 83. request.path_info) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve 216. for pattern in self.url_patterns: File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns 245. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module 240. self._urlconf_module = import_module(self.urlconf_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:/xampp/htdocs\testproject\urls.py" in 5. admin.autodiscover() File "C:\Python25\lib\site-packages\django\contrib\admin\__init__.py" in autodiscover 56. import_module("%s.admin" % app) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:\Python25\lib\site-packages\django\contrib\auth\admin.py" in 128. admin.site.register(Group, GroupAdmin) File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in register 90. validate(admin_class, model) File "C:\Python25\lib\site-packages\django\contrib\admin\validation.py" in validate 22. models.get_apps() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in get_apps 100. self._populate() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in _populate 58. self.load_app(app_name, True) File "C:\Python25\lib\site-packages\django\db\models\loading.py" in load_app 74. models = import_module('.models', app_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) Exception Type: IndentationError at /admin/polls/poll/5/ Exception Value: unexpected indent (models.py, line 10) Please any help. --~--~-~--~~~---~--~~ 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: __unicode__(self) doesn't work
Did you see my second post? I changed it still a problem On Mon, Oct 12, 2009 at 8:19 AM, Denis Bahati wrote: > Hi all, > I have a problem with __unicode__(self) function it doesn't give any > changes to the display of poll list it just display the Poll object when i > code like below: > > > from django.db import models > import datetime > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' > > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField() > def __unicode__(self): > return self.choice > > *if i change the code like the one shown below it gives me the traceback > about indents, i also included below.* > > from django.db import models > import datetime > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' > > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField() > def __unicode__(self): > return self.choice > > Environment: Request Method: GET Request URL: > http://localhost/testproject/admin/polls/poll/5/ Django Version: 1.1 > Python Version: 2.5.4 Installed Applications: ['django.contrib.auth', > 'django.contrib.contenttypes', 'django.contrib.sessions', > 'django.contrib.sites', 'django.contrib.admin', 'testproject.polls'] > Installed Middleware: ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File > "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response > 83. request.path_info) File > "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve 216. > for pattern in self.url_patterns: File > "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in > _get_url_patterns 245. patterns = getattr(self.urlconf_module, > "urlpatterns", self.urlconf_module) File > "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in > _get_urlconf_module 240. self._urlconf_module = > import_module(self.urlconf_name) File > "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module > 35. __import__(name) File "C:/xampp/htdocs\testproject\urls.py" in > 5. admin.autodiscover() File > "C:\Python25\lib\site-packages\django\contrib\admin\__init__.py" in > autodiscover 56. import_module("%s.admin" % app) File > "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module > 35. __import__(name) File > "C:\Python25\lib\site-packages\django\contrib\auth\admin.py" in > 128. admin.site.register(Group, GroupAdmin) File > "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in register > 90. validate(admin_class, model) File > "C:\Python25\lib\site-packages\django\contrib\admin\validation.py" in > validate 22. models.get_apps() File > "C:\Python25\lib\site-packages\django\db\models\loading.py" in get_apps 100. > self._populate() File > "C:\Python25\lib\site-packages\django\db\models\loading.py" in _populate 58. > self.load_app(app_name, True) File > "C:\Python25\lib\site-packages\django\db\models\loading.py" in load_app 74. > models = import_module('.models', app_name) File > "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module > 35. __import__(name) Exception Type: IndentationError at > /admin/polls/poll/5/ Exception Value: unexpected indent (models.py, line 10) > > * > * > > > Please any help. > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
__unicode__(self) doesn't work
Hi all, I have a problem with __unicode__(self) function it doesn't give any changes to the display of poll list it just display the Poll object when i code like below: from django.db import models import datetime class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice *if i change the code like the one shown below it gives me the traceback about indents, i also included below.* from django.db import models import datetime class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice Environment: Request Method: GET Request URL: http://localhost/testproject/admin/polls/poll/5/ Django Version: 1.1 Python Version: 2.5.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'testproject.polls'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response 83. request.path_info) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve 216. for pattern in self.url_patterns: File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns 245. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module 240. self._urlconf_module = import_module(self.urlconf_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:/xampp/htdocs\testproject\urls.py" in 5. admin.autodiscover() File "C:\Python25\lib\site-packages\django\contrib\admin\__init__.py" in autodiscover 56. import_module("%s.admin" % app) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:\Python25\lib\site-packages\django\contrib\auth\admin.py" in 128. admin.site.register(Group, GroupAdmin) File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in register 90. validate(admin_class, model) File "C:\Python25\lib\site-packages\django\contrib\admin\validation.py" in validate 22. models.get_apps() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in get_apps 100. self._populate() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in _populate 58. self.load_app(app_name, True) File "C:\Python25\lib\site-packages\django\db\models\loading.py" in load_app 74. models = import_module('.models', app_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) Exception Type: IndentationError at /admin/polls/poll/5/ Exception Value: unexpected indent (models.py, line 10) * * Please any help. --~--~-~--~~~---~--~~ 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: __unicode__(self) doesn't work
On Monday 12 Oct 2009 10:39:48 am Denis Bahati wrote: > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > was_published_today.short_description = 'Published today?' your indentation is all wrong - there has to be an indent before the return statements -- regards kg http://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 -~--~~~~--~~--~--~---
__unicode__(self) doesn't work
Hi there i have the problem with unicode function it doesn't give me any changes. the poll list is displayed as Poll object and does doesn't give me error if i write the models.py like this:from django.db import models import datetime class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice If i change to the way below it give me the below below: Environment: Request Method: GET Request URL: http://localhost/testproject/admin/polls/poll/5/ Django Version: 1.1 Python Version: 2.5.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'testproject.polls'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response 83. request.path_info) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve 216. for pattern in self.url_patterns: File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns 245. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module 240. self._urlconf_module = import_module(self.urlconf_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:/xampp/htdocs\testproject\urls.py" in 5. admin.autodiscover() File "C:\Python25\lib\site-packages\django\contrib\admin\__init__.py" in autodiscover 56. import_module("%s.admin" % app) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) File "C:\Python25\lib\site-packages\django\contrib\auth\admin.py" in 128. admin.site.register(Group, GroupAdmin) File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in register 90. validate(admin_class, model) File "C:\Python25\lib\site-packages\django\contrib\admin\validation.py" in validate 22. models.get_apps() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in get_apps 100. self._populate() File "C:\Python25\lib\site-packages\django\db\models\loading.py" in _populate 58. self.load_app(app_name, True) File "C:\Python25\lib\site-packages\django\db\models\loading.py" in load_app 74. models = import_module('.models', app_name) File "C:\Python25\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) Exception Type: IndentationError at /admin/polls/poll/5/ Exception Value: unexpected indent (models.py, line 10) Thanks in advance. --~--~-~--~~~---~--~~ 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: __unicode__(self):
Thanks! I was trying to use a + concatenator and it just wasn't happy. Brandon On Apr 14, 1:00 am, 1234 <[EMAIL PROTECTED]> wrote: > add "self" > > 2008/4/14, Malcolm Tredinnick <[EMAIL PROTECTED]>: > > > > > On Sun, 2008-04-13 at 22:04 -0700, Brandon Taylor wrote: > > > Hello everyone, > > > > I'm pretty new to Django, so please bear with me. > > > > When I'm defining a model, and I want to return a value to use in the > > > admin for the information to be displayed as such: > > > > from django.db import models > > > > class Link(models.Model): > > > name = models.CharField() > > > url = models.CharField() > > > position = models.PositiveSmallIntegerField() > > > > def __unicode__(self): > > > return name > > > That will give you a NameError, since "name" does not exist. You want to > > do "return self.name" there. > > > > Is it possible to concatenate fields for the def__unicode__(self) > > > method? I can't seem to find a way to do that, and was just wondering > > > if it's possible? > > > A __unicode__ method must return a unicode string. That's all. How you > > construct that string is entirely up to you. If you want to construct it > > by putting various attribute values together, that's fine. It's just > > Python. So, for example, > > > return u"%s %s" % (self.name, self.url) > > > would return a concatenation of the name and url attributes. Season to > > taste. > > > Regards, > > Malcolm > > > -- > > Honk if you love peace and quiet. > >http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: __unicode__(self):
add"self" 2008/4/14, Malcolm Tredinnick <[EMAIL PROTECTED]>: > > > > On Sun, 2008-04-13 at 22:04 -0700, Brandon Taylor wrote: > > Hello everyone, > > > > I'm pretty new to Django, so please bear with me. > > > > When I'm defining a model, and I want to return a value to use in the > > admin for the information to be displayed as such: > > > > from django.db import models > > > > class Link(models.Model): > > name = models.CharField() > > url = models.CharField() > > position = models.PositiveSmallIntegerField() > > > > def __unicode__(self): > > return name > > > That will give you a NameError, since "name" does not exist. You want to > do "return self.name" there. > > > > Is it possible to concatenate fields for the def__unicode__(self) > > method? I can't seem to find a way to do that, and was just wondering > > if it's possible? > > > A __unicode__ method must return a unicode string. That's all. How you > construct that string is entirely up to you. If you want to construct it > by putting various attribute values together, that's fine. It's just > Python. So, for example, > > return u"%s %s" % (self.name, self.url) > > would return a concatenation of the name and url attributes. Season to > taste. > > Regards, > Malcolm > > > -- > Honk if you love peace and quiet. > http://www.pointy-stick.com/blog/ > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: __unicode__(self):
On Sun, 2008-04-13 at 22:04 -0700, Brandon Taylor wrote: > Hello everyone, > > I'm pretty new to Django, so please bear with me. > > When I'm defining a model, and I want to return a value to use in the > admin for the information to be displayed as such: > > from django.db import models > > class Link(models.Model): > name = models.CharField() > url = models.CharField() > position = models.PositiveSmallIntegerField() > > def __unicode__(self): > return name That will give you a NameError, since "name" does not exist. You want to do "return self.name" there. > Is it possible to concatenate fields for the def__unicode__(self) > method? I can't seem to find a way to do that, and was just wondering > if it's possible? A __unicode__ method must return a unicode string. That's all. How you construct that string is entirely up to you. If you want to construct it by putting various attribute values together, that's fine. It's just Python. So, for example, return u"%s %s" % (self.name, self.url) would return a concatenation of the name and url attributes. Season to taste. Regards, Malcolm -- Honk if you love peace and quiet. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
__unicode__(self):
Hello everyone, I'm pretty new to Django, so please bear with me. When I'm defining a model, and I want to return a value to use in the admin for the information to be displayed as such: from django.db import models class Link(models.Model): name = models.CharField() url = models.CharField() position = models.PositiveSmallIntegerField() def __unicode__(self): return name class Admin: ordering = ['position'] class Meta: verbose_name_plural = 'Links' Is it possible to concatenate fields for the def__unicode__(self) method? I can't seem to find a way to do that, and was just wondering if it's possible? Thanks, Brandon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---