I've made a model (models.py):
class opetest(models.Model):
name = models.CharField(max_length=200)
author = models.ForeignKey(User, related_name='author')
description = models.TextField(u'Test description', help_text = u'Some words about quiz')
pub_date = models.DateTimeField('date published', blank=False)
vacancies = models.ManyToManyField(Vacancy, blank=True)
students = models.ManyToManyField(User, blank=True, related_name='opetests') #This field I want to edit on "User change page"
estimate = models.IntegerField(default = 0, help_text = u'Estimate time in hours. \'0\' - unlimited')
then I try to add inline block to allow assign opetest
on 'change user' page (admin.py):
class ProfileAdmin(UserAdmin):
filter_horizontal = ('opetests',)
admin.site.unregister(User)
admin.site.register(User, ProfileAdmin)
And I got an error:
'ProfileAdmin.filter_horizontal' refers to field 'opetests' that is missing from model 'User'.
I want to show opetests like Groups on change user page. How can I achieve that?
Hmm, I don't think you want inlines here.
You want to be using the Django admin's filter_horizontal:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.filter_horizontal
That will give you the widget that you're describing, used to add/remove Groups on the User Change page.
Ok, based on your edits, updated answer - basically, what we have is a UserProfile, linked to each user.
The UserProfile contains a m2m relationship to opetest - which we show in the admin with a filter_horizontal. End result is something like this:
models.py
admin.py
Let me know if you have any questions, or need anything further.