Z
Z
zkweb2015-10-22 14:59:15
Django
zkweb, 2015-10-22 14:59:15

How in the standard User to make a similar list as the choice of "Group"?

I need to make a similar list as "Groups" for a user. Only there will be a list of stores. I'm new to Django, I did something according to the documentation that didn't work. Can you provide an example code? Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Lebedev, 2015-10-22
@zkweb

for starters, I would not redefine the user model, but simply expand it like this , something like : models.py

from django.contrib.auth.models import User

class Customer(models.Model):
    user = models.OneToOneField(User)
    shops = models.ManyToManyField(Shops)

well, and just like for groups:
admin.py
class CustomerInline(admin.StackedInline):
    model = Customer
    fk_name = 'user'
    can_delete = False
    filter_horizontal = ('shops', )

class CustomerAdmin(UserAdmin):
    inlines = (CustomerInline, )

admin.site.unregister(User)
admin.site.register(User, CustomerAdmin)

R
Roman Kitaev, 2015-10-22
@deliro

It's not very clear, but probably like this:
1) Redefine the user
2) Add the M2M store field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question