Admin Site appending letter "s" to end of each model\table name

1,244 views
Skip to first unread message

Gillwill

unread,
Sep 10, 2011, 5:40:10 PM9/10/11
to Django users
Apparently the Django default is to append the letter "s" to the end
of the model name for each listed under a given application on the
Site Administration page. (It does this in the tutorial sample site as
well - e.g. naming "poll" "polls", etc...)

Is there any way to get rid of that?

I would think there would be, but I've yet to find in the default
admin templates or code where it is doing this.

Any help appreciated.

-Gil

Christian Ramsey

unread,
Sep 10, 2011, 5:50:19 PM9/10/11
to django...@googlegroups.com
I believe you can use :

  def __unicode__(self)
	return 'Name you'd like without the s'
for each model and this will be used instead.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Michał Sawicz

unread,
Sep 10, 2011, 6:52:10 PM9/10/11
to django...@googlegroups.com
Dnia 2011-09-10, sob o godzinie 14:50 -0700, Christian Ramsey pisze:

> def __unicode__(self)
> return 'Name you'd like without the s'
> for each model and this will be used instead.

That's obviously not what he's after.


> On 10 Sep 2011, at 14:40, Gillwill wrote:

> >Apparently the Django default is to append the letter "s" to the end
> > of the model name for each listed under a given application on the
> > Site Administration page. (It does this in the tutorial sample site
> > as
> > well - e.g. naming "poll" "polls", etc...)
> >
> > Is there any way to get rid of that?

First, why is that a problem? If you're using localized model names and
that's where that doesn't fit - you shouldn't, really. You should use
english names for the models and use the i18n infrastructure [1] to
translate the names properly.

Either way [2] and [3] is what you need.

[1] https://docs.djangoproject.com/en/1.3/howto/i18n/
[2]
https://docs.djangoproject.com/en/1.3/ref/models/options/#verbose-name
[3]
https://docs.djangoproject.com/en/1.3/ref/models/options/#verbose-name-plural

Cheers,
--
Michał (Saviq) Sawicz <mic...@sawicz.net>

signature.asc

Andres Reyes

unread,
Sep 10, 2011, 6:50:06 PM9/10/11
to django...@googlegroups.com
Actually the solution is to define a verbose_name and a verbose_name_plural in your model's Meta

class MyModel(models.Model):
    field = models.CharField(max_length=200)
  
    class Meta:
        verbose_name = 'My model's name'
        verbose_name_plural = 'My model's name in plural context'
--
Andrés Reyes Monge
arm...@gmail.com
+(505)-8873-7217

gillwi...@yahoo.com

unread,
Sep 10, 2011, 7:46:48 PM9/10/11
to django...@googlegroups.com
It was only a problem  insofar as I didn't like the way such a listing looked, particulalrly when I have several models that already, originally, have an "s" at the end of their name like "Movies", "Books", etc... which would then be listed as "Moviess", "Bookss"...  and removing the "s" from their class names in models.py would require many code changes elsewhere in the app.
 
Anyway, thanks to all for the solution:
 
The verbose_name & verbose_name_plural did the trick.
 
-Gil
 
P.S.
 
I am basically a newbie at Django & Python so not sure I completely understand "localized model names" vs "english names". My model class names are just matches to the mysql database table names.

Shawn Milochik

unread,
Sep 10, 2011, 9:12:43 PM9/10/11
to django...@googlegroups.com
On 09/10/2011 07:46 PM, gillwi...@yahoo.com wrote:
It was only a problem� insofar as I didn't like the way such a listing looked, particulalrly when I have several models that already, originally,�have an "s" at the end of their name like "Movies", "Books", etc... which would then be listed as "Moviess", "Bookss"...� and removing the "s"�from their class names in models.py�would require many code changes elsewhere in the app.
ďż˝
Anyway, thanks to all for the solution:
ďż˝
The verbose_name & verbose_name_plural did the trick.
ďż˝
-Gil


It's conventional to name model in the singular by default, such as Movie and Book. You have a 'Movie' model, not a 'Movies' model. It also makes the default in the admin make perfect sense. If you have something that does end in is or the plural doesn't end in S (ox/oxen) then use verbose_name_plural.

If you think about it, a "Movies" doesn't have a "title" and "year_released" and a "rating" -- a "Movie" does.

Gil

unread,
Sep 10, 2011, 11:55:58 PM9/10/11
to django...@googlegroups.com
I'm a newbie to object-oriented programming too, so I suppose my mindset is still in procedural, SQL and "recordset" modes, and otherwise: my old ways :-) Thanks for that additional info. Good Points.
From: Shawn Milochik <sh...@milochik.com>
To: django...@googlegroups.com
Sent: Saturday, September 10, 2011 6:12 PM

Subject: Re: Admin Site appending letter "s" to end of each model\table name
It's conventional to name model in the singular by default, such as Movie and Book. You have a 'Movie' model, not a 'Movies' model. It also makes the default in the admin make perfect sense. If you have something that does end in is or the plural doesn't end in S (ox/oxen) then use verbose_name_plural.

If you think about it, a "Movies" doesn't have a "title" and "year_released" and a "rating" -- a "Movie" does.

Shawn Milochik

unread,
Sep 11, 2011, 12:06:58 AM9/11/11
to django...@googlegroups.com
On 09/10/2011 11:55 PM, Gil wrote:
I'm a newbie to object-oriented programming too, so I suppose my mindset is still in procedural, SQL and "recordset" modes, and otherwise: my old ways :-) Thanks for that additional info. Good Points.
From: Shawn Milochik <sh...@milochik.com>

You're welcome. The way you were doing it makes perfect sense if you have experience creating database tables by hand, the way most people do for their PHP and ASP apps. Django's ORM is doing all the same stuff underneath, but it provides a level of abstraction that makes it (much) easier to do common things, and it's a bit different than the "old way."


Javier Guerra Giraldez

unread,
Sep 12, 2011, 12:43:13 AM9/12/11
to django...@googlegroups.com
On Sat, Sep 10, 2011 at 11:06 PM, Shawn Milochik <sh...@milochik.com> wrote:
> The way you were doing it makes perfect sense if you have experience
> creating database tables by hand, the way most people do for their PHP and
> ASP apps. Django's ORM is doing all the same stuff underneath, but it
> provides a level of abstraction that makes it (much) easier to do common
> things, and it's a bit different than the "old way."

AFAICT, most SQL database design texts advice on using singular nouns
for table names. ORMs inherited that practice.

of course, as a newbie, I also made the mistake of using plural names
very often, until I found that advice; and I can say that it really
sounds better after a while.

--
Javier

Casey Greene

unread,
Sep 12, 2011, 9:24:23 AM9/12/11
to django...@googlegroups.com

Casey Greene

unread,
Sep 12, 2011, 9:26:24 AM9/12/11
to django...@googlegroups.com
I did not realize that my email client had not grabbed new mail from
today and this was 2 days old. Sorry for the reply ad nauseum.

Casey

Reply all
Reply to author
Forward
0 new messages