I have materials recorded in the database and belonging to different users. those are either private access, or are part of a group, or free access to all. I want, for example, a current user can have access to all the materials open access (but can not modify those he did not create (readonly fields). But, He could add other records ..
I have a model
DROITS = (
('lecture', 'all'),
('groupe', 'group')
('private', 'private data')
class Material(models.Model):
name = models.CharField(_('name'), max_length=50)
category = models.ForeignKey(Category, verbose_name=_('category'))
user = models.ForeignKey(User, default=None, blank= True, null = True)
droits_acces = models.CharField(_('access right'), max_length=150, choices = DROITS, default= 'private' )
groupe = models.ForeignKey(Group, verbose_name=_('group'), blank = True, null= True, default = None)
Admin :
class MaterialAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'user', 'created', 'droits_acces')
inlines = (MediaInline, UniteProperty2Inline, Essai_TemperatureInline)
def queryset(self, request):
qs = super(MaterialAdmin, self).queryset(request)
if request.user.is_superuser:
return qs
else:
.....
the first thing is to associate user and material. how can we do? with the class Material, I filter only the fields related material
after if the material does not belong to the current user I have to put 'Essai_TemperatureInline' read access only