How can I change the TabularInline "title" on Django Admin?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I change the TabularInline "title" on Django Admin?

fellipeh
Hello,

When we need to use TabulerInline on Django Admin, the admin template create a "title" for the field... it's not the verbose_name... verbose_name is set like a Group.. "Blue" line before TabularInline... after this line, we have a table title... that's my problem... how can I change these "table title" on TabularInline?

Cheers

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZHe-w%3DQf%2B%3DqwofNnEd1%2B_U_6P%2Bj%2BDBqN%2BjQHyhmkayd%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Michal Petrucha-3
On Thu, Jul 07, 2016 at 01:56:08PM -0300, Fellipe Henrique wrote:
> Hello,
>
> When we need to use TabulerInline on Django Admin, the admin template
> create a "title" for the field... it's not the verbose_name... verbose_name
> is set like a Group.. "Blue" line before TabularInline... after this line,
> we have a table title... that's my problem... how can I change these "table
> title" on TabularInline?

Maybe you're referring to verbose_name_plural?

Cheers,

Michal

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/20160707175740.GD22177%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

fellipeh

On Thu, Jul 7, 2016 at 2:57 PM, Michal Petrucha <[hidden email]> wrote:
Maybe you're referring to verbose_name_plural?

Unfortunately no.. :(

Here is a example: (in pt-br sorry...)
Inline image 2

I want to change the "DATASET" and "Dataset_users object"

verbose_name and verbose_name_plural change the text on the "blue" line...


Cheers


T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZHOrRCT2nSG9fNv43vx1_t7peFK3XWUAapk2_jtC0AfSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Michal Petrucha-3
On Thu, Jul 07, 2016 at 03:29:00PM -0300, Fellipe Henrique wrote:

> On Thu, Jul 7, 2016 at 2:57 PM, Michal Petrucha <
> [hidden email]> wrote:
>
> > Maybe you're referring to verbose_name_plural?
> >
>
> Unfortunately no.. :(
>
> Here is a example: (in pt-br sorry...)
> [image: Inline image 2]
>
> I want to change the "DATASET" and "Dataset_users object"
>
> verbose_name and verbose_name_plural change the text on the "blue" line...
In that case, the “DATASET” would be the verbose_name of that field,
and “Dataset_users object” is the string representation of the
original original object that the row corresponds to.

Cheers,

Michal

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/20160707202438.GE22177%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Mike Dewhirst-3
In reply to this post by fellipeh
On 8/07/2016 2:56 AM, Fellipe Henrique wrote:
> Hello,
>
> When we need to use TabulerInline on Django Admin, the admin template
> create a "title" for the field... it's not the verbose_name...
> verbose_name is set like a Group.. "Blue" line before TabularInline...
> after this line, we have a table title... that's my problem... how can I
> change these "table title" on TabularInline?


     fieldsets = (
         ('This ought to change the title', {
             'classes': ('collapse', 'wide'),
             'fields': (
                 'foo',
                 'bar',
                 'baz',
                 ),
             }
         ),
     )




>
> Cheers
>
> T.·.F.·.A.·.   Â  S+F
> *Fellipe Henrique P. Soares*
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
> /Fedora Ambassador:Â https://fedoraproject.org/wiki/User:Fellipeh/
> /Blog:Â /http:www.fellipeh.eti.br
> /GitHub:Â https://github.com/fellipeh/
> /Twitter: @fh_bash/
>
> --
> 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 [hidden email]
> <mailto:[hidden email]>.
> To post to this group, send email to [hidden email]
> <mailto:[hidden email]>.
> 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/CAF1jwZHe-w%3DQf%2B%3DqwofNnEd1%2B_U_6P%2Bj%2BDBqN%2BjQHyhmkayd%3DQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAF1jwZHe-w%3DQf%2B%3DqwofNnEd1%2B_U_6P%2Bj%2BDBqN%2BjQHyhmkayd%3DQ%40mail.gmail.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 [hidden email].
To post to this group, send email to [hidden email].
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/78bd8cba-3200-65af-e4fa-e525181f9baf%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

fellipeh
In reply to this post by Michal Petrucha-3

On Thu, Jul 7, 2016 at 5:24 PM, Michal Petrucha <[hidden email]> wrote:
In that case, the “DATASET” would be the verbose_name of that field,
and “Dataset_users object” is the string representation of the
original original object that the row corresponds to.

Unfortunately no.. :(

I have set all verbose_name and verbose_name_plural, on all models.. and all models have str representation.. but still show these dataset_users object... instead the verbose_name

These "problem" occur only when I have M2M field.. in other FK fields doesn't appears..


T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZF3Bg1mUvoZMzx%3DATUMrsSUfk5B8kLZh6%3Di%2BZZLpth3qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Ramiro Morales-2
On Tue, Jul 12, 2016 at 12:54 PM, Fellipe Henrique <[hidden email]> wrote:

On Thu, Jul 7, 2016 at 5:24 PM, Michal Petrucha <[hidden email]> wrote:
In that case, the “DATASET” would be the verbose_name of that field,
and “Dataset_users object” is the string representation of the
original original object that the row corresponds to.

Unfortunately no.. :(

I have set all verbose_name and verbose_name_plural, on all models.. and all models have str representation.. but still show these dataset_users object... instead the verbose_name

These "problem" occur only when I have M2M field.. in other FK fields doesn't appears..


Can you post a simplified excerpt of the relevant (fields, Meta options, __*__ methods) models, admin app ModelAdmin's and *Inline's involved which result in the layout depicted in the screenshot you posted?

Regards,

--
Ramiro Morales
@ramiromorales

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAO7PdF8owYdEzwVhsDvF%2BXoC-86MbTE-%2BRcnZRcF27TZq3m4_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

fellipeh

On Tue, Jul 12, 2016 at 1:34 PM, Ramiro Morales <[hidden email]> wrote:
Can you post a simplified excerpt of the relevant (fields, Meta options, __*__ methods) models, admin app ModelAdmin's and *Inline's involved which result in the layout depicted in the screenshot you posted?

Sure, here is:

class Dataset(models.Model):
active = models.BooleanField(_('Ativo'), default=True)
title = models.CharField(_('Nome'), max_length=250)
users = models.ManyToManyField(MyCustomUser)

class Meta:
verbose_name = _('Dataset')
verbose_name_plural = _('Datasets')

def __str__(self):
return self.title

class MyCustomUser(AbstractBaseUser, PermissionsMixin):
username = models.CharField(
_('Nome do usuário'), max_length=200, blank=True, null=True)
email = models.EmailField(
_('Endereço de E-Mail'), blank=False, unique=True)
first_name = models.CharField(_('Nome'), max_length=30, blank=True)
last_name = models.CharField(
_('Sobrenome'), max_length=30, blank=True, default='')
is_staff = models.BooleanField(_('Administrador?'), default=False)
is_active = models.BooleanField(_('Usuário Ativo?'), default=True)
date_joined = models.DateTimeField(
_('Data Cadastro'), default=timezone.now)

objects = CustomUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name']

class Meta:
verbose_name = _('Usuário')
verbose_name_plural = _('Usuários')

def __str__(self):
if self.first_name or self.last_name:
return self.get_full_name()
return self.email

Admin:

class DatasetInline(admin.TabularInline):
model = Dataset.users.through
verbose_name = _('Dataset')
verbose_name_plural = _('Datasets')


class MyCustomUserAdmin(UserAdmin):
model = User
add_fieldsets = (None, {
'classes': ('wide',),
'fields': (
'email', 'password1', 'password2', 'first_name', 'last_name',
'is_superuser'),
}),

fieldsets = (
(None, {'fields': ('email', 'password')}),
(_('Personal info'), {'fields': (
'first_name', 'last_name')}),
(_('Permissions'), {'fields': ('is_active', 'is_superuser')}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
)

ordering = ('first_name', 'email')
list_display = ('email', 'first_name', 'last_name')
inlines = [DatasetInline]
list_filter = ('is_active', 'is_superuser')


admin.site.register(User, MyCustomUserAdmin)

The results:

Inline image 1

Cheers!


T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZHuJNH8pWQO1EF2VXZNUC64-ssneSfwNARe%3DCsi0x0iSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Ramiro Morales-2


On Tue, Jul 12, 2016 at 1:44 PM, Fellipe Henrique <[hidden email]> wrote:

On Tue, Jul 12, 2016 at 1:34 PM, Ramiro Morales <[hidden email]> wrote:
Can you post a simplified excerpt of the relevant (fields, Meta options, __*__ methods) models, admin app ModelAdmin's and *Inline's involved which result in the layout depicted in the screenshot you posted?

Sure, here is:
[...]


Where the 'Conjunto de dados' seen in the screenshot title comes from? Is the code you posted actually in sync with it?

--
Ramiro Morales
@ramiromorales

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAO7PdF8vzCTb9PCpzVw%2BeOyQ%3DfoWH%2B4emwGPNQNM%2BAR-0U9r4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

fellipeh

On Tue, Jul 12, 2016 at 1:52 PM, Ramiro Morales <[hidden email]> wrote:
Where the 'Conjunto de dados' seen in the screenshot title comes from? Is the code you posted actually in sync with it?

Sorry about that, I take the screenshot before change these text to "DataSet"...

Inline image 1

My problem is, the second "Dataset" (on light gray line) and "Dataset_users object"

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZF2WwricBicEKxPL7eWsp%2BQrTuD7YgCQueNfKAWzyTDrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Lachlan Musicman
There's a ticket for this in the tracker iirc, but I can't find it now. I think the reason is because that's the name of the DB field - it's not localizable (in so much as we don't localize db field names).

I *think* that was the reason.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 13 July 2016 at 03:42, Fellipe Henrique <[hidden email]> wrote:

On Tue, Jul 12, 2016 at 1:52 PM, Ramiro Morales <[hidden email]> wrote:
Where the 'Conjunto de dados' seen in the screenshot title comes from? Is the code you posted actually in sync with it?

Sorry about that, I take the screenshot before change these text to "DataSet"...

Inline image 1

My problem is, the second "Dataset" (on light gray line) and "Dataset_users object"

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAF1jwZF2WwricBicEKxPL7eWsp%2BQrTuD7YgCQueNfKAWzyTDrA%40mail.gmail.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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiN0TMULASBEgjzb3TJENDchTO8bU%2BYSLC8dVN5mg13iow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Ramiro Morales-2
On Tue, Jul 12, 2016 at 8:39 PM, Lachlan Musicman <[hidden email]> wrote:
There's a ticket for this in the tracker iirc, but I can't find it now. I think the reason is because that's the name of the DB field - it's not localizable (in so much as we don't localize db field names).

That was mi recollection too. But I've been unable to find it.

Regards,

--
Ramiro Morales
@ramiromorales

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAO7PdF9ExFBK48FYB4q%2BOHDFxPxM0KoY6-0DbTn-Aip2U4q1jA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I change the TabularInline "title" on Django Admin?

Ramiro Morales-2
In reply to this post by fellipeh
On Tue, Jul 12, 2016 at 2:42 PM, Fellipe Henrique <[hidden email]> wrote:


On Tue, Jul 12, 2016 at 1:52 PM, Ramiro Morales <[hidden email]> wrote:
Where the 'Conjunto de dados' seen in the screenshot title comes from? Is the code you posted actually in sync with it?

Sorry about that, I take the screenshot before change these text to "DataSet"...

Inline image 1

My problem is, the second "Dataset" (on light gray line) and "Dataset_users object"


I've prepared this simplified app.

Note: All the is completely centered around controlling the labels in the admin views, this can mean things get completely ugly on ther UI areas.

The Dataset model setup is basically what you posted originally, the Sample model is very similar to Dataset but the M2M relationship between User and Sample is defined through an explicit SampleUserRel model. See

  https://docs.djangoproject.com/en/1.9/topics/db/models/#intermediary-manytomany

  https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ManyToManyField.through

sections of the Django documentation.

#--------------------------------------------
# models.py
from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible


@python_2_unicode_compatible
class User(models.Model):
    username = models.CharField(max_length=200, blank=True, null=True)
    email = models.EmailField(blank=False, unique=True)

    def __str__(self):
        return self.email


@python_2_unicode_compatible
class Dataset(models.Model):
    active = models.BooleanField(default=True)
    title = models.CharField(max_length=250)
    users = models.ManyToManyField(User)

    def __str__(self):
        return self.title


@python_2_unicode_compatible
class Sample(models.Model):
    active = models.BooleanField(default=True)
    title = models.CharField(max_length=250)
    users = models.ManyToManyField(User, through='SampleUserRel')

    def __str__(self):
        return self.title


@python_2_unicode_compatible
class SampleUserRel(models.Model):
    user = models.ForeignKey(User)
    sample = models.ForeignKey(Sample, verbose_name='this can be set with the verbose_name option of the FK field to the remote model in the intermediate model')

    def __str__(self):
        return "this can be set with the intermediate model's __str__ method"


#--------------------------------------------
# admin.py
from django.contrib import admin

from .models import Dataset, User, Sample, SampleUserRel


class DatasetInline(admin.TabularInline):
    model = Dataset.users.through
    verbose_name = 'this can be set with {Stacked,Tabular}Inline.verbose_name'
    verbose_name_plural = 'this can be set with {Stacked,Tabular}.verbose_name_plural'


class SampleUserRelInline(admin.TabularInline):
    model = SampleUserRel
    extra = 1
    verbose_name = "this can be set with intermediate's model verbose_name and overridden with {Stacked,Tabular}Inline.verbose_name"
    verbose_name_plural = "this can be set with intermediate model's verbose_name_plural and overridden with {Stacked,Tabular}Inline.verbose_name_plural"


class UserAdmin(admin.ModelAdmin):
    list_display = ('email',)
    inlines = [DatasetInline, SampleUserRelInline]


admin.site.register(User, UserAdmin)
admin.site.register([Dataset, Sample])


Btw, something like this is what we talk about when we ask for an excerpt of the code with only the relevant parts, please take the time to prepare things by stripping code unrelated to the issue at hand before posting your code. Help us to help you.

The above setup results in the following Change User view:

Inline image 1

Hoping this is of help,

--
Ramiro Morales
@ramiromorales

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAO7PdF_dupadcYtQpwWaCOBxTZ13G-rHh%2B4u2sQLbMwa0UJwnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.