Creating a variable without using a database means that you do not want to use the django permission system. At this point, I would ask why you do not want to use it?
If it is ok to use sjwstem django permissions, you can create a permission and check it by overriding the admin save method ... For example:
in models.py
class SomeModel(Model): your_spec_field = FieldType(...) class Meta: permissions = ( ("some_perm", u"A name for your default permission"), )
In your related admin.py
class SomeModelAdmin(ModelAdmin): def save_model(self, request, obj, form, change): if change: curr_value = SomeModel.objects.get(pk=obj.id) if not request.user.has_perm('<your_app>.some_perm'): obj.your_spec_field = curr_value.your_spec_field else: if not request.user.has_perm('<your_app>.some_perm') obj.your_spec_field = ''
In this approach, you will get the status of the related record before saving it and checking for the appropriate permission. If the user does not have the required variable. then you replace your field value with the previous one. If this is a new entry, you will set this field to whatever value you want.
Fallenangel
source share