[Django] #24869: Model unicode and Foreign key

8 views
Skip to first unread message

Django

unread,
May 28, 2015, 4:56:02 AM5/28/15
to django-...@googlegroups.com
#24869: Model unicode and Foreign key
-------------------------------+--------------------
Reporter: lefedor | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
possible bug:


{{{
class aModel(Model):
name = models.CharField(_('name'), null=True, max_length=64,
blank=True, default=None)

class bModel(Model):
aLink = models.ForeignKey(aModel, null=False, blank=False)
def __unicode__(self):
return u'%s' % (self.aLink.name)
}}}


gives error at admin:

RelatedObjectDoesNotExist at ....
bModel has no aLink.

same for
{{{
def __unicode__(self):
return u'%s' % str(self.id)
}}}

but works with
{{{
def __unicode__(self):
return u'%s' % (self.id.aLink.name)
}}}

is it correct?

--
Ticket URL: <https://code.djangoproject.com/ticket/24869>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 28, 2015, 8:59:36 AM5/28/15
to django-...@googlegroups.com
#24869: Model unicode and Foreign key
-------------------------------+--------------------------------------

Reporter: lefedor | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Which page gives the error and what is the full traceback?

--
Ticket URL: <https://code.djangoproject.com/ticket/24869#comment:1>

Django

unread,
May 29, 2015, 7:08:59 AM5/29/15
to django-...@googlegroups.com
#24869: Model unicode and Foreign key
-------------------------------+--------------------------------------
Reporter: lefedor | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => needsinfo


--
Ticket URL: <https://code.djangoproject.com/ticket/24869#comment:2>

Reply all
Reply to author
Forward
0 new messages