On Tue, Jul 12, 2016 at 1:34 PM, Ramiro Morales <cramm0@gmail.com> 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:
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 django-users+unsubscribe@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/CAF1jwZHuJNH8pWQO1EF2VXZNUC64-ssneSfwNARe%3DCsi0x0iSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:
Post a Comment