class UserAdminPanel(admin.ModelAdmin):
    inlines = (UserPlaylist, UserVideos, UserComment, UserReplays, )
    list_per_page = 20
    fieldsets = (
        (None, {'fields': ('username', )}),
        (_('Personal info'), {'fields': ('first_name', 'last_name',
'email')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff',
'is_superuser',
                                       'groups', 'user_permissions')}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'password1', 'password2'),
        }),
    )
    list_display = [
        'username',
        'email',
        'last_name',
        'user_reg',  # refer to Registration model
        'is_staff',
    ]
    list_filter = ('date_joined', 'is_staff', 'is_superuser', 'is_active',
'groups')
    search_fields = [
        'date_joined',
        'email',
        'first_name',
        'last_name',
        'username',
    ]
    ordering = ['-date_joined', 'username']
    filter_horizontal = ('groups', 'user_permissions',)

On Mon, Nov 6, 2017 at 12:32 AM, mohammad k <[email protected]> wrote:

> use this code for ManytoMany fields in django admin :
>
> filter_horizontal = ('groups', 'user_permissions',)
>
> On Fri, Nov 3, 2017 at 1:45 PM, Paul <[email protected]> wrote:
>
>> I have a Product model, an Image Model and a Category Model.
>>
>> A Product can have multiple Images(Foreign Key) and a Product can be in
>> multiple Categories a Category can contain multiple Products.
>>
>> A Category can have multiple subcategories(key to itself).
>>
>>
>> class Category(MetaData):
>>  parent = models.ForeignKey('self', blank=True, null=True, 
>> verbose_name='parent
>> category', on_delete=models.CASCADE)
>>
>> class ProductMetaData):
>>   categories = models.ManyToManyField(Category)
>>
>> class ProductImage(models.Model):
>>   product = models.ForeignKey(Product, related_name='image', on_delete=
>> models.CASCADE)
>>
>>
>>
>> In Product Django Admin:
>>
>> class ProductDocumentInline(admin.TabularInline):
>>  model = ProductDocument class ProductAdmin(MetaData):
>>  inlines = [ProductImageInline]
>>  fieldsets = (
>>  ('Product Data', {
>>  'fields': ('name', 'short_description', 'description')
>>  }),
>>  ('SEO', {
>>  'classes': ('collapse',),
>>  'fields': ('meta_title', 'meta_description', 'slug', 'canonical')
>>  }),
>>  ('MetaData', {
>>  'classes': ('collapse',),
>>  'fields': (('created_at', 'created_by'), ('updated_at', 'updated_by'))
>>  }),
>>  )
>>  readonly_fields = ('created_at', 'updated_at', 'created_by',
>> 'updated_by')
>>  list_display = ('name', 'updated_at')
>>  ordering = ('-updated_at',)
>>  search_fields = ('name',)
>>
>>
>> admin.site.register(Product, ProductAdmin)
>> admin.site.register(ProductImage)
>>
>>
>>
>> Issues:
>>
>>    1.
>>
>>    If I don't customize fieldsets (grouped, ordered) the Categories
>>    appear like default in the middle of the form. If there are customized as
>>    in my example they don't appear.
>>    2.
>>
>>    If they don't appear Products without Categories can be created and I
>>    don't want that. I want a product to have at least one category.
>>    3.
>>
>>    Now the inline Images appear below all Product fields.
>>
>> I want the Categories to appear first, then normal fields for
>> Product(grouped,ordered), Images inline and at the end the SEO and metadata
>> fields. How can this be done ?
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/37bf83ae-cdca-4c73-8ace-747386513e53%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/37bf83ae-cdca-4c73-8ace-747386513e53%40googlegroups.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 [email protected].
To post to this group, send email to [email protected].
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/CACOk0Ty8qYBHRiGY6VajbH5mh2o67gOw%3DwgJob0ktrx52-c8WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to