Re: __unicode__ and return.self
Glad to help. How the record is represented is up to you. For instance, if I have a Person model with the fields first_name, middle_name, last_name, email_address and phone number, I would think it prudent to define __unicode__ as:
def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)
... since first + last name is a common representation for a person. It would be just as valid (and perhaps even more usable in some situations) to return a middle name as well.
--
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144
On Sat, Mar 24, 2012 at 10:34 PM, MF-DOS <pwashington85@gmail.com> wrote:
Thanks for the reply.
If my model has 5 fields, why am I only returning one or two?
Shouldn't I return all 5?
On Mar 24, 9:19 pm, Jonathan Baker <jonathandavidba...@gmail.com>
wrote:
> The __unicode__ method allows models to return a more usable representation
> of a record instead of a unicode object. This is useful in a variety of
> places, from the Django admin to using the manage.py shell on the command
> line.
>
> The return statement effectively ends the execution of a particular
> function or method by returning something (an object, string, whatever you
> may need to return for the task at hand).
>
>
>
>
>
>
>
>
>
> On Sat, Mar 24, 2012 at 10:10 PM, spike <pwashingto...@gmail.com> wrote:
> > Running the tut here:
> >https://docs.djangoproject.com/en/1.1/intro/tutorial01/ but I'm having
> > trouble understanding what the point of __unicode__ is. Also, what is the
> > point of the return statements? I've read the docs over and over but don't
> > get it.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/django-users/-/jKgyKR2iRdgJ.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Jonathan D. Baker
> Web Developerhttp://jonathandbaker.com
> 303.257.4144
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home